Crate carbonara

Source
Expand description

carbonara

§Carbonara is a Rust library for calculating the energy consumption and CO2e emissions of the Internet.

based on Green Coding Co2 formulas

use carbonara::{MeasurementConfig, BenchmarkExecutor, PowerSource, MeasurementError};
use std::time::Duration;
// Example usage with Auto power source detection, which will try RAPL first and then fall back to the ACPI power meter,
// if that also fails, it will use TDP based power estimation.
fn main() -> Result<(), MeasurementError> {
    let config = MeasurementConfig {
        duration: Duration::from_secs(5),
        power_source: PowerSource::Auto,
        sample_interval_ms: 100,
    };

    let executor = BenchmarkExecutor::new(config);


    let result = executor.measure(|| {
        // CPU-intensive workload
        for _ in 0..1_000_000 {
            let _ = (0..100).sum::<i32>();
        }
    })?;


    println!("{} Measurement Results:", result.measurement_method);
    println!("Total Energy: {:?}", result.total_energy);
    println!("Average Power: {:?}", result.average_power);
    println!("Peak Power: {:?}", result.peak_power);
    println!("Duration: {:?}", result.duration);
    println!("CO2e: {:.2} g", result.co2e(None));

    Ok(())
}

Structs§

AcpiMeasurement
ACPI measurement implementation
BenchmarkExecutor
Benchmark executor
EnergyMeasurement
Measurement results
MeasurementConfig
Measurement configuration
RaplMeasurement
Intel RAPL measurement implementation

Enums§

MeasurementError
Measurement errors
PowerSource
Represents different power measurement methods

Functions§

benchmarks_to_kwh
Estimates energy consumption from benchmarks
gigabytes_to_kwh
Converts Gigabytes to kWh
joules_to_kwh
Converts Joules to kWh
kwh_to_co2e
Converts kWh to CO2e
kwh_to_joules
Converts kWh to Joules
megabytes_to_kwh
Converts Megabytes to kWh
tdp_to_joules
Estimates energy consumption from TDP (Thermal Design Power)