(self, line: str = '')
| 21 | self._pgo: bool = pgo |
| 22 | |
| 23 | def log(self, line: str = '') -> None: |
| 24 | empty = not line |
| 25 | |
| 26 | # add the system load prefix: "load avg: 1.80 " |
| 27 | load_avg = self.get_load_avg() |
| 28 | if load_avg is not None: |
| 29 | line = f"load avg: {load_avg:.2f} {line}" |
| 30 | |
| 31 | # add the timestamp prefix: "0:01:05 " |
| 32 | log_time = time.perf_counter() - self.start_time |
| 33 | |
| 34 | mins, secs = divmod(int(log_time), 60) |
| 35 | hours, mins = divmod(mins, 60) |
| 36 | formatted_log_time = "%d:%02d:%02d" % (hours, mins, secs) |
| 37 | |
| 38 | line = f"{formatted_log_time} {line}" |
| 39 | if empty: |
| 40 | line = line[:-1] |
| 41 | |
| 42 | print(line, flush=True) |
| 43 | |
| 44 | def get_load_avg(self) -> float | None: |
| 45 | if hasattr(os, 'getloadavg'): |
no test coverage detected