Skip to content

[code-reusability] Reuse shared bytes-to-MiB conversion - #264

Open
Pedro Henrique Penna (ppenna) wants to merge 1 commit into
devfrom
code-reusability/shared-bytes-to-mib-313e30b848df9b39
Open

Pedro Henrique Penna (ppenna) wants to merge 1 commit into
devfrom
code-reusability/shared-bytes-to-mib-313e30b848df9b39

Conversation

@ppenna

Copy link
Copy Markdown
Contributor

Summary

Move the existing internal benchmark.bytes_to_mib() helper to nvx_tools.common and reuse it for lifecycle result collection and diagnostics in performance.py.

The helper's existing callers are the ten benchmark RSS formatting and summary paths in scripts/nvx_tools/benchmark.py. The second call site is lifecycle performance conversion in read_lifecycle_data() and append_openvmm_diagnostics(), which repeated value / (1024 * 1024) through BYTES_PER_MIB.

For every int or float these sites pass, bytes_to_mib(value) returns the identical float division result. The surrounding unit selection, formatting precision, metrics, messages, and errors are unchanged. The existing focused lifecycle collection test verifies both converted metric values and rendered MiB diagnostics; the helper's existing benchmark callers remain covered by the full suite.

Evidence

Open issues, open pull requests, active workflow changes, and pull-request history were checked for bytes_to_mib, BYTES_PER_MIB, and the bytes-to-MiB concern. No active, rejected, or duplicate proposal covers this reuse. Active workflow PRs concern snapshot tiers, TCP console cleanup, and usage documentation, and do not overlap these functions or files. Prior merged reusability PRs cover different helpers.

Patch

  • scripts/nvx_tools/common.py
  • scripts/nvx_tools/benchmark.py
  • scripts/nvx_tools/performance.py
  • 19 total added-plus-deleted lines across 3 files

Validation

  • python -m unittest scripts.test_performance.PerformanceTests.test_collects_openvmm_json_and_appends_diagnostics -v - passed (1 test)
  • python -m unittest scripts/test_performance.py scripts/test_nvx_tools.py scripts/test_microvm_tests.py scripts/test_development_release.py -v - passed (362 tests, 6 skipped)
  • python scripts/test_adversarial.py -v - passed (55 tests)
  • python .github/skills/nvx-host-connect/scripts/test_hosts.py -v - passed (4 tests)
  • python -m compileall -q scripts - passed
  • python -m ruff check scripts - passed
  • python -m pyright --pythonplatform Linux - passed
  • python -m pyright --pythonplatform Windows - passed
  • python -m ruff format --check scripts - passed
  • python scripts/nvx.py --help - passed
  • python scripts/nvx.py test-openvmm-unit --help - passed
  • python scripts/nvx.py test-openvmm --help - passed
  • python scripts/nvx.py test-microvm --help - passed
  • python scripts/nvx.py test-adversarial --help - passed
  • python scripts/nvx.py benchmark --help - passed
  • git diff --check - passed

No dependency, public API/CLI/ABI, gitlink, or OpenVMM change was made. Hardware, private-submodule, and OpenVMM checks were not applicable and were not run.

Generated by code-reusability · copilot · gpt56 · 120.4 AIC · ⌖ 24 AIC · ⊞ 16.3K · ◷

  • expires on Oct 13, 2026, 9:49 PM UTC

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 29, 2026 21:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The refactor preserves the conversion and has no unresolved findings.

Review effort: Balanced
Findings: None

What changed in this PR

This PR moves the bytes-to-MiB helper into nvx_tools.common so benchmark and lifecycle reporting share the same conversion.

Changes:

  • Reuse the shared helper for benchmark RSS reporting.
  • Use it for lifecycle metrics and OpenVMM diagnostics.
File Description
scripts/​nvx_tools/​performance.py Uses the shared helper for lifecycle conversions.
scripts/​nvx_tools/​common.py Defines the shared helper.
scripts/​nvx_tools/​benchmark.py Imports the helper instead of defining it locally.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ppenna
Pedro Henrique Penna (ppenna) marked this pull request as ready for review September 30, 2026 05:40
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.

2 participants