Skip to content

add power units for pmda-denki metrics#2641

Merged
kmcdonell merged 3 commits into
performancecopilot:mainfrom
christianhorn:add-denki-units
Jul 5, 2026
Merged

add power units for pmda-denki metrics#2641
kmcdonell merged 3 commits into
performancecopilot:mainfrom
christianhorn:add-denki-units

Conversation

@christianhorn

Copy link
Copy Markdown
Collaborator

Adding the new power units.

For metric denki.bat.energy_now, unit Watthour (Wh) would be appropriate, capacity. Should we add that?
Once could argue "it's just power delivered over a time".. but I think here in this instance we can not use that property, and would vote that we add a unit Wh.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Clarified unit metadata for battery readings so bat.power_now and related energy/power metrics are consistently reported in watts.
    • Improved RAPL reading labels by adding an explicit JSON unit field ("watt") for both sysfs and msr domains, enhancing dashboard display and query accuracy.

Walkthrough

denki.c now declares explicit watt power metadata for battery metrics and adds watt labels to RAPL instance domains.

Changes

Power unit metadata for denki metrics

Layer / File(s) Summary
Update metrictab power unit declarations
src/pmdas/denki/denki.c
bat.energy_now and bat.power_now now use PMDA_EXTRAUNITS with explicit power-unit information instead of PMDA_PMUNITS.
Add watt labels for RAPL domains
src/pmdas/denki/denki.c
denki_label() now appends {"units":"watt"} for RAPL_SYSFS_INDOM and RAPL_MSR_INDOM while keeping the existing indom_name label.

Poem

A bunny hops on watts so bright,
With labels crisp and units right.
Battery purrs, RAPL gleams,
Tiny metadata fuels big dreams. 🐇

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding power units to pmda-denki metrics.
Description check ✅ Passed The description is directly related to the change, discussing power units for pmda-denki metrics.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/pmdas/denki/denki.c`:
- Around line 897-900: The bat.energy_now metric definition in denki.c still
uses dimensionless PMDA_PMUNITS(0,0,0,0,0,0) instead of the required Wh
annotation. Update the PMDA_PMUNITS value for the bat.energy_now entry in the
metric table to use the same watt-hour capacity unit convention as the related
battery metrics, keeping the change localized to that metric definition.
- Around line 892-896: The RAPL metric definitions in denki.c are using
PM_UNIT_POWER/PM_POWER_W for denki.rapl.sysfs and denki.rapl.msr, but these
counters are cumulative energy readings rather than power. Update the unit
metadata in the RAPL entries within the PMDA_EXTRAUNITS/PMDA_PMID definitions to
use a unitless or more appropriate descriptor, or add an explicit comment in the
RAPL section explaining any intentional approximation. Keep the change localized
to the RAPL metric table entries so the symbols denki.rapl.sysfs and
denki.rapl.msr remain easy to identify.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: fc0a8a5d-c27b-45ba-8efa-b16cc8eece6d

📥 Commits

Reviewing files that changed from the base of the PR and between 18003b6 and 67d4b7a.

📒 Files selected for processing (1)
  • src/pmdas/denki/denki.c

Comment thread src/pmdas/denki/denki.c Outdated
Comment thread src/pmdas/denki/denki.c Outdated

@coderabbitai coderabbitai Bot 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.

♻️ Duplicate comments (1)
src/pmdas/denki/denki.c (1)

1274-1281: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

RAPL labels incorrectly describe energy counters as "watt".

RAPL_SYSFS_INDOM and RAPL_MSR_INDOM back rapl.sysfs/rapl.msr, which are PM_SEM_COUNTER cumulative energy readings (see metrictab lines 892-896, still dimensionless). Adding {"units":"watt"} here mislabels them as instantaneous power, which is misleading to consumers of these labels — the prior discussion on this PR converged on using "joules"/"millijoules" for these counters instead, mirroring the BAT_ENERGYNOW_INDOM"watt hours" pattern used just below.

🐛 Proposed fix
 				case RAPL_SYSFS_INDOM:
 					pmdaAddLabels(lpp, "{\"indom_name\":\"rapl sysfs\"}");
-					pmdaAddLabels(lpp, "{\"units\":\"watt\"}");
+					pmdaAddLabels(lpp, "{\"units\":\"joules\"}");
 					break;
 				case RAPL_MSR_INDOM:
 					pmdaAddLabels(lpp, "{\"indom_name\":\"rapl msr\"}");
-					pmdaAddLabels(lpp, "{\"units\":\"watt\"}");
+					pmdaAddLabels(lpp, "{\"units\":\"joules\"}");
 					break;

Based on learnings, "RAPL sysfs and MSR ... are cumulative energy counters, not power readings ... follow the existing convention ... state the real unit (e.g., joules/millijoules) via pmdaAddLabels/metadata rather than pmUnits."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pmdas/denki/denki.c` around lines 1274 - 1281, The RAPL label metadata in
the RAPL_SYSFS_INDOM and RAPL_MSR_INDOM cases is misreporting cumulative energy
counters as “watt”; update the pmdaAddLabels entries in this switch so the
labels describe the actual energy unit instead (for example joules or
millijoules), matching the existing convention used for BAT_ENERGYNOW_INDOM and
the PM_SEM_COUNTER semantics. Keep the change localized to the denki label setup
around these RAPL case labels and ensure the metadata reflects energy rather
than instantaneous power.

Source: Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@src/pmdas/denki/denki.c`:
- Around line 1274-1281: The RAPL label metadata in the RAPL_SYSFS_INDOM and
RAPL_MSR_INDOM cases is misreporting cumulative energy counters as “watt”;
update the pmdaAddLabels entries in this switch so the labels describe the
actual energy unit instead (for example joules or millijoules), matching the
existing convention used for BAT_ENERGYNOW_INDOM and the PM_SEM_COUNTER
semantics. Keep the change localized to the denki label setup around these RAPL
case labels and ensure the metadata reflects energy rather than instantaneous
power.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 6b26fdd9-391d-4837-a5f5-948349abbb0a

📥 Commits

Reviewing files that changed from the base of the PR and between 67d4b7a and c729e4f.

📒 Files selected for processing (1)
  • src/pmdas/denki/denki.c

@kmcdonell

Copy link
Copy Markdown
Member

@christianhorn sorry, I disagree, we don't need Wh, the canonical way of specifying this now is

PMDA_EXTRAUNITS(0,1,0,0,PM_TIME_HOUR,0,PM_UNIT_POWER, PM_POWER_W)

which gets reported like this

kenj@bozo:~/src/pcp/qa/src$ units-parse tuple 0 1 0 0 5 0 4 2
(0,1,0,0,5,0,4,2) => "power (W) hour" => conv rc 0 => (0,1,0,0,5,0,4,2)*1 => "power (W) hour" 

so not quite Wh, but close enough I think.

Adding another slice of "extra" units (like for energy) is a big deal QA and code wise, and I'd like to keep a tight control over the number we're willing to support.

@christianhorn

Copy link
Copy Markdown
Collaborator Author

Nice, works for me.

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/pmdas/denki/denki.c (1)

1276-1280: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Use an energy unit for the RAPL indom labels. denki.rapl.sysfs and denki.rapl.msr are cumulative energy counters (PM_SEM_COUNTER with dimensionless pmUnits), so {"units":"watt"} is misleading here. Label them with the actual energy unit (joules/millijoules) instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pmdas/denki/denki.c` around lines 1276 - 1280, The RAPL indom labels in
denki.c are using the wrong unit string for cumulative energy counters. Update
the pmdaAddLabels calls in the RAPL branch handling RAPL_MSR_INDOM (and the
corresponding sysfs case nearby) to use an energy unit label such as joules or
millijoules instead of watts, keeping the existing indom_name labels intact.

Source: Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/pmdas/denki/denki.c`:
- Around line 1276-1280: The RAPL indom labels in denki.c are using the wrong
unit string for cumulative energy counters. Update the pmdaAddLabels calls in
the RAPL branch handling RAPL_MSR_INDOM (and the corresponding sysfs case
nearby) to use an energy unit label such as joules or millijoules instead of
watts, keeping the existing indom_name labels intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 2121c4c0-24ec-4eda-933f-ce4fdfa02117

📥 Commits

Reviewing files that changed from the base of the PR and between c729e4f and 6a24a53.

📒 Files selected for processing (1)
  • src/pmdas/denki/denki.c

@kmcdonell kmcdonell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks @christianhorn

@kmcdonell kmcdonell merged commit 681b35f into performancecopilot:main Jul 5, 2026
17 checks passed
@christianhorn christianhorn deleted the add-denki-units branch July 5, 2026 20:56
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