Skip to content

fix: count DRAM in RAPL energy total - #1344

Open
davidberenstein1957 wants to merge 1 commit into
masterfrom
fix/rapl-include-dram
Open

fix: count DRAM in RAPL energy total#1344
davidberenstein1957 wants to merge 1 commit into
masterfrom
fix/rapl-include-dram

Conversation

@davidberenstein1957

Copy link
Copy Markdown
Collaborator

On Linux, rapl_include_dram=True selected DRAM domains and read them every cycle, but their energy never reached the reported total — the result was identical to rapl_include_dram=False while the log claimed DRAM was included.

What changed

codecarbon/core/cpu.py_create_rapl_files now assigns the Power-Gadget-compatible display name Processor Energy Delta_N(kWh) to DRAM domains as well as package/psys. Previously DRAM fell into the else branch and kept its raw sysfs name dram, which the aggregator in codecarbon/external/hardware.py (^Processor Energy Delta_\d) filters out.

DRAM domains only reach _create_rapl_files when rapl_include_dram is true — they are filtered out earlier otherwise — so the default path is unchanged. This also makes Linux match Windows EMI, which already names every selected channel this way (codecarbon/core/windows_emi.py:581) and so has never had the bug.

How it was verified

Added test_rapl_include_dram_energy_is_aggregated in tests/test_rapl_parameters.py, parametrized over both flag values. It builds a fake sysfs tree with package-0 and dram, advances both counters, calls get_cpu_details(), and asserts the summed Processor Energy Delta_* value. With rapl_include_dram=True it expects package + DRAM; it fails on master (package-only) and passes with this change. The False case pins the default path.

test_rapl_include_dram_true_explicit was updated: it previously asserted a RAPL file was still named dram, which is exactly the behaviour being fixed. It now asserts both domains carry aggregated names.

The suite is gated on Linux and CI will exercise it; locally (macOS) the tests were driven directly with sys.platform patched, and all tests in test_rapl_parameters.py and test_rapl_mmio_scanning.py pass.

Note for the changelog

This is a measurement change: anyone already setting rapl_include_dram=True will see reported CPU energy increase (correctly). DRAM is typically 10-20% of package power on memory-heavy workloads.

Closes#1305

🤖 Generated with Claude Code

@codecov

codecovBot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.43%. Comparing base (3ec31a0) to head (0a24bdb).

Additional details and impacted files
@@ Coverage Diff @@## master #1344 +/- ##
=======================================
Coverage 91.43% 91.43% =======================================
Files 49 49 Lines 5057 5058 +1 =======================================
+ Hits 4624 4625 +1 
Misses 433 433 

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@davidberenstein1957
davidberenstein1957 marked this pull request as ready for review August 12, 2026 17:37
@davidberenstein1957
davidberenstein1957 requested a review from a team as a code ownerAugust 12, 2026 17:37
@davidberenstein1957
davidberenstein1957force-pushed the fix/rapl-include-dram branch 2 times, most recently from f5a7183 to cb38949CompareAugust 19, 2026 14:29
Aggregate the dram domain into the reported processor energy alongside package/psys, with tests covering aggregation and the non-power-domain fallback.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rapl_include_dram=True reads DRAM domains but never adds them to the energy total

1 participant

@davidberenstein1957