CPU Energy - RAPL - Scaphandre - component
What it does
This metric provider reads the Intel/AMD RAPL energy counters on Windows through the ScaphandreDrv kernel driver. It is the Windows counterpart to the Linux CPU Energy RAPL MSR provider.
Classname
CpuEnergyRaplScaphandreComponentProvider
Metric Name
cpu_energy_rapl_scaphandre_component
The metric name is the same as the key in the config.yml. It differs from the metric name of the
Linux provider (cpu_energy_rapl_msr_component), so runs made on Windows and on Linux show up as
separate metrics.
Unit
uJ
Configuration
The provider lives in the windows architecture section of the config.yml. It is commented out
by default, because it only works once the ScaphandreDrv driver is installed and running.
measurement:
metric_providers:
windows:
cpu_energy_rapl_scaphandre_component:
sampling_rate: 99
# Optionally disable individual RAPL domains
# domains:
# cpu_gpu: False
# dram: FalseConfig keys:
sampling_rate— the interval in milliseconds. Passed to the binary as-i.domains— optional map of RAPL domains to booleans. Valid keys arecpu_package,cpu_cores,cpu_gpu,dramandpsys. Any domain set to a falsy value is passed to the binary via-xand is never read. Setting a domain toTruehas no effect beyond not disabling it, since all supported domains are measured by default. An unknown domain name raises aMetricProviderConfigurationErrorat startup.
Please see Configuration → for further info.
Input Parameters
- args
-i: interval in milliseconds (the binary’s own default is 99)-d: measure a single named domain only and skip auto-detection-x: comma-separated list of domains to disable, e.g.-x cpu_gpu,dram-c: check mode — reads the RAPL power unit MSR and exits
The provider itself only ever passes -i and (when domains disables something) -x.
metric-provider-binary.exe -i 99 -x cpu_gpu,dramOutput
This metric provider prints to Stdout a continuous stream of data. The format of the data is as follows:
TIMESTAMP READING DETAIL_NAME
Where:
TIMESTAMP: Unix timestamp, in microsecondsREADING: The energy consumed by the domain since the previous sample in uJDETAIL_NAME: The RAPL domain — one ofcpu_package,cpu_cores,cpu_gpu,dram,psys
Any errors are printed to Stderr.
Unlike the other providers, the Python side does not redirect Stdout through a shell. It opens the log file itself and hands the file handle to the subprocess.
How it works
The provider is a C binary (metric-provider-binary.exe) that opens the driver device
\\.\ScaphandreDriver and issues IOCTL_READ_MSR calls to read the RAPL MSRs directly. It reads
CPU index 0 only.
The energy unit is derived from MSR_RAPL_POWER_UNIT (0x606), with a fallback to the AMD
register 0xC0010299. Each domain is then read from its own energy status register and the
delta to the previous sample is converted to microjoules. A negative delta is treated as a 32-bit
counter wrap and corrected by adding the counter range.
At startup the binary auto-detects which domains are actually active by taking one sample 100 ms
apart per domain: dram, cpu_gpu and psys are dropped if they report no energy progression.
Auto-detection is skipped entirely when a single domain was forced with -d, and domains excluded
via -x are removed before detection so they are never probed.
Timing uses QueryPerformanceCounter plus a wall-clock offset taken at startup, mirroring the
get_time_offset() / get_adjusted_time() approach of the Linux providers. The binary calls
timeBeginPeriod(1) to raise the Windows timer resolution to 1 ms, because the default 15.6 ms
timer granularity would make Sleep(99) overshoot far outside the tool’s sampling rate tolerance.
The main loop is deadline-based: it records the tick at the start of each iteration and sleeps only
the remaining time, so measurement overhead does not accumulate into drift.
The cpu_package domain doubles as a health canary. If its read fails, the driver is considered
faulty. After 5 consecutive failures the binary exits with code 2 so that the tool notices the
process died rather than silently recording nothing. If you disable cpu_package via domains,
it is still read internally as the canary but is not printed.
Installation
The binary is compiled with MSVC. From the x64 Native Tools Command Prompt for VS, run
build.bat in the provider folder, which invokes:
cl rapl_reader_cli.c /Fe:metric-provider-binary /O2 /W3 /link winmm.libwinmm.lib is required for timeBeginPeriod / timeEndPeriod.
The ScaphandreDrv kernel driver must be installed and running before the provider can be used.
Caveats
- Only CPU index 0 is read. On multi-socket machines the other packages are not measured.
- The
cpu_gpudomain reports 2 uJ whenever the real delta is 1 uJ or less. The integrated GPU often reports 0 uJ for single intervals when it is idle. Dropping these samples would leave gaps in the time series, and reporting 0 would trigger the resolution underflow check. A constant 2 uJ oncpu_gpushould therefore be read as “no measurable GPU energy”, not as an actual measurement. - Domains that are inactive at startup are dropped for the whole run. A domain that only becomes active later will not appear.
- RAPL is an on-chip model, not a physical power meter at the wall. See the RAPL documentation for the general caveats that apply to all RAPL-based providers.
Troubleshooting
Cannot open driver. Error: <n>— the ScaphandreDrv driver is not installed or not running. Check withsc.exe query ScaphandreDrvand start it withsc.exe start ScaphandreDrv.Cannot read RAPL power unit MSR.— the driver responds but the CPU does not expose the RAPL power unit register. This typically means RAPL is unavailable, for instance in a VM.Fatal: ScaphandreDrv driver lost after 5 consecutive failures.— the driver stopped responding during the measurement. Verify it is still running withsc.exe query ScaphandreDrv.Unknown RAPL domain '<name>'— adomainskey in theconfig.ymlis misspelled. Valid values arecpu_package,cpu_cores,cpu_gpu,dramandpsys.- If the system check fails, make sure that
metric-provider-binary.exeexists in the provider folder and that the driver is installed and running.