Skip to content

A linux Pressure Stall Information (PSI) file descriptor wrapper / monitor library for Rust.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

chise0713/presutaoru

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

presutaoru (ぷれすたおる)

A linux Pressure Stall Information (PSI) file descriptor monitor library for Rust.

Example

use presutaoru::{PsiFdBuilder, PsiEntry, StallType, PsiMonitor};
use std::time::Duration;

let psi_fd = PsiFdBuilder::default()
    .entry(presutaoru::PsiEntry::Cpu)
    .stall_type(presutaoru::StallType::Some)
    .stall_amount(Duration::from_micros(500))
    .time_window(Duration::from_secs(1))
    .build()
    .unwrap();

Addionally, to monitor PSI events, enable the monitor feature.

//! [dependencies]
//! presutaoru = { version = "0.1", features = ["monitor"] }
let mut monitor = PsiMonitor::new();
monitor.add_fd(psi_fd);

Running the monitor

When using std::thread:

// same as above
//! [dependencies]
//! presutaoru = { version = "0.1", features = ["monitor", "thread"] }
let mut thread = monitor.into_thread().unwrap();
thread.start().unwrap();

while let Ok(r) = thread.recv() {
    match r {
        Event::Ready(id) => println!("psi event triggerd on: {:?}", id),
        Event::Failure(e) => eprintln!("{}", e.to_string()),
    }
}

Or register the file desc to tokio's reactor:

// same as above
//! [dependencies]
//! presutaoru = { version = "0.1", features = ["monitor", "tokio"] }
use presutaoru::tokio::PsiTokioReactor;

let mut job = monitor.into_tokio_reactor().unwrap();
job.start().unwrap();

while let Ok(r) = job.recv().await {
    match r {
        Event::Ready(id) => println!("psi event triggerd on: {:?}", id),
        Event::Failure(e) => eprintln!("{}", e.to_string()),
    }
}

All file descriptors will be closed when the monitor or its thread / job are dropped.

// ...
drop(monitor); // all fds are closed here
// ...
// in the thread example
drop(thread); // all fds are closed here
// ...
// in the tokio example
drop(jobs);   // all fds are closed here

Features

  • monitor: Enable PSI event monitoring functionality.
  • thread: Enable monitoring using std::thread.
  • tokio: Enable monitoring using tokio's reactor.

All features are disabled by default.

thread and tokio features require monitor feature to be enabled.

License

This project is licensed under either of

at your option.

About

A linux Pressure Stall Information (PSI) file descriptor wrapper / monitor library for Rust.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages