#process #cpu #memory

simple-process-stats

Get memory usage and CPU time on Linux and Windows

4 releases (1 stable)

1.0.0 Dec 25, 2020
0.2.1 Nov 24, 2020
0.2.0 Aug 25, 2020
0.1.0 Jul 19, 2020

#73 in Operating systems

Download history 145/week @ 2021-02-23 61/week @ 2021-03-02 53/week @ 2021-03-09 381/week @ 2021-03-16 72/week @ 2021-03-23 55/week @ 2021-03-30 97/week @ 2021-04-06 33/week @ 2021-04-13 41/week @ 2021-04-20 21/week @ 2021-04-27 71/week @ 2021-05-04 36/week @ 2021-05-11 44/week @ 2021-05-18 28/week @ 2021-05-25 51/week @ 2021-06-01 71/week @ 2021-06-08

390 downloads per month

MIT license

13KB
226 lines

simple-process-stats

A small library to get memory usage and elapsed CPU time.

  • Supports Windows, Linux and macOS.
  • Async interface, uses tokio::fs for file operations
use simple_process_stats::ProcessStats;

let process_stats = ProcessStats::get().await.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).


lib.rs:

A small library to get memory usage and elapsed CPU time.

  • Supports Windows, Linux and macOS.
  • Async interface, uses tokio::fs for file operations
use simple_process_stats::ProcessStats;

# #[tokio::main]
# async fn main() {
let process_stats = ProcessStats::get().await.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).

Dependencies

~0.4–1.6MB
~33K SLoC