taskstats/
lib.rs

1//! This crate provides a high-level encapsulation of Linux's
2//! [per-task statistics interface](https://www.kernel.org/doc/html/latest/accounting/taskstats.html).
3//!
4//! Currently only limited information is exposed in `Taskstats` struct,
5//! but new field can be easily added for future version.
6//! If there are any other fields in `taskstats` struct useful to you,
7//! feel free to submit PR to add them.
8//!
9//! ## Examples
10//!
11//! Query aggregated taskstats of a task:
12//! ```no_run
13//! # use taskstats::{TaskstatsConnection, TaskstatsListener};
14//! # use std::ffi::CString;
15//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
16//! let mut conn = TaskstatsConnection::new()?;
17//! let stats = conn.get_pid_stats(1)?;
18//! // ...
19//! # Ok(())
20//! # }
21//! ```
22//!
23//! Listen to taskstats of exited tasks:
24//! ```no_run
25//! # use taskstats::{TaskstatsConnection, TaskstatsListener};
26//! # use std::ffi::CString;
27//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
28//! let conn = TaskstatsConnection::new()?;
29//! let cpu_mask = CString::new("0-7\0".to_owned()).unwrap().into_boxed_c_str();
30//! let mut listener = TaskstatsListener::register(conn, cpu_mask)?;
31//! loop {
32//!     let (pid, stats) = listener.get_next()?;
33//!     // ...
34//! }
35//! # }
36//! ```
37//!
38//! ## Note
39//!
40//! This crate only exposes stats for pid / task, but not tgid / process,
41//! because the kernel doesn't really pass much useful information for tgid.
42//! It is recommended that you rely on pid stats and aggregate for process manually.
43
44mod conn;
45mod error;
46mod genetlink;
47mod listener;
48mod netlink;
49mod parse;
50mod raw;
51mod taskstats;
52
53pub use self::conn::TaskstatsConnection;
54pub use self::error::{Error, InvalidMessage};
55pub use self::listener::TaskstatsListener;
56pub use self::taskstats::Taskstats;