| Crates.io | systrack |
| lib.rs | systrack |
| version | 0.1.0 |
| created_at | 2023-10-07 01:17:03.990449+00 |
| updated_at | 2023-10-07 01:17:03.990449+00 |
| description | Track system resource usage over custom lapses |
| homepage | |
| repository | https://github.com/jdvillal/systrack |
| max_upload_size | |
| id | 995937 |
| size | 20,935 |
Track system resource usage over custom lapses.
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.