#![deny(clippy::all)]
#![deny(clippy::cargo)]
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "windows")]
mod windows;
use std::path::PathBuf;
use std::time::Duration;
use thiserror::Error;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ProcessStats {
pub cpu_time_user: Duration,
pub cpu_time_kernel: Duration,
pub memory_usage_bytes: u64,
}
impl ProcessStats {
#[cfg(target_os = "windows")]
pub fn get() -> Result<ProcessStats, Error> {
windows::get_info()
}
#[cfg(target_os = "linux")]
pub fn get() -> Result<ProcessStats, Error> {
linux::get_info()
}
#[cfg(target_os = "macos")]
pub fn get() -> Result<ProcessStats, Error> {
macos::get_info()
}
}
#[derive(Error, Debug)]
pub enum Error {
#[error("Failed to read from file `{0}`: {1}")]
FileRead(PathBuf, std::io::Error),
#[error("File contents are in unexpected format")]
FileContentsMalformed,
#[error("Call to system-native API errored: {0}")]
SystemCall(std::io::Error),
}