From 5e0a48572058a95b4ac887b2747cdf20245e130c Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 6 Mar 2025 10:58:14 +0100 Subject: [PATCH] code improvements --- cpu_governor_auto_adjust/config.py | 2 +- cpu_governor_auto_adjust/cpu_governor_auto_adjust.py | 3 +-- cpu_governor_auto_adjust/schedule.py | 7 +++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cpu_governor_auto_adjust/config.py b/cpu_governor_auto_adjust/config.py index 84cceb6..3061aa4 100644 --- a/cpu_governor_auto_adjust/config.py +++ b/cpu_governor_auto_adjust/config.py @@ -29,7 +29,7 @@ class Config: @cached_property def basepath(self) -> Path: if self._basepath is None: - return Path(__file__).parent + return Path.cwd() return self._basepath @cached_property diff --git a/cpu_governor_auto_adjust/cpu_governor_auto_adjust.py b/cpu_governor_auto_adjust/cpu_governor_auto_adjust.py index 397865f..dc16e0e 100755 --- a/cpu_governor_auto_adjust/cpu_governor_auto_adjust.py +++ b/cpu_governor_auto_adjust/cpu_governor_auto_adjust.py @@ -15,8 +15,7 @@ def main() -> None: async def _main() -> None: - cwd = Path.cwd() - config = Config(cwd) + config = Config() log = getLogger('main', loglevel=config.loglevel.upper()) if config.testmode: log.warning("starting in testmode, cpu adjustments have been disabled") diff --git a/cpu_governor_auto_adjust/schedule.py b/cpu_governor_auto_adjust/schedule.py index 2f7971c..19b9d27 100644 --- a/cpu_governor_auto_adjust/schedule.py +++ b/cpu_governor_auto_adjust/schedule.py @@ -6,6 +6,7 @@ import asyncio import signal from asyncio import Task from functools import cached_property, partial +from time import monotonic class TriggerScheduler(AppClass): @@ -32,14 +33,16 @@ class TriggerScheduler(AppClass): """Run a callback_trigger with a specific name and check its status at a given interval.""" await _trigger.async_run() while True: - self.log.debug("Checking state of trigger %s, state: %s", _trigger.name, _trigger.trigger_state) + self.log.debug("callback trigger %s, state: %s", _trigger.name, _trigger.trigger_state) await asyncio.sleep(_trigger.config.interval_in_seconds) async def run_once_trigger(self, _trigger: Trigger) -> None: """Run a trigger with a specific name at a given interval.""" while True: + start = monotonic() _trigger.run() - self.log.debug("Checking state of trigger %s, state: %s", _trigger.name, _trigger.trigger_state) + end = monotonic() + self.log.debug("run once trigger %s, state: %s, duration: %.3f ms", _trigger.name, _trigger.trigger_state, (end - start) * 1000) await asyncio.sleep(_trigger.config.interval_in_seconds) def start_trigger(self, _trigger: Trigger) -> None: