Skip to content

Report edge CPU time as delta ratio instead of cumulative (#71)#81

Open
ff225 wants to merge 1 commit into
mainfrom
fix/sciot-071-cpu-times-delta-ratio
Open

Report edge CPU time as delta ratio instead of cumulative (#71)#81
ff225 wants to merge 1 commit into
mainfrom
fix/sciot-071-cpu-times-delta-ratio

Conversation

@ff225

@ff225 ff225 commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

get_edge_system_metrics() (src/server/communication/request_handler.py:118) read psutil.cpu_times() and reported cpu_idle/cpu_user/cpu_system directly. Those fields are cumulative seconds since boot, so in offloading-decision telemetry they only ever grow and don't reflect current edge load.

Fix

get_edge_system_metrics() now keeps the previous cpu_times() sample (module-level, behind a lock since the handler can run concurrently across ASGI request threads) and reports each field's share of the delta since the last call:

  • First call: no prior sample exists, so cpu_idle/cpu_user/cpu_system are 0.0 (all other fields — cpu_count, cpu_freq, load averages, memory — are unaffected and still reported immediately).
  • Subsequent calls: cpu_idle = delta(idle) / delta(total), same for user/system, giving a 0..1 ratio of time spent in each state since the previous call rather than an ever-growing absolute count.

The delta total is computed across all cpu_times() fields available on the platform (idle, user, system, nice, iowait, irq, softirq, steal, guest, guest_nice), not just the three reported ones, so the ratios are correct even on platforms exposing extra states.

Files

  • src/server/communication/request_handler.py

Test plan

  • Updated tests/unit/test_request_handler_helpers.py: first call returns 0.0 ratios (previously asserted raw cumulative values), second call asserts the correct delta ratios given a fake psutil.
  • uv run pytest tests/unit/test_request_handler_helpers.py tests/unit/test_offloading_decision_events.py -q — 36 passed
  • Fast CI suite — 215 passed, 1 skipped
  • ruff check on changed files — clean (no new formatting issues introduced; the file has pre-existing unrelated formatting drift not touched here)

Closes #71

psutil.cpu_times() returns cumulative seconds since boot; reporting
those directly in offloading telemetry made cpu_idle/user/system
grow monotonically and useless for comparing device load over time.
get_edge_system_metrics() now keeps the previous sample and reports
each field's share of the delta since the last call instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cpu_times report cumulative times

1 participant