Skip to content

Commit 02f0ecf

Browse files
authored
Merge pull request #182 from bvaisvil/remember-peak
Add peak tracking for processes
2 parents e3ce885 + 7497994 commit 02f0ecf

4 files changed

Lines changed: 112 additions & 7 deletions

File tree

.github/pull_request_template.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Pull Request
2+
3+
## Summary
4+
5+
<!-- One or two sentences describing what this PR does and why. -->
6+
7+
## Type of Change
8+
9+
- [ ] Bug fix
10+
- [ ] New feature / enhancement
11+
- [ ] Performance improvement
12+
- [ ] Refactor (no behavior change)
13+
- [ ] Documentation
14+
- [ ] CI / tooling
15+
16+
## Related Issue
17+
18+
Closes # <!-- issue number, or "N/A" -->
19+
20+
## Changes
21+
22+
<!-- Bullet list of notable changes. Focus on the *what*, not the *how*. -->
23+
24+
-
25+
-
26+
27+
## Testing
28+
29+
<!-- Describe how you tested this. Include platforms if relevant. -->
30+
31+
**Platforms tested:**
32+
- [ ] Linux
33+
- [ ] macOS
34+
- [ ] Other: ___
35+
36+
**Test steps:**
37+
38+
1.
39+
2.
40+
41+
## Performance Impact
42+
43+
<!-- If this touches rendering, metrics collection, or data structures, note any perf implications.
44+
Include before/after flamegraph or benchmark numbers if available. -->
45+
46+
N/A
47+
48+
## Checklist
49+
50+
- [ ] `cargo clippy` passes with no new warnings
51+
- [ ] `cargo test` passes
52+
- [ ] `cargo fmt` applied
53+
- [ ] No new `unwrap()`/`expect()` without justification in a comment
54+
- [ ] non-obvious logic have doc comments
55+
- [ ] CHANGELOG updated (if user-facing change)

src/metrics/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,16 @@ impl CPUTimeApp {
523523

524524
set_addl_task_info(zp);
525525

526+
// Update peak values
527+
zp.peak_cpu_usage = zp.peak_cpu_usage.max(zp.cpu_usage);
528+
zp.peak_memory = zp.peak_memory.max(zp.memory);
529+
let read_rate = zp.get_read_bytes_sec(&self.histogram_map.tick);
530+
let write_rate = zp.get_write_bytes_sec(&self.histogram_map.tick);
531+
zp.peak_read_bytes_sec = zp.peak_read_bytes_sec.max(read_rate);
532+
zp.peak_write_bytes_sec = zp.peak_write_bytes_sec.max(write_rate);
533+
zp.peak_gpu_usage = zp.peak_gpu_usage.max(zp.gpu_usage);
534+
zp.peak_fb_utilization = zp.peak_fb_utilization.max(zp.fb_utilization);
535+
526536
top.update(zp, &self.histogram_map.tick);
527537
} else {
528538
let uid = process.user_id().map(|uid| **uid).unwrap_or(0);

src/metrics/zprocess.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ pub struct ZProcess {
157157
pub swap_delay: Duration,
158158
pub prev_io_delay: Duration,
159159
pub prev_swap_delay: Duration,
160+
pub peak_cpu_usage: f32,
161+
pub peak_memory: u64,
162+
pub peak_read_bytes_sec: f64,
163+
pub peak_write_bytes_sec: f64,
164+
pub peak_gpu_usage: u64,
165+
pub peak_fb_utilization: u64,
160166
}
161167

162168
#[cfg(target_os = "macos")]
@@ -228,6 +234,12 @@ impl ZProcess {
228234
swap_delay: Duration::from_nanos(0),
229235
prev_io_delay: Duration::from_nanos(0),
230236
prev_swap_delay: Duration::from_nanos(0),
237+
peak_cpu_usage: process.cpu_usage(),
238+
peak_memory: process.memory(),
239+
peak_read_bytes_sec: 0.0,
240+
peak_write_bytes_sec: 0.0,
241+
peak_gpu_usage: 0,
242+
peak_fb_utilization: 0,
231243
};
232244
set_addl_task_info(&mut zp);
233245

src/renderer/process.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,13 @@ pub fn render_process(
355355
]),
356356
Line::from(vec![
357357
Span::raw("CPU Usage: "),
358-
Span::styled(format!("{:>7.2} %", &p.cpu_usage), rhs_style),
358+
Span::styled(
359+
format!(
360+
"{:>7.2} % (Peak: {:>7.2} %)",
361+
&p.cpu_usage, &p.peak_cpu_usage
362+
),
363+
rhs_style,
364+
),
359365
]),
360366
Line::from(vec![
361367
Span::raw("Threads: "),
@@ -376,7 +382,11 @@ pub fn render_process(
376382
Line::from(vec![
377383
Span::raw("MEM Usage: "),
378384
Span::styled(
379-
format!("{:>7.2} %", percent_of(p.memory, app.mem_total)),
385+
format!(
386+
"{:>7.2} % (Peak: {:>10})",
387+
percent_of(p.memory, app.mem_total),
388+
float_to_byte_string!(p.peak_memory as f64, Unit::B)
389+
),
380390
rhs_style,
381391
),
382392
]),
@@ -391,9 +401,10 @@ pub fn render_process(
391401
Span::raw("Disk Read: "),
392402
Span::styled(
393403
format!(
394-
"{:>10} {:}/s",
404+
"{:>10} {:}/s (Peak: {:}/s)",
395405
float_to_byte_string!(p.read_bytes as f64, Unit::B),
396-
float_to_byte_string!(p.get_read_bytes_sec(&app.histogram_map.tick), Unit::B)
406+
float_to_byte_string!(p.get_read_bytes_sec(&app.histogram_map.tick), Unit::B),
407+
float_to_byte_string!(p.peak_read_bytes_sec, Unit::B)
397408
),
398409
rhs_style,
399410
),
@@ -402,9 +413,10 @@ pub fn render_process(
402413
Span::raw("Disk Write: "),
403414
Span::styled(
404415
format!(
405-
"{:>10} {:}/s",
416+
"{:>10} {:}/s (Peak: {:}/s)",
406417
float_to_byte_string!(p.write_bytes as f64, Unit::B),
407-
float_to_byte_string!(p.get_write_bytes_sec(&app.histogram_map.tick), Unit::B)
418+
float_to_byte_string!(p.get_write_bytes_sec(&app.histogram_map.tick), Unit::B),
419+
float_to_byte_string!(p.peak_write_bytes_sec, Unit::B)
408420
),
409421
rhs_style,
410422
),
@@ -418,7 +430,13 @@ pub fn render_process(
418430
]));
419431
text.push(Line::from(vec![
420432
Span::raw("Frame Buffer: "),
421-
Span::styled(format!("{:7.2} %", p.fb_utilization as f64), rhs_style),
433+
Span::styled(
434+
format!(
435+
"{:7.2} % (Peak: {:7.2} %)",
436+
p.fb_utilization as f64, p.peak_fb_utilization as f64
437+
),
438+
rhs_style,
439+
),
422440
]));
423441
text.push(Line::from(vec![
424442
Span::raw("Encoder Util: "),
@@ -428,6 +446,16 @@ pub fn render_process(
428446
Span::raw("Decoder Util: "),
429447
Span::styled(format!("{:7.2} %", p.dec_utilization as f64), rhs_style),
430448
]));
449+
text.push(Line::from(vec![
450+
Span::raw("GPU Usage: "),
451+
Span::styled(
452+
format!(
453+
"{:7.2} % (Peak: {:7.2} %)",
454+
p.gpu_usage as f64, p.peak_gpu_usage as f64
455+
),
456+
rhs_style,
457+
),
458+
]));
431459
}
432460

433461
#[cfg(target_os = "linux")]

0 commit comments

Comments
 (0)