Skip to content

Show windowed BEAM CPU and RSS metrics in the TUI - #144

Merged
zhongwencool merged 3 commits into
mainfrom
zw/tui-runtime-metrics
Oct 5, 2026
Merged

zhongwencool merged 3 commits into
mainfrom
zw/tui-runtime-metrics

Conversation

@zhongwencool

@zhongwencool zhongwencool commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Replace platform-dependent ps %CPU/%MEM fields with actual-window BEAM process CPU (user + system, 100% per logical CPU), current RSS, and signed RSS changes in Home and System.

  • Use Linux proc counters with cached tick/page units and controlled macOS ps counters, with bounded output, deadlines, child cleanup, and independent unavailable/warm-up states.

  • Show separate Normal/Dirty CPU scheduler busy summaries only with the existing scheduler-usage toggle. Reuse its samples and single registration; keep the default off and release the registration with the existing render worker.

  • Preserve process-row capacity, fix the 139-column summary edge, retain RSS changes in narrow System cells, and document measurement semantics and failure recovery.

  • Simplify Home management by removing the obsolete token argument; retain legacy cleanup compatibility, use direct compact-unit formatting, and reuse CPU-window value formatting.

Integration

Merged the latest main (e0189c2, CLI 2.1.0) into this branch. The task-first CLI, explicit targets, schema contracts, and release version remain intact. The PR diff is limited to this TUI metrics feature and its tests/docs.

Validation after merging main

  • Full EUnit: 916 tests, 0 failures, with ERL_FLAGS='+S 4:4 +SDcpu 4:4'.
  • Focused TUI/runtime-metrics suite: 125 tests, 0 failures.
  • rebar3 compile, rebar3 fmt --check, rebar3 lint, rebar3 xref, rebar3 dialyzer, rebar3 docs, and git diff --check: passed.
  • scripts/escript-smoke.sh: passed, including TUI stdin-EOF cleanup.
  • Public schema generation: passed. Validated 97 capture responses and 47 agent-workflow responses, packaged schemas, and deliberate negative cases.
  • Isolated task-first CLI agent workflow: passed.
  • An initial full-suite run timed out while booting the peer for the upstream stalled-code-server test (no assertion failures). That unchanged test passed independently; the bounded-scheduler full rerun passed.

Earlier feature/runtime validation

  • macOS OTP 26–29 and Linux OTP 28 focused suites passed.
  • Real 139-column macOS TTY walkthrough covered pause/resume, the shared scheduler toggle, Home/System transitions, readable RSS changes, and clean quit.
  • Same-PID top comparisons on macOS and Linux confirmed workload transitions. Linux windowed CPU was about 100% for one busy process and 395% for four, then returned to idle.
  • Owned memory-allocation and two-node smokes verified RSS/VM allocation observations and target PID sampling without enabling scheduler measurement.

Boundaries

No new public CLI flags or JSON fields, load averages, historical storage, automatic alerts, container-budget percentages, or scheduler-performance redesign. No production node changes or release publication. Linux OTP 26/27 were not exercised locally; cached Linux OTP 29 runtimes failed prim_tty initialization before sampling, so a complete Linux OTP matrix is not claimed. CI validation remains separate from these local results.

Changes:
- Replace platform-dependent ps percentages with user-plus-system CPU counter windows and current RSS with signed sample changes in Home and System.
- Add independent Linux proc and macOS ps counter parsing, cached Linux units, explicit warm-up and unavailable states, and view-local monotonic baselines.
- Bound OS command output and execution, terminate timed-out or interrupted children, and preserve process rows with compact CPU-window metadata.
- Preserve virtual-memory details, document metric semantics, and add parser, lifecycle, layout, and reproducible workload and remote-node smoke checks.

Validation:
- Run rebar3 compile, fmt --check, xref, dialyzer, and git diff --check successfully.
- Pass the full EUnit suite with 875 tests and zero failures; pass 14 focused runtime-metrics tests after the minimal-Linux cleanup fallback.
- Pass 114 focused tests and workload, memory-allocation, and remote-identity smokes on macOS OTP 26, 27, and 28 and Linux OTP 28; pass the macOS OTP 29 focused suite and smoke.
- Compare the same macOS BEAM PID with top: counter windows react to idle, single-worker, multi-worker, and stopped workloads and support values above 100 percent.
- Measure 30 Home collections against the baseline: median collection time changes from 25.43 ms to 11.41 ms; this is a local observation, not a general performance guarantee.
- Do not change the CLI JSON schema, push commits, or publish a release; scheduler-summary work follows separately.
Changes:
- Reuse the existing wall-time samples and diagnostic pool validation to show separate online Normal and Dirty CPU busy percentages only when scheduler usage is enabled.
- Keep the existing shortcut and default-off setting, add no sampler or registration, and attach the single measurement registration to the existing render worker so worker failure cannot leave it resident.
- Re-establish first, resumed, invalid, and topology-changed scheduler windows without fabricated zero values; preserve other tools' registrations and avoid redundant startup samples.
- Keep Home's 139-column summary within its existing height and preserve RSS changes in narrow System cells with documented IEC compact units.
- Fix CPU baseline recovery after a failed Linux proc read and distinguish process-ranking warm-up from independent CPU warm-up in regression tests.
- Update help and configuration reference without changing the public CLI or JSON contract.

Validation:
- Pass the complete EUnit suite: 883 tests, zero failures.
- Pass 122 focused tests on macOS OTP 26, 27, 28, and 29 and Linux OTP 28, including sampling-call tracing, registration preservation, worker-crash cleanup, and layout checks.
- Run rebar3 compile, fmt --check, xref, dialyzer, and git diff --check successfully; pass scripts/escript-smoke.sh including TUI EOF cleanup.
- Exercise a real 139-column macOS TTY: pause/resume, the shared scheduler toggle, Home/System transitions, readable RSS changes, and clean quit.
- Pass workload, memory-allocation, and remote-target identity smokes; the Linux OTP 28 process reaches about 100 percent with one worker and about 395 percent with four, then returns to idle.
- Do not claim Linux OTP 29 validation: the cached OTP 29 container runtimes fail prim_tty initialization before the sampler runs. Linux OTP 26 and 27 were not available in this run.
- Do not push, open a pull request, or publish a release.
Changes:
- Integrate origin/main at e0189c2, including the task-first CLI 2.1.0 entrypoint, target rules, and public schemas while preserving the TUI metrics feature.
- Remove the obsolete scheduler token argument from Home management, actions, and process navigation; keep registration ownership and release in the existing render worker.
- Preserve the exported cleanup entrypoint's legacy four-item resource form while using the two-process resource form internally.
- Replace compact-unit replacement passes with the existing formatter's number/unit split and reuse window_value for valid CPU-window text.
- Keep equivalent lint-compliant guard semantics and add cleanup compatibility, registration preservation, compact-unit, and window-state regressions.

Validation:
- Pass the focused suite with 125 tests and zero failures.
- Pass the full EUnit suite with 916 tests and zero failures using ERL_FLAGS='+S 4:4 +SDcpu 4:4'.
- Pass compile, fmt --check, lint, xref, dialyzer, escript smoke including TUI EOF cleanup, and diff checks after the simplifications.
- Previously pass generated documentation, public schema generation, 97 capture fixtures, 47 agent-workflow fixtures, packaged schemas, negative cases, and the isolated task-first agent workflow after integrating main.
- Preserve both merge parents; update only the existing PR branch without changing production nodes or publishing a release.
@zhongwencool
zhongwencool force-pushed the zw/tui-runtime-metrics branch from b4c6898 to 100a615 Compare October 5, 2026 10:19
@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.24088% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.02%. Comparing base (9682931) to head (100a615).
⚠️ Report is 32 commits behind head on main.

Files with missing lines Patch % Lines
src/observer_cli_runtime_metrics.erl 89.26% 19 Missing ⚠️
src/observer_cli.erl 94.02% 4 Missing ⚠️
src/observer_cli_snapshot.erl 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #144      +/-   ##
==========================================
- Coverage   97.65%   95.02%   -2.64%     
==========================================
  Files          27       34       +7     
  Lines        8452     9451     +999     
==========================================
+ Hits         8254     8981     +727     
- Misses        198      470     +272     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zhongwencool
zhongwencool merged commit 3fcd50b into main Oct 5, 2026
8 checks passed
@zhongwencool
zhongwencool deleted the zw/tui-runtime-metrics branch October 5, 2026 11:23
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.

1 participant