Crates.io | vjoule_api |
lib.rs | vjoule_api |
version | 1.3.1 |
source | src |
created_at | 2023-02-14 12:01:32.024999 |
updated_at | 2024-02-16 09:31:05.167567 |
description | API for vjoule |
homepage | |
repository | |
max_upload_size | |
id | 784819 |
size | 11,840 |
This is a library used to communicate with the vJoule service. This API provides simplified functions to manage cgroups, and retreive the estimate consumption.
extern crate vjoule_api;
use std::thread;
use std::time::Duration;
use vjoule_api::VJouleAPI;
use vjoule_api::vjoule_api::error::VJouleError;
fn compute_pi (prec : u64)-> f64 {
let mut res = 0.0;
for i in 0 .. prec {
res += (4.0 / prec as f64) / (1.0 + ((i as f64 - 0.5) * (1.0 / prec as f64)) * ((i as f64 - 0.5) * (1.0 / prec as f64)))
}
res
}
fn test_pi (api : &mut VJouleAPI, prec : u64)-> Result<ConsumptionDiff, VJouleError> {
let m_beg = api.get_current_machine_consumption ()?;
let pi = compute_pi (prec);
let m_end = api.get_current_machine_consumption_no_force ()?;
let m_diff = m_end - m_beg;
println!("PI : {}", pi);
println!("{}", m_diff);
Ok (m_diff)
}
fn run_pi (mut api : &mut VJouleAPI) {
match test_pi (&mut api) {
Err (s) => {
println!("Pi error : {}", s);
}
Ok (_) => {}
}
}
fn main() {
let api = vjoule_api::VJouleAPI::new ();
match api {
Ok (mut api) => {
let a = run_pi (&mut api, 100000000);
let b = run_pi (&mut api, 200000000);
match (a, b) {
(Ok (x), Ok (y)) => {
println!("{}", x % y);
}
_ => {}
}
}
Err (s) => {
println!("{}", s);
}
}
}