Skip to content

Commit

Permalink
Merge pull request #314 from Hwatwasthat/master
Browse files Browse the repository at this point in the history
Updated some examples to a bit more than printing debug.
  • Loading branch information
eminence authored Jul 29, 2024
2 parents a738d0d + 296791a commit 784dd2c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
5 changes: 3 additions & 2 deletions procfs/examples/lslocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::path::Path;
fn main() {
let myself = Process::myself().unwrap();
let mountinfo = myself.mountinfo().unwrap();

println!("{:18}{:13}{:13}{:13}{:12} Path", "Process", "PID", "Lock Type", "Mode", "Kind");
println!("{}", "=".repeat(74));
for lock in procfs::locks().unwrap() {
lock.pid
.and_then(|pid| Process::new(pid).ok())
Expand Down Expand Up @@ -33,7 +34,7 @@ fn main() {
for f in fds {
let fd = f.unwrap();
if let FDTarget::Path(p) = fd.target {
if let Ok(stat) = rustix::fs::statat(&rustix::fs::cwd(), &p, AtFlags::empty()) {
if let Ok(stat) = rustix::fs::statat(&rustix::fs::CWD, &p, AtFlags::empty()) {
if stat.st_ino as u64 == lock.inode {
print!("{}", p.display());
found = true;
Expand Down
14 changes: 13 additions & 1 deletion procfs/examples/mounts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
// List mountpoints listed in /proc/mounts

fn main() {
let width = 15;
for mount_entry in procfs::mounts().unwrap() {
println!("{mount_entry:?}");
println!("Device: {}", mount_entry.fs_spec);
println!("{:>width$}: {}", "Mount point", mount_entry.fs_file);
println!("{:>width$}: {}","FS type", mount_entry.fs_vfstype);
println!("{:>width$}: {}", "Dump", mount_entry.fs_freq);
println!("{:>width$}: {}", "Check", mount_entry.fs_passno);
print!("{:>width$}: ", "Options");
for (name, entry) in mount_entry.fs_mntops {
if let Some(entry) = entry {
print!("{name}: {entry} ");
}
}
println!("");
}
}
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 784dd2c

Please sign in to comment.