added consumed time measure per trigger

This commit is contained in:
2025-04-01 23:07:39 +02:00
parent 5b53575768
commit 4fad9bdbd2
2 changed files with 18 additions and 3 deletions
+17 -2
View File
@@ -14,13 +14,22 @@ class Trigger(AppClass):
self._active: bool = False
self.log.setLevel(self.config.loglevel.upper())
self._timestamp_last_statistics = monotonic()
self._total_consumed_time = 0
self.runs = 0
def __hash__(self):
return super().__hash__(hash(self.name))
@property
def average_consumed_time(self) -> str:
if self.runs == 0:
return 0
return f"{(self._total_consumed_time / self.runs) * 1_000_000:.3f} µs"
def log_statistics(self):
class_vars = {}
start = monotonic()
for base in reversed(self.__class__.__mro__[:-1]):
if hasattr(base, '__dict__'):
for key, value in base.__dict__.items():
@@ -40,7 +49,9 @@ class Trigger(AppClass):
if not isinstance(value, (int, float, Governor)):
value = str(value)
class_vars[key] = value
self.log.info("info and statistics: %s", class_vars)
end = monotonic()
self.log.info("info and statistics [time taken: %.3fµs]: %s", (end - start) * 1_000_000, class_vars)
@property
def trigger_state(self) -> str:
@@ -78,11 +89,15 @@ class Trigger(AppClass):
async def run(self) -> None:
while True:
start = monotonic()
self.log.debug("run trigger code of %s", self.__class__.__name__)
if self._timestamp_last_statistics + int(self._config.statistics_interval_in_seconds) < monotonic():
self.log_statistics()
self._timestamp_last_statistics = monotonic()
self.trigger_code()
self.log.debug("trigger state: %s", self.trigger_state)
end = monotonic()
self._total_consumed_time += end - start
self.runs += 1
self.log.debug("trigger state: %s, finished in %.3f µs", self.trigger_state, (end - start) * 1_000_000)
await asyncio.sleep(self.config.interval_in_seconds)
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "cpu_governor_auto_adjust"
version = "0.5.7"
version = "0.5.12"
description = "This application has been developed to automatically change cpu governor based on certain triggers."
authors = [
{ name = "Martin Reurekas", email = "martin@semrks.nl" }