1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Explicitly configure for platform-specific code
// Allow unwrap() in test code since tests can safely panic
/// # darwin-metrics
///
/// `darwin-metrics` is a Rust library that provides native access to macOS system metrics through low-level system
/// APIs. This crate offers efficient, safe, and async-capable interfaces for monitoring system resources on macOS.
///
/// ## Features
///
/// - **CPU Monitoring**: Usage statistics, frequency information, model details
/// - **Memory Analysis**: RAM usage, swap space, memory pressure
/// - **GPU Information**: Model detection, utilization metrics, VRAM tracking
/// - **Storage Metrics**: Disk space, I/O performance, read/write speeds
/// - **Power Management**: Battery status, charging state, time estimation
/// - **Thermal Monitoring**: Fan speeds, temperature tracking, thermal status
/// - **Process Information**: Process enumeration, resource usage, system info
/// - **Network Monitoring**: Interface discovery, traffic statistics, bandwidth
///
/// ## Installation
///
/// Add this to your `Cargo.toml`:
///
/// ```toml
/// [dependencies]
/// darwin-metrics = "0.1.5"
/// ```
///
/// ## Requirements
///
/// - macOS El Capitan (10.11) or later
/// - Rust 1.85 or later
/// - Xcode Command Line Tools
///
/// ## Quick Start
///
/// ```ignore
/// // This example won't be run by doctests but serves as API usage documentation
/// use darwin_metrics::hardware::{cpu, gpu, temperature};
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // Get CPU information
/// let cpu_obj = cpu::CPU::new();
/// println!("CPU cores: {}", cpu_obj.cores());
///
/// // Monitor temperature
/// let mut temp_monitor = temperature::Temperature::new();
/// let cpu_temp = temp_monitor.cpu_temperature()?;
/// println!("CPU Temperature: {:.1}°C", cpu_temp);
///
/// // Check thermal metrics
/// let metrics = temp_monitor.get_thermal_metrics()?;
/// println!("Is CPU throttling: {}", metrics.is_throttling);
///
/// Ok(())
/// }
/// ```
///
/// ## Feature Flags
///
/// ### Core Features (Enabled by Default)
///
/// - `battery` - Enable battery monitoring
/// - `cpu` - Enable CPU metrics
/// - `memory` - Enable memory statistics
/// - `gpu` - Enable GPU monitoring
/// - `disk` - Enable storage metrics
/// - `temperature` - Enable thermal monitoring
/// - `async` - Enable async support (requires tokio)
///
/// ### Additional Features
///
/// - `process_monitoring` - Enable detailed process monitoring
/// - `unstable-tests` - Enable tests that may be unstable in CI environments
///
/// ## Module Structure
///
/// - [`battery`] - Battery information and power metrics
/// - [`hardware`] - Hardware monitoring:
/// - [`hardware::cpu`] - CPU usage, frequency, and core information
/// - [`hardware::gpu`] - GPU metrics and memory usage
/// - [`hardware::memory`] - System memory statistics
/// - [`hardware::temperature`] - Temperature sensors and fan control
/// - [`network`] - Network interfaces and traffic statistics
/// - [`power`] - Power consumption and management
/// - [`process`] - Process monitoring and management
/// - [`system`] - Overall system information
///
/// ## Error Handling
///
/// The crate provides a centralized [`Error`] type that encompasses all possible error conditions and a convenient
/// [`Result`] type alias.
///
/// ```
/// # fn foo() {
/// use darwin_metrics::Result;
///
/// fn example() -> Result<()> {
/// // Function implementation...
/// Ok(())
/// }
/// # }
/// ```
///
/// ## Async Support
///
/// When the `async` feature is enabled, the crate provides async versions of monitoring functions that can be used with
/// the tokio runtime.
///
/// ```ignore
/// use darwin_metrics::hardware::temperature::Temperature;
///
/// async fn example() -> darwin_metrics::Result<()> {
/// let mut temp = Temperature::new();
/// let metrics = temp.get_thermal_metrics_async().await?;
/// println!("CPU temperature: {:?}°C", metrics.cpu_temperature);
/// Ok(())
/// }
/// ```
///
// Re-export the core error types for easier use Re-export primary modules for direct access
pub use Battery;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;