https://github.com/robotty/simple-process-stats
A small Rust library to get memory usage and elapsed CPU time.
https://github.com/robotty/simple-process-stats
linux macos process-stats rust rust-crate windows
Last synced: about 2 months ago
JSON representation
A small Rust library to get memory usage and elapsed CPU time.
- Host: GitHub
- URL: https://github.com/robotty/simple-process-stats
- Owner: robotty
- License: mit
- Created: 2020-07-19T17:46:12.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-12T22:42:31.000Z (over 3 years ago)
- Last Synced: 2026-01-02T11:11:34.652Z (5 months ago)
- Topics: linux, macos, process-stats, rust, rust-crate, windows
- Language: Rust
- Homepage: https://crates.io/crates/simple-process-stats
- Size: 33.2 KB
- Stars: 20
- Watchers: 1
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# simple-process-stats
A small library to get memory usage and elapsed CPU time.
Supports Windows, Linux and macOS.
```rust
use simple_process_stats::ProcessStats;
let process_stats = ProcessStats::get().expect("could not get stats for running process");
println!("{:?}", process_stats);
// ProcessStats {
// cpu_time_user: 421.875ms,
// cpu_time_kernel: 102.332ms,
// memory_usage_bytes: 3420160,
// }
```
On Linux, this library reads `/proc/self/stat` and uses the `sysconf` libc function.
On Windows, the library uses `GetCurrentProcess` combined with `GetProcessTimes` and `K32GetProcessMemoryInfo`.
On macOS, this library uses `proc_pidinfo` from `libproc` (and current process ID is determined via `libc`).