fix(daemon): compute dora top disk-I/O rate from the real sampling window - #3109
fix(daemon): compute dora top disk-I/O rate from the real sampling window#3109phil-opp wants to merge 1 commit into
dora top disk-I/O rate from the real sampling window#3109Conversation
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
ce49a6e to
0100960
Compare
…ndow `collect_and_send_metrics_bg` divided the per-refresh disk byte deltas (from sysinfo's `disk_usage()`, which report bytes since the previous `refresh_processes_specifics` call) by a hard-coded `METRICS_INTERVAL_SECS` (2 s). That constant is only correct when refreshes are exactly one interval apart, so `dora top`'s "I/O READ"/"I/O WRITE" columns over-reported in two cases: - First sample: the metrics `System` starts empty (and is reset to empty if a refresh ever panics), so sysinfo has no baseline and reports the process's total-since-start I/O. Divided by 2 s that is a large spurious spike for every freshly spawned node. - Skipped/catch-up cycle: when a prior collection still holds the lock the cycle is skipped, so the next refresh covers ~two intervals of I/O but is still divided by one — roughly doubling the reported rate. Track the wall-clock instant of the previous successful refresh and divide by the measured window instead. A new `disk_rate_bytes_per_sec` helper returns `None` (no rate reported) when there is no prior baseline or the window is implausibly short, mirroring how CPU% is meaningless on first observation. Unit-tested for the no-baseline, near-zero-window, and actual-window cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PYiYgEo2WKBXfGooqP2WG5
0100960 to
28ab3b7
Compare
|
🤖 Automated review by Claude — this is a fully automated review with no human in the loop. Treat it as advisory. Reviewed the diff — no issues found. The new Generated by Claude Code |
Issue
collect_and_send_metrics_bg(binaries/daemon/src/lib.rs) turns per-refresh disk byte deltas into a rate by dividing by a hard-coded constant:disk_read/disk_writtencome from sysinfo'sprocess.disk_usage(), which reports bytes since the previousrefresh_processes_specificscall — not "over the last 2 s". The constant divisor is only correct when refreshes are exactly one interval apart, so the user-facingdora top"I/O READ"/"I/O WRITE" columns over-report in two real cases:metrics_systemis initialized empty (sysinfo::System::new()) and reset to a fresh emptySystemif a refresh ever panics. On the first refresh after that, sysinfo has no prior baseline, soread_bytesis effectively the process's total-since-start I/O. Divided by 2 s that is a large spurious spike for every freshly spawned (or post-panic) node.try_lockfails and the cycle is skipped. The next successful refresh then covers ~two intervals of I/O but is still divided by one interval, roughly doubling the reported rate.Fix
Track the wall-clock
Instantof the previous successful refresh (newmetrics_last_refreshfield) and divide by the measured window instead of the constant. A new pure helper does the arithmetic:It returns
None— i.e. no rate reported for that sample — when there is no prior baseline (first refresh, or a poisoned lock) or the window is implausibly short (< 0.1 s), mirroring how CPU% is meaningless on a first observation.disk_read_bytes/disk_write_bytesare alreadyOption<u64>, soNoneflows through cleanly.The now-unused
METRICS_INTERVAL_SECSconstant is removed (METRICS_INTERVALitself is still used to drive the interval timer).Scope note
This fixes the divisor and the daemon's first-sample case. A process appearing for the very first time in an already-warm
System(or a newly spawned descendant folded into the aggregate) can still momentarily reflect sysinfo's total-since-start delta for that single sample — that is an inherent sysinfo behavior, out of scope here.Validation
New unit tests cover: no baseline →
None; near-zero window →None; 8 MB over a 4 s window → 2 MB/s (the old constant divisor would have reported 4 MB/s); steady-state 2 s window unchanged.origin/mainbefore opening. Please review carefully before merging.🤖 Generated with Claude Code
Generated by Claude Code