fix: count DRAM in RAPL energy total - #1344
Open
davidberenstein1957 wants to merge 2 commits into
Open
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
davidberenstein1957
marked this pull request as ready for review
August 12, 2026 17:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Linux,
rapl_include_dram=Trueselected DRAM domains and read them every cycle, but their energy never reached the reported total — the result was identical torapl_include_dram=Falsewhile the log claimed DRAM was included.What changed
codecarbon/core/cpu.py—_create_rapl_filesnow assigns the Power-Gadget-compatible display nameProcessor Energy Delta_N(kWh)to DRAM domains as well as package/psys. Previously DRAM fell into theelsebranch and kept its raw sysfs namedram, which the aggregator incodecarbon/external/hardware.py(^Processor Energy Delta_\d) filters out.DRAM domains only reach
_create_rapl_fileswhenrapl_include_dramis 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_aggregatedintests/test_rapl_parameters.py, parametrized over both flag values. It builds a fake sysfs tree withpackage-0anddram, advances both counters, callsget_cpu_details(), and asserts the summedProcessor Energy Delta_*value. Withrapl_include_dram=Trueit expects package + DRAM; it fails on master (package-only) and passes with this change. TheFalsecase pins the default path.test_rapl_include_dram_true_explicitwas updated: it previously asserted a RAPL file was still nameddram, 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.platformpatched, and all tests intest_rapl_parameters.pyandtest_rapl_mmio_scanning.pypass.Note for the changelog
This is a measurement change: anyone already setting
rapl_include_dram=Truewill see reported CPU energy increase (correctly). DRAM is typically 10-20% of package power on memory-heavy workloads.Closes #1305
🤖 Generated with Claude Code