A class to interface Intel's Running Average Power Limit (RAPL) for monitoring CPU power consumption. This class provides methods to set up and read energy consumption data from Intel RAPL files, which are available on Linux systems. It enables the measurement of CPU energy usage o
| 391 | |
| 392 | |
| 393 | class IntelRAPL: |
| 394 | """ |
| 395 | A class to interface Intel's Running Average Power Limit (RAPL) for monitoring CPU power consumption. |
| 396 | |
| 397 | This class provides methods to set up and read energy consumption data from Intel RAPL files, |
| 398 | which are available on Linux systems. |
| 399 | It enables the measurement of CPU energy usage over time and provides methods to fetch |
| 400 | both dynamic and static CPU energy details. |
| 401 | |
| 402 | Attributes: |
| 403 | _lin_rapl_dir (str): The directory path where Intel RAPL files are located. |
| 404 | _system (str): The platform of the running system, typically used to ensure compatibility. |
| 405 | _rapl_files (List[RAPLFile]): A list of RAPLFile objects representing the files to read energy data from. |
| 406 | _cpu_details (Dict): A dictionary storing the latest CPU energy details. |
| 407 | _last_mesure (int): Placeholder for storing the last measurement time. |
| 408 | rapl_include_dram (bool): Whether to include DRAM power in measurements (default: False for complete hardware measurement). |
| 409 | rapl_prefer_psys (bool): Whether to prefer psys domain over package domains (default: False). |
| 410 | When True, uses psys (platform/system) domain which includes CPU + platform components. |
| 411 | When False (default), uses package domains which are more reliable and match CPU TDP specs. |
| 412 | |
| 413 | Args: |
| 414 | rapl_dir (str): Path to RAPL directory (default: "/sys/class/powercap/intel-rapl/subsystem") |
| 415 | rapl_include_dram (bool): Include DRAM domain for complete hardware measurement (default: False). |
| 416 | Set to False to measure only CPU package power. |
| 417 | rapl_prefer_psys (bool): Prefer psys (platform) domain over package domains (default: False). |
| 418 | Set to True to measure total platform power (CPU + chipset + PCIe). |
| 419 | Note: psys can report higher values than CPU TDP and may be less reliable on older systems. |
| 420 | |
| 421 | Methods: |
| 422 | start(): |
| 423 | Starts monitoring CPU energy consumption. |
| 424 | |
| 425 | get_cpu_details(duration: Time) -> Dict: |
| 426 | Fetches the CPU energy deltas over a specified duration by reading values from RAPL files. |
| 427 | |
| 428 | get_static_cpu_details() -> Dict: |
| 429 | Returns the CPU details without recalculating them. |
| 430 | |
| 431 | """ |
| 432 | |
| 433 | def __init__( |
| 434 | self, |
| 435 | rapl_dir="/sys/class/powercap/intel-rapl/subsystem", |
| 436 | rapl_include_dram=False, |
| 437 | rapl_prefer_psys=False, |
| 438 | ): |
| 439 | self._lin_rapl_dir = rapl_dir |
| 440 | self._system = sys.platform.lower() |
| 441 | self._rapl_files = [] |
| 442 | self.rapl_include_dram = rapl_include_dram |
| 443 | self.rapl_prefer_psys = rapl_prefer_psys |
| 444 | self._setup_rapl() |
| 445 | self._cpu_details: Dict = {} |
| 446 | |
| 447 | self._last_mesure = 0 |
| 448 | |
| 449 | def _is_platform_supported(self) -> bool: |
| 450 | return self._system.startswith("lin") |
no outgoing calls
searching dependent graphs…