1use std::time::Duration;
4
5#[derive(Debug, Clone)]
11pub struct MonitorConfig {
12 pub poll_interval: Duration,
14 pub history_size: usize,
16 pub background_collection: bool,
18}
19
20const DEFAULT_HISTORY_SIZE: usize = 600;
22const HIGH_FREQ_HISTORY_SIZE: usize = 1200;
24const LOW_OVERHEAD_HISTORY_SIZE: usize = 120;
26
27impl Default for MonitorConfig {
28 fn default() -> Self {
29 Self {
30 poll_interval: Duration::from_millis(100),
31 history_size: DEFAULT_HISTORY_SIZE,
32 background_collection: false,
33 }
34 }
35}
36
37impl MonitorConfig {
38 #[must_use]
40 pub fn high_frequency() -> Self {
41 Self {
42 poll_interval: Duration::from_millis(50),
43 history_size: HIGH_FREQ_HISTORY_SIZE,
44 background_collection: true,
45 }
46 }
47
48 #[must_use]
50 pub fn low_overhead() -> Self {
51 Self {
52 poll_interval: Duration::from_millis(500),
53 history_size: LOW_OVERHEAD_HISTORY_SIZE,
54 background_collection: false,
55 }
56 }
57}
58
59#[derive(Debug, Clone)]
65pub enum MonitorError {
66 NoDevice,
68 InvalidDevice(u32),
70 BackendInit(String),
72 QueryFailed(String),
74 NotAvailable(String),
76}
77
78impl std::fmt::Display for MonitorError {
79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80 match self {
81 Self::NoDevice => write!(f, "No GPU device available"),
82 Self::InvalidDevice(idx) => write!(f, "Invalid device index: {idx}"),
83 Self::BackendInit(msg) => write!(f, "Backend initialization failed: {msg}"),
84 Self::QueryFailed(msg) => write!(f, "Metrics query failed: {msg}"),
85 Self::NotAvailable(msg) => write!(f, "Feature not available: {msg}"),
86 }
87 }
88}
89
90impl std::error::Error for MonitorError {}