3 releases

0.1.2 Oct 17, 2019
0.1.1 Aug 31, 2019
0.1.0 Aug 31, 2019

#620 in Unix APIs

34 downloads per month

MPL-2.0 license

22KB
557 lines

PSI (Pressure Stall Information)

Utilities for working with PSI on Linux 4.20+.

Documentation Build Status Crate

Usage

[dependencies]
psi = "0.1"

License

Copyright (c) Chris Manning

This project is licensed under the MPL-2.0 license.


lib.rs:

Linux Pressure Stall Information (PSI) support for Rust.

About

The Linux Pressure Stall Information (PSI) feature provides real-time pressure information for CPU, IO and memory. psi is a rust library for reading PSI and monitoring for pressure thresholds on Linux 4.20+.

Example

use crate::psi::*;

fn example() -> Result<()> {
    let all: AllPsiStats = PsiKind::Memory.read_psi()?;
    if all.some.avg10 > 0.1f32 {
        // do something
    }
    let full: Psi = PsiKind::Memory.read_psi_line(PsiLine::Full)?;
    if full.avg60 > 0.1f32 {
        // do something else
    }
    Ok(())
}

Monitor Example

use std::time::Duration;
use crate::psi::*;

fn example() -> Result<()> {
    let mut monitor = PsiMonitor::new()?;
    let oom_id = monitor.add_trigger(
        Trigger::new_builder()
            .memory()
            .full()
            .stall(Duration::from_millis(100))
            .window(Duration::from_millis(500))
            .build(),
    )?;

    loop {
        let psi_event: PsiEvent = monitor.wait_single()?;
        // react to psi_event
    }
}

TODO

  • cgroup2 support

Dependencies

~115KB