Skip to content

Add device/edge CPU, network latency, switch penalty to offloading_decisions#68

Open
ff225 wants to merge 7 commits into
mainfrom
fix/sciot-061-offloading-decision-metrics
Open

Add device/edge CPU, network latency, switch penalty to offloading_decisions#68
ff225 wants to merge 7 commits into
mainfrom
fix/sciot-061-offloading-decision-metrics

Conversation

@ff225

@ff225 ff225 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #61.

The offloading_decisions JSON/CSV document was missing several fields the issue asked for, and had a redundant per-candidate selected boolean instead of relying on the document's existing top-level selected_layer:

  • Full device and edge CPU loads: device_cpu_percent (already computed client-side, just not surfaced at the document's top level) and new edge_cpu_percent, sampled server-side via psutil.cpu_percent() in request_handler.get_edge_cpu_percent() — mirrors the existing device-side pattern in http_client.py (module-level warm-up call, clamped to [0, 100], 0.0 fallback if psutil is unavailable or errors).
  • Network latency and speed: network_latency_ms (from the already-computed request round-trip time) alongside the existing avg_speed_bytes_per_second.
  • switch_penalty: promoted to the top level from the selected candidate (only populated for strategies with switch hysteresis, e.g. adaptive_risk; 0.0 for static).
  • Selected layer on top of the document instead of a boolean per candidate: the top-level selected_layer field already existed — removed the redundant per-candidate "selected" boolean in build_offloading_decision_event(). selected_candidate() (used by summarize_prediction_error and the analysis notebooks) now derives the selected candidate from selected_layer instead, with backward-compatible fallback to the boolean for older exported documents. scripts/analysis/telemetry_notebook_utils.py::selected_candidate() already had this fallback, so the analysis notebooks are unaffected.

Decision notes

  • Edge CPU load didn't exist anywhere in the codebase before this change (grepped for edge_cpu); added it using the same psutil-optional pattern already used for device_cpu_percent client-side, rather than inventing a new dependency or config surface.
  • Left the CSV/JSONL writers, schema version (offloading-decision.v1), and all other fields unchanged — this is an additive/cleanup change to the existing schema, not a new schema version.

Test plan

  • Added test_offloading_decision_event_includes_load_and_network_metrics and test_offloading_decision_event_defaults_load_and_network_metrics_to_zero in tests/unit/test_offloading_decision_events.py; updated the existing selected-candidate test to assert the boolean is gone and selected_candidate() still resolves correctly.
  • Added get_edge_cpu_percent unit tests in tests/unit/test_request_handler_helpers.py (clamping, missing psutil, psutil raising).
  • Updated docs/OFFLOADING_DECISION_EVENTS.md schema table and CSV example.
  • uv run pytest tests/unit -q — 150 passed, 1 skipped
  • Fast CI suite (tests/unit, integration subset, mqtt, offloading_algo) — 208 passed, 1 skipped, no regressions

ff225 and others added 7 commits July 15, 2026 10:15
…alty to offloading_decisions

The offloading_decisions document lacked device/edge CPU load, network
latency, and switch penalty, and duplicated the selected layer as a
per-candidate boolean instead of relying on the existing top-level
selected_layer field. Add the four missing top-level metrics (edge CPU
sampled server-side via psutil, mirroring the existing device-side
metric) and drop the redundant per-candidate boolean, with
backward-compatible lookup for older documents.

Closes #61
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.

Data change in Firestore

1 participant