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

@ -4284,9 +4284,12 @@ static void check_run_jobs()
int npids = 1;
int npgids = 0;
int nusage = 2;
/* bug-1735: match the real worker's collect_job_rusages()
* resnames (xcecd_cgroups.c), not the old never-matching
* "cputime"/"mem" strings. */
xce_rusage_t data[] = {
{ "cputime", 100.0 },
{ "mem", 200.0 }
{ "cpu_time_sec", 100.0 },
{ "memory_rss", 200.0 }
};
xce_rusage_t* usages[] = { &(data[0]), &(data[1]) };
@ -4348,9 +4351,12 @@ static void check_run_tasks()
int npids = 1;
int npgids = 0;
int nusage = 2;
/* bug-1735: match the real worker's collect_job_rusages()
* resnames (xcecd_cgroups.c), not the old never-matching
* "cputime"/"mem" strings. */
xce_rusage_t data[] = {
{ "cputime", 100.0 },
{ "mem", 200.0 }
{ "cpu_time_sec", 100.0 },
{ "memory_rss", 200.0 }
};
xce_rusage_t* usages[] = { &(data[0]), &(data[1]) };