diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e3e1634..32291fc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,9 +19,7 @@ jobs: steps: - uses: actions/checkout@v7 - uses: dtolnay/rust-toolchain@stable - - name: Run tests (only default features) - run: cargo test - - name: Run tests (all tests enabled) + - name: Run tests run: cargo test build: runs-on: ${{ matrix.os }} diff --git a/CHANGELOG.md b/CHANGELOG.md index a053652..2c61178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ # Changelog ## Unversioned + - Major: Replaced async api with synchronous API. (#20, #22, #24) -- macOS: apply timebase information to CPU times. (#21, #25) +- Bugfix: macOS: apply timebase information to CPU times. (#21, #25) +- Dev: Dependency updates (#26). ## v1.0.0 diff --git a/Cargo.toml b/Cargo.toml index 85597d7..7ebbb07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,24 +4,24 @@ description = "Get memory usage and CPU time on Linux and Windows" license = "MIT" version = "1.0.0" keywords = ["process", "cpu", "memory"] -categories = ["api-bindings", "asynchronous", "os"] +categories = ["api-bindings", "os"] repository = "https://github.com/robotty/simple-process-stats" readme = "README.md" authors = ["Ruben Anders "] -edition = "2018" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -thiserror = "1.0.20" +thiserror = "2" [target.'cfg(target_os = "windows")'.dependencies] -winapi = { version = "0.3.9", features = ["psapi", "processthreadsapi"] } +winapi = { version = "0.3", features = ["psapi", "processthreadsapi"] } [target.'cfg(target_os = "linux")'.dependencies] -procfs = "0.9.0" -libc = "0.2.72" +procfs = "0.18" +libc = "0.2" [target.'cfg(target_os = "macos")'.dependencies] -darwin-libproc = "0.2.0" -libc = "0.2.72" +darwin-libproc = "0.2" +libc = "0.2" diff --git a/src/linux.rs b/src/linux.rs index 41a75d5..b58b2fe 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -1,19 +1,19 @@ use crate::{Error, ProcessStats}; +use procfs::FromRead; use procfs::process::Stat; use std::io::Cursor; use std::path::Path; use std::time::Duration; pub fn get_info() -> Result { - let bytes_per_page = procfs::page_size().map_err(Error::SystemCall)?; - let ticks_per_second = procfs::ticks_per_second().map_err(Error::SystemCall)?; + let bytes_per_page = procfs::page_size(); + let ticks_per_second = procfs::ticks_per_second(); let path = Path::new("/proc/self/stat"); let file_contents = std::fs::read(path).map_err(|e| Error::FileRead(path.to_path_buf(), e))?; let readable_string = Cursor::new(file_contents); - let stat_file = - Stat::from_reader(readable_string).map_err(|_e| Error::FileContentsMalformed)?; + let stat_file = Stat::from_read(readable_string).map_err(|_e| Error::FileContentsMalformed)?; let memory_usage_bytes = (stat_file.rss as u64) * (bytes_per_page as u64); let user_mode_seconds = (stat_file.utime as f64) / (ticks_per_second as f64); @@ -32,7 +32,7 @@ pub mod tests { #[test] pub fn test_no_error() { - #[no_mangle] + #[unsafe(no_mangle)] fn spin_for_a_bit() { let mut _a = 0; for _i in 0..9999999 { diff --git a/src/macos.rs b/src/macos.rs index 54135da..a70de56 100644 --- a/src/macos.rs +++ b/src/macos.rs @@ -22,7 +22,7 @@ struct mach_timebase_info { impl mach_timebase_info { pub fn get() -> Self { - extern "C" { + unsafe extern "C" { fn mach_timebase_info(info: *mut mach_timebase_info) -> libc::c_int; } let mut info = mach_timebase_info { numer: 0, denom: 0 }; @@ -43,7 +43,7 @@ pub mod tests { #[test] pub fn test_no_error() { - #[no_mangle] + #[unsafe(no_mangle)] fn spin_for_a_bit() { let mut _a = 0; for _i in 0..9999999 { diff --git a/src/windows.rs b/src/windows.rs index 600b478..ffac61e 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -94,9 +94,10 @@ mod tests { #[test] fn test_no_error() { - #[no_mangle] + #[unsafe(no_mangle)] fn spin_for_a_bit() { let mut _a = 0; + #[allow(clippy::explicit_counter_loop)] for _i in 0..9999999 { _a += 1; }