Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated some examples to a bit more than printing debug. #314

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading