Skip to content

fix: count DRAM in RAPL energy total - #1344

Open
davidberenstein1957 wants to merge 2 commits into
masterfrom
fix/rapl-include-dram
Open

fix: count DRAM in RAPL energy total#1344
davidberenstein1957 wants to merge 2 commits 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

davidberenstein1957 and others added 2 commits August 12, 2026 17:25
rapl_include_dram=True selected DRAM domains but _create_rapl_files only
gave the Power-Gadget-compatible 'Processor Energy Delta_N(kWh)' name to
package/psys domains. DRAM kept its raw sysfs name, so the aggregator in
external/hardware.py dropped its energy and reported package-only totals.

Name DRAM domains like package/psys, matching what Windows EMI already
does for emi_include_dram.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
test_rapl_both_parameters_together still asserted a RAPL file was named 'dram', which is the behaviour this branch fixes: DRAM domains now get the aggregated 'Processor Energy Delta_N(kWh)' name so their energy reaches the reported total. Assert both selected domains are aggregated and identify the package/DRAM domains by sysfs path instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.41%. Comparing base (065d0e6) to head (ad8dc5d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1344      +/-   ##
==========================================
+ Coverage   91.39%   91.41%   +0.02%     
==========================================
  Files          49       49              
  Lines        5056     5057       +1     
==========================================
+ Hits         4621     4623       +2     
+ Misses        435      434       -1     

☔ 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 owner August 12, 2026 17:37
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.

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

1 participant