Skip to content

Fix locale-safe RAPL idle-power parsing - #2

Open
Rex-Eisaxt wants to merge 1 commit into
ds-lab:mainfrom
Rex-Eisaxt:fix/rapl-decimal-separator
Open

Fix locale-safe RAPL idle-power parsing#2
Rex-Eisaxt wants to merge 1 commit into
ds-lab:mainfrom
Rex-Eisaxt:fix/rapl-decimal-separator

Conversation

@Rex-Eisaxt

Copy link
Copy Markdown

Summary

Fix locale-dependent parsing of RAPL idle-power measurements.

Under locales using a decimal comma, Bash printf could misinterpret decimal-point input and truncate the fractional component of the measured value. This produced inaccurate RAPL idle-power metadata.

Changes

  • Set LC_NUMERIC=C locally in freeze-idle-rapl.sh so its numeric calculations and formatting are deterministic.
  • Accept both decimal-point and decimal-comma RAPL values in the Python parser.
  • Require a valid numeric Package Total value.
  • Preserve the documented N/A → None behavior for unavailable CPU, integrated-GPU, and DRAM domains.
  • Reject mixed separators, repeated separators, partial matches, trailing malformed content, and other invalid labelled values.
  • Add 26 focused regression tests.

Validation

  • pytest tests/unit/test_rapl_util.py -v: 26 passed
  • bash -n metrion/discovery/system_scanner/bare_metal/linux/freeze-idle-rapl.sh: passed
  • Complete unit suite: 159 passed, 8 failed, 3 errors

The eight failures and three errors are unchanged from the existing baseline; this change introduced no additional failures.

Under a comma-decimal LC_NUMERIC, bash's printf %f in freeze-idle-rapl.sh
truncated bc's dot-decimal output and re-emitted it with a comma, which the
Python parser then crashed on. Pin LC_NUMERIC=C in the script so numeric
formatting is deterministic regardless of host locale, and make
parse_rapl_idle_log accept both decimal points and decimal commas while
rejecting mixed/repeated separators, negative values, and other malformed
input with a clear error instead of silently defaulting to None or 0.0.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

1 participant