1 unstable release
0.1.0 | Oct 7, 2023 |
---|
#17 in #usage
14KB
217 lines
systrack
Track system resource usage over custom lapses.
Usage examples
Create a tracker that records CPU usage.
let mut cpu_tracker = SystemTracker::new_cpu_tracker();
This creates a structure that keep track of CPU usage over the last minute (by default). Interally, a background thread updates the historical information twice per second.
If you want a tracker to save historical data for a longer lapse, you should create the tracker using new_cpu_tracker_with_capacity()
.
To get the historical data, you can call fetch_usage()
.
for _ in 0..10 {
println!("{:?}", cpu_tracker.fetch_usage());
thread::sleep(Duration::from_millis(500));
}
Also, if you want the tracker to stop recording, you can call stop()
.
cpu_tracker.stop();
for _ in 0..5 {
println!("{:?}", cpu_tracker.fetch_usage());
thread::sleep(Duration::from_millis(500));
}
Keep in mind that once the stop()
method is called, the fetch_usage()
method will always return None
.
Memory usage tracker works almost identical. Check the examples dir for more.
Dependencies
~0.7–1MB
~20K SLoC