-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked pressure example to be more readable.
- Loading branch information
Chris Bury
committed
Jul 25, 2024
1 parent
4557da9
commit 296791a
Showing
1 changed file
with
26 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,30 @@ | ||
use procfs::prelude::*; | ||
use procfs::{prelude::*, CpuPressure, IoPressure, MemoryPressure, PressureRecord}; | ||
|
||
/// A basic example of /proc/pressure/ usage. | ||
fn main() { | ||
println!("memory pressure: {:#?}", procfs::MemoryPressure::current()); | ||
println!("cpu pressure: {:#?}", procfs::CpuPressure::current()); | ||
println!("io pressure: {:#?}", procfs::IoPressure::current()); | ||
if let Ok(pressure) = MemoryPressure::current() { | ||
println!("Memory Pressure:"); | ||
println!("{:>10}:", "Some"); | ||
print_pressure(pressure.some, 20); | ||
println!("{:>10}:", "Full"); | ||
print_pressure(pressure.full, 20); | ||
} | ||
if let Ok(pressure) = CpuPressure::current() { | ||
println!("CPU Pressure:"); | ||
print_pressure(pressure.some, 20); | ||
} | ||
if let Ok(pressure) = IoPressure::current() { | ||
println!("IO Pressure:"); | ||
println!("{:>10}:", "Some"); | ||
print_pressure(pressure.some, 20); | ||
println!("{:>10}:", "Full"); | ||
print_pressure(pressure.full, 20); | ||
} | ||
} | ||
|
||
fn print_pressure(pressure: PressureRecord, width: usize) { | ||
println!("{:>width$}: {}", "Average 10", pressure.avg10); | ||
println!("{:>width$}: {}", "Average 60", pressure.avg60); | ||
println!("{:>width$}: {}", "Average 300", pressure.avg300); | ||
println!("{:>width$}: {}", "Total", pressure.total); | ||
} |