fix(bug-1735): job memory/CPU usage always read 0 in scheduler replay

Two independent gaps in misc.c/job.c, both silently zeroing every real
job's resource-usage data:

- update_host_runusage() matched worker rusage report resnames
  "cputime"/"mem", but the real worker's collector
  (collect_job_rusages(), xcecd_cgroups.c) sends "cpu_time_sec"/
  "memory_rss" -- the two never matched, so cpu_time/mem_usage stayed
  at their calloc()'d zero for every non-simulated job. Aligned both
  sides, including xce_test's own simulated-worker fixture.
- update_job_rusages() had a standing FIXME: xce_job_runusage_t's
  job-level max_mem/avg_mem/used_mem/cpu_time were never derived from
  the per-host host_runusage[] entries. Added aggregate_job_runusage()
  (sum/max/avg across hosts) and wired it in right after the per-host
  update.

Added test_host_runusage.c (standalone unit test, mirrors
resval_typeresolve_unit_test's isolation pattern) plus the
controller_unit_test stub aggregate_job_runusage() needs since that
target excludes the real misc.c.

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:07:33 +00:00
parent ccef561031
commit d8a37fa27a
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
7 changed files with 335 additions and 10 deletions

View file

@ -355,3 +355,27 @@ test('resval typeresolve test', resval_typeresolve_unit_test,
timeout: 60,
env: ['ASAN_OPTIONS=detect_leaks=0'])
# bug-1735: misc.c's update_host_runusage()/aggregate_job_runusage() are
# small, dependency-light functions (calloc/realloc/strcmp only, no RTTI
# locking, no networking) -- standalone binary linking the REAL misc.c
# directly, mirroring resval_typeresolve_unit_test's isolation rationale
# above. get_ep_worker()/get_ep_role() (same file, RTTI-backed) are unused
# by these tests but still link fine via controller_unit_test_deps' existing
# librtti_dep.
host_runusage_unit_test_src = [
'testsuite/test_host_runusage.c',
'misc.c',
]
host_runusage_unit_test = executable('host_runusage_unit_test',
host_runusage_unit_test_src,
include_directories: [incdir],
dependencies: controller_unit_test_deps,
c_args: ['-DXCE_TESTING'],
install: false)
test('host runusage test', host_runusage_unit_test,
suite: 'controller',
timeout: 60,
env: ['ASAN_OPTIONS=detect_leaks=0'])