Skip to content

Commit

Permalink
Support /proc/[pid]/task/[tid]/status (prometheus#110)
Browse files Browse the repository at this point in the history
Signed-off-by: koushiro <[email protected]>
  • Loading branch information
koushiro authored Nov 13, 2020
1 parent 04548e1 commit bf5ef09
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/process/task.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};

use super::{FileWrapper, Io, ProcError, Stat};
use super::{FileWrapper, Io, ProcError, Stat, Status};
use crate::ProcResult;

/// A task (aka Thread) inside of a [`Process`](crate::process::Process)
Expand Down Expand Up @@ -37,6 +37,13 @@ impl Task {
Stat::from_reader(FileWrapper::open(self.root.join("stat"))?)
}

/// Thread info from `/proc/<pid>/task/<tid>/status`
///
/// Many of the returned fields will be the same as the parent process
pub fn status(&self) -> ProcResult<Status> {
Status::from_reader(FileWrapper::open(self.root.join("status"))?)
}

/// Thread IO info from `/proc/<pid>/task/<tid>/io`
///
/// This data will be unique per task.
Expand Down Expand Up @@ -117,6 +124,7 @@ mod tests {
for task in me.tasks().unwrap() {
let task = task.unwrap();
let stat = task.stat().unwrap();
let status = task.status().unwrap();
let io = task.io().unwrap();

summed_io.rchar += io.rchar;
Expand All @@ -127,12 +135,12 @@ mod tests {
summed_io.write_bytes += io.write_bytes;
summed_io.cancelled_write_bytes += io.cancelled_write_bytes;

if stat.comm == "one" {
if stat.comm == "one" && status.name == "one" {
found_one = true;
assert!(io.rchar >= bytes_to_read);
assert!(stat.utime >= 50, "utime({}) too small", stat.utime);
}
if stat.comm == "two" {
if stat.comm == "two" && status.name == "two" {
found_two = true;
assert_eq!(io.rchar, 0);
assert_eq!(stat.utime, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/process/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ fn test_all() {
for task in tasks {
let task = task.unwrap();
check_unwrap(&prc, task.stat());
check_unwrap(&prc, task.status());
check_unwrap(&prc, task.io());
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/sys/fs/binfmt_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ pub fn enabled() -> ProcResult<bool> {
Ok(val == "enabled")
}

/*
struct BinFmtEntry {
pub enabled: bool,
pub interpreter: String,
pub flags: (),
pub offset: u8,
pub magic: Vec<u8>,
}
*/

#[cfg(test)]
mod tests {
Expand Down
2 changes: 2 additions & 0 deletions support.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ This is an approximate list of all the files under the `/proc` mount, and an ind
* [ ] `/proc/[pid]/syscall`
* [ ] `/proc/[pid]/task`
* [x] `/proc/[pid]/task/[tid]/stat`
* [x] `/proc/[pid]/task/[tid]/status`
* [x] `/proc/[pid]/task/[tid]/io`
* [ ] `/proc/[pid]/task/[tid]/children`
* [ ] `/proc/[pid]/timers`
* [ ] `/proc/[pid]/timerslack_ns`
Expand Down

0 comments on commit bf5ef09

Please sign in to comment.