Skip to content

Commit

Permalink
Reworked pressure example to be more readable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Bury committed Jul 25, 2024
1 parent 4557da9 commit 296791a
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions procfs/examples/pressure.rs
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);
}

0 comments on commit 296791a

Please sign in to comment.