From 43ab617625cac5a6ef560019b2244fb4bcbe0c5f Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 14 Mar 2025 16:36:31 +0100 Subject: [PATCH] improved CpuLoad trigger logic --- cpu_governor_auto_adjust/config.py | 2 +- cpu_governor_auto_adjust/triggers/cpu_load.py | 6 ++++++ pyproject.toml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cpu_governor_auto_adjust/config.py b/cpu_governor_auto_adjust/config.py index 90b5c6d..bad20bd 100644 --- a/cpu_governor_auto_adjust/config.py +++ b/cpu_governor_auto_adjust/config.py @@ -19,7 +19,7 @@ class TriggerTuple(NamedTuple): custom_config: OrderedDict[str, Any] def __repr__(self) -> str: - return f"{self.name}, interval: {self.interval_in_seconds}, governor: {self.governor}, custom_config: {self.custom_config}" + return f"{self.name}, loglevel: {self.loglevel}, interval: {self.interval_in_seconds}, governor: {self.governor}, custom_config: {self.custom_config}" class Config: diff --git a/cpu_governor_auto_adjust/triggers/cpu_load.py b/cpu_governor_auto_adjust/triggers/cpu_load.py index 1d0cb44..da07e12 100644 --- a/cpu_governor_auto_adjust/triggers/cpu_load.py +++ b/cpu_governor_auto_adjust/triggers/cpu_load.py @@ -50,6 +50,10 @@ class CpuLoadTrigger(Trigger): self.current_load, self.threshold, self.governor.name ) self.timestamp_last_governor_change = current_time + + elif current_active and new_active: + self.log.debug("trigger is already active, load: %s, threshold: %s", self.current_load, self.threshold) + self.timestamp_last_governor_change = current_time elif current_active and not new_active: if (current_time - timedelta(minutes=self.cooldown_period_in_minutes)) < self.timestamp_last_governor_change: @@ -60,5 +64,7 @@ class CpuLoadTrigger(Trigger): "deactivating trigger, load: %s, threshold: %s, governor: %s", self.current_load, self.threshold, self.governor.name ) + else: + self.log.debug("trigger is already inactive, load: %s, threshold: %s", self.current_load, self.threshold) self.active = new_active diff --git a/pyproject.toml b/pyproject.toml index 5c8f0d4..5278547 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "cpu_governor_auto_adjust" -version = "0.1.43" +version = "0.1.44" description = "This application has been developed to automatically change cpu governor based on certain triggers." authors = [ { name = "Martin Reurekas", email = "martin@semrks.nl" }