Skip to main content

jolt_platform/
power.rs

1//! Power monitoring traits and types.
2
3use color_eyre::eyre::Result;
4
5use crate::types::PowerMode;
6
7/// Power information snapshot.
8///
9/// All power values are in watts.
10#[derive(Debug, Clone, Default)]
11pub struct PowerInfo {
12    /// CPU package power consumption in watts.
13    pub cpu_power_watts: f32,
14
15    /// GPU power consumption in watts.
16    pub gpu_power_watts: f32,
17
18    /// Total system power consumption in watts.
19    /// This may be measured (SMC/RAPL) or estimated (sum of components).
20    pub system_power_watts: f32,
21
22    /// Current power mode.
23    pub power_mode: PowerMode,
24
25    /// Whether enough samples have been collected for reliable readings.
26    /// Power readings may be unstable during the first few samples.
27    pub is_warmed_up: bool,
28}
29
30impl PowerInfo {
31    /// Get combined CPU + GPU power.
32    pub fn package_power_watts(&self) -> f32 {
33        self.cpu_power_watts + self.gpu_power_watts
34    }
35}
36
37/// Trait for platform-specific power providers.
38pub trait PowerProvider {
39    /// Create a new power provider instance.
40    fn new() -> Result<Self>
41    where
42        Self: Sized;
43
44    /// Refresh power information from the system.
45    fn refresh(&mut self) -> Result<()>;
46
47    /// Get the current power information.
48    fn info(&self) -> &PowerInfo;
49
50    /// Check if power monitoring is supported on this system.
51    ///
52    /// Returns false if the required hardware/permissions are not available.
53    fn is_supported() -> bool
54    where
55        Self: Sized,
56    {
57        true
58    }
59}