From 3529acfeec1a63e5b7005edae58ec05a49b8659e Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sun, 27 Jun 2021 14:18:20 -0400 Subject: [PATCH] proc_stats: report a blocked event loop Use the PeriodicCallback in proc_stats to check if the event loop was blocked for a More than 5 seconds. If this is detected, log Moonraker's CPU usage over that time. Signed-off-by: Eric Callahan --- moonraker/components/proc_stats.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/moonraker/components/proc_stats.py b/moonraker/components/proc_stats.py index a6a49d7..bea7214 100644 --- a/moonraker/components/proc_stats.py +++ b/moonraker/components/proc_stats.py @@ -34,6 +34,7 @@ TEMPERATURE_PATH = "/sys/class/thermal/thermal_zone0/temp" STAT_UPDATE_TIME_MS = 1000 REPORT_QUEUE_SIZE = 30 THROTTLE_CHECK_INTERVAL = 10 +REPORT_BLOCKED_TIME = 5. THROTTLED_FLAGS = { 1: "Under-Voltage Detected", @@ -106,6 +107,10 @@ class ProcStats: proc_time = time.process_time() time_diff = update_time - self.last_update_time usage = round((proc_time - self.last_proc_time) / time_diff * 100, 2) + if time_diff > REPORT_BLOCKED_TIME: + logging.info( + f"EVENT LOOP BLOCKED: {round(time_diff, 2)} seconds, " + f"Moonraker Process Usage: {usage}%") mem, mem_units = self._get_memory_usage() cpu_temp = self._get_cpu_temperature() result = {