Debian Codegraph @

third_party/rust/procfs-core/src/process/schedstat.rs

raw
1 use crate::from_iter;
2 use crate::ProcResult;
3 use std::io::Read;
4
5 #[cfg(feature = "serde1")]
6 use serde::{Deserialize, Serialize};
7
8 /// Provides scheduler statistics of the process, based on the `/proc/<pid>/schedstat` file.
9 #[derive(Debug, Clone)]
10 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
11 pub struct Schedstat {
12 /// Time spent on the cpu.
13 ///
14 /// Measured in nanoseconds.
15 pub sum_exec_runtime: u64,
16 /// Time spent waiting on a runqueue.
17 ///
18 /// Measured in nanoseconds.
19 pub run_delay: u64,
20 /// \# of timeslices run on this cpu.
21 pub pcount: u64,
22 }
23
24 impl crate::FromRead for Schedstat {
25 fn from_read<R: Read>(mut r: R) -> ProcResult<Self> {
26 let mut line = String::new();
27 r.read_to_string(&mut line)?;
28 let mut s = line.split_whitespace();
29
30 let schedstat = Schedstat {
31 sum_exec_runtime: expect!(from_iter(&mut s)),
32 run_delay: expect!(from_iter(&mut s)),
33 pcount: expect!(from_iter(&mut s)),
34 };
35
36 if cfg!(test) {
37 assert!(s.next().is_none());
38 }
39
40 Ok(schedstat)
41 }
42 }