Report edge CPU time as delta ratio instead of cumulative (#71)#81
Open
ff225 wants to merge 1 commit into
Open
Report edge CPU time as delta ratio instead of cumulative (#71)#81ff225 wants to merge 1 commit into
ff225 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_edge_system_metrics()(src/server/communication/request_handler.py:118) readpsutil.cpu_times()and reportedcpu_idle/cpu_user/cpu_systemdirectly. 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 previouscpu_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:cpu_idle/cpu_user/cpu_systemare0.0(all other fields —cpu_count,cpu_freq, load averages, memory — are unaffected and still reported immediately).cpu_idle = delta(idle) / delta(total), same foruser/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.pyTest plan
tests/unit/test_request_handler_helpers.py: first call returns0.0ratios (previously asserted raw cumulative values), second call asserts the correct delta ratios given a fakepsutil.uv run pytest tests/unit/test_request_handler_helpers.py tests/unit/test_offloading_decision_events.py -q— 36 passedruff checkon changed files — clean (no new formatting issues introduced; the file has pre-existing unrelated formatting drift not touched here)Closes #71