Skip to content
Open
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
22 changes: 21 additions & 1 deletion procfs-core/src/pressure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::collections::HashMap;
#[cfg(feature = "serde1")]
use serde::{Deserialize, Serialize};

/// Pressure stall information for either CPU, memory, or IO.
/// Pressure stall information for either CPU, memory, IRQ or IO.
///
/// See also: <https://www.kernel.org/doc/Documentation/accounting/psi.txt>
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -92,6 +92,26 @@ impl super::FromBufRead for IoPressure {
}
}

/// IRQ pressure information, only available if the kernel was compiled with CONFIG_IRQ_TIME_ACCOUNTING=y
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct IrqPressure {
/// This record indicates this share of time in which all non-idle tasks are stalled
/// simultaneously.
pub full: PressureRecord,
}

impl super::FromBufRead for IrqPressure {
fn from_buf_read<R: std::io::BufRead>(r: R) -> ProcResult<Self> {
let mut full = String::new();
let mut reader = r;
reader.read_line(&mut full)?;
Ok(IrqPressure {
full: parse_pressure_record(&full)?,
})
}
}

fn get_f32(map: &HashMap<&str, &str>, value: &str) -> ProcResult<f32> {
map.get(value).map_or_else(
|| Err(ProcError::Incomplete(None)),
Expand Down
8 changes: 7 additions & 1 deletion procfs/examples/pressure.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use procfs::{prelude::*, CpuPressure, IoPressure, MemoryPressure, PressureRecord};
use procfs::{prelude::*, CpuPressure, IoPressure, IrqPressure, MemoryPressure, PressureRecord};

/// A basic example of /proc/pressure/ usage.
fn main() {
Expand All @@ -13,13 +13,19 @@ fn main() {
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);
}

if let Ok(pressure) = IrqPressure::current() {
println!("IRQ Pressure:");
print_pressure(pressure.full, 20);
}
}

fn print_pressure(pressure: PressureRecord, width: usize) {
Expand Down
4 changes: 4 additions & 0 deletions procfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ impl Current for IoPressure {
const PATH: &'static str = "/proc/pressure/io";
}

impl Current for IrqPressure {
const PATH: &'static str = "/proc/pressure/irq";
}

impl Current for SharedMemorySegments {
const PATH: &'static str = "/proc/sysvipc/shm";
}
Expand Down
Loading