fix(bug-1736): capture memory_swap/tasks_current, compute peak_cpu_time

The worker's rusage collector already measures and sends
"memory_swap"/"tasks_current" per job, but xce_host_runusage_t had no
field to receive them at all -- a complete dead end, not a naming
mismatch like bug-1735's cpu_time/mem_usage. Added mem_swap/
tasks_current fields (types.h), matching capnp fields on HostRunusage
(controller.capnp, new ordinals @3/@4) for WAL field-completeness, and
wired update_host_runusage() (misc.c) to parse them. Also fixed
merge_job_runusage()'s (job.c) existing-host merge branch, which only
copied cpu_time/mem_usage per host -- the two new fields would
otherwise have been silently dropped on WAL replay/catchup for a host
already seen.

Also computed peak_cpu_time as the running max of aggregate_job_
runusage()'s per-call cpu_time sum across every report a job has ever
received, guarding against a later report reducing it.

Deliberately NOT computed: peak_cpu_duration and the three efficiency
fields (mem_efficiency/avg_cpu_efficiency/peak_cpu_efficiency) -- these
need a "used vs. requested" ratio against a job's resource request (a
resreq expression tree, not a plain core/slot count) and/or an
unspecified duration semantic. A documented scope decision, not an
oversight -- see aggregate_job_runusage()'s doc comment.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019QxaSzHRB7pmYFp4cVnwkA
This commit is contained in:
Rongsong Shen 2026-08-30 15:32:02 +00:00
parent dfcd345ded
commit 5c2c6664e5
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
5 changed files with 169 additions and 26 deletions

View file

@ -977,8 +977,10 @@ void merge_job_runusage(xce_job_runusage_t** dst, xce_job_runusage_t* src)
if (matched >= 0) {
/* Existing host: overwrite scalars only. d's host_name pointer
* (possibly xstring-backed) is never touched or freed here. */
d->host_runusage[matched]->cpu_time = sh->cpu_time;
d->host_runusage[matched]->mem_usage = sh->mem_usage;
d->host_runusage[matched]->cpu_time = sh->cpu_time;
d->host_runusage[matched]->mem_usage = sh->mem_usage;
d->host_runusage[matched]->mem_swap = sh->mem_swap;
d->host_runusage[matched]->tasks_current = sh->tasks_current;
} else {
/* Genuinely new host: append, transferring ownership of sh's
* own plain-malloc'd host_name directly -- never xstring. */