Skip to content

Commit 09194a5

Browse files
Legit fix for cputime (including stime)
1 parent dce1d7c commit 09194a5

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/psq/main.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ fn main() {
3535
// Assume hertz is 100.
3636
// TODO: Look this up via syscall (no /proc value for it)
3737
let hertz = 100;
38-
// let minute_hertz = hertz * 60;
39-
// let hour_hertz = minute_hertz * 60;
38+
let minute_hertz = hertz * 60;
39+
let hour_hertz = minute_hertz * 60;
4040

4141
let mut table = Table::init(
4242
pids.iter().map(|p| {
@@ -66,19 +66,17 @@ fn main() {
6666
},
6767
(_, true) => {
6868
let rss = p.status.vmrss.map(|m| (m / 1024).to_string()).unwrap_or("".to_owned());
69-
// FIXME: This algorithm is definitely wrong
70-
let _second_utime = p.stat.utime / hertz;
71-
let second_utime = _second_utime % 60;
72-
let _minute_utime = _second_utime / 60;
73-
let minute_utime = _minute_utime % 60;
74-
let hour_utime = _minute_utime / 60;
75-
let utime = format!(
69+
let raw_time = p.stat.utime + p.stat.stime;
70+
let second_utime = raw_time / hertz % 60;
71+
let minute_utime = raw_time / minute_hertz % 60;
72+
let hour_utime = raw_time / hour_hertz % 60;
73+
let cputime = format!(
7674
"{:02}:{:02}:{:02}",
7775
hour_utime,
7876
minute_utime,
7977
second_utime
8078
);
81-
row![p.stat.pid, p.stat.ppid, rss, utime, name]
79+
row![p.stat.pid, p.stat.ppid, rss, cputime, name]
8280
}
8381
}
8482
}).collect::<Vec<_>>()

0 commit comments

Comments
 (0)