MCPcopy Create free account
hub / github.com/mlco2/codecarbon / _get_value

Method _get_value

codecarbon/core/rapl.py:47–65  ·  view source on GitHub ↗

Reads the value in the file at the path

(self)

Source from the content-addressed store, hash-verified

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()

Callers 3

__post_init__Method · 0.95
startMethod · 0.95
deltaMethod · 0.95

Calls 1

from_ujoulesMethod · 0.80

Tested by

no test coverage detected