Reads the value in the file at the path
(self)
| 45 | self.max_energy_reading = Energy.from_ujoules(0) |
| 46 | |
| 47 | def _get_value(self) -> Energy: |
| 48 | """ |
| 49 | Reads the value in the file at the path |
| 50 | """ |
| 51 | try: |
| 52 | with open(self.path, "r") as f: |
| 53 | micro_joules = float(f.read()) |
| 54 | return Energy.from_ujoules(micro_joules) |
| 55 | except Exception as e: |
| 56 | # Be tolerant to transient IO / permission errors while reading energy. |
| 57 | if isinstance(e, PermissionError): |
| 58 | logger.warning( |
| 59 | "Unable to read RAPL value from %s due to permission error: %s", |
| 60 | self.path, |
| 61 | e, |
| 62 | ) |
| 63 | else: |
| 64 | logger.debug("Unable to read RAPL value from %s: %s", self.path, e) |
| 65 | return Energy.from_ujoules(0) |
| 66 | |
| 67 | def start(self) -> None: |
| 68 | self.last_energy = self._get_value() |
no test coverage detected