From 1598b8dd67e828f755e075e7065f0c0ee177dd2a Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 19 Dec 2025 16:50:47 +0000 Subject: [PATCH] Add include_stats parameter to status endpoint and reduce log verbosity - Add optional include_stats parameter to /api/status endpoint (default false) - Only fetch timing stats when include_stats=true, avoiding mutex acquisition - Remove verbose command logging from unix_socket.c (only log unrecognized commands) - This reduces log flooding and avoids unnecessary mutex contention on the critical PLC scan cycle when stats are not needed Co-Authored-By: Thiago Alves --- core/src/plc_app/unix_socket.c | 8 -------- webserver/app.py | 14 +++++++++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/core/src/plc_app/unix_socket.c b/core/src/plc_app/unix_socket.c index e9b00968..7c8663b5 100644 --- a/core/src/plc_app/unix_socket.c +++ b/core/src/plc_app/unix_socket.c @@ -45,12 +45,10 @@ void handle_unix_socket_commands(const char *command, char *response, size_t res { if (strcmp(command, "PING") == 0) { - log_debug("Received PING command"); strncpy(response, "PING:OK\n", response_size); } else if (strcmp(command, "STATUS") == 0) { - log_debug("Received STATUS command"); PLCState current_state = plc_get_state(); if (current_state == PLC_STATE_INIT) @@ -68,7 +66,6 @@ void handle_unix_socket_commands(const char *command, char *response, size_t res } else if (strcmp(command, "STOP") == 0) { - log_debug("Received STOP command"); if (plc_set_state(PLC_STATE_STOPPED)) strncpy(response, "STOP:OK\n", response_size); else @@ -76,7 +73,6 @@ void handle_unix_socket_commands(const char *command, char *response, size_t res } else if (strcmp(command, "START") == 0) { - log_debug("Received START command"); PLCState current_state = plc_get_state(); if (current_state != PLC_STATE_RUNNING) { @@ -97,12 +93,10 @@ void handle_unix_socket_commands(const char *command, char *response, size_t res } else if (strcmp(command, "STATS") == 0) { - log_debug("Received STATS command"); format_timing_stats_response(response, response_size); } else if (strncmp(command, "DEBUG:", 6) == 0) { - log_debug("Received DEBUG command"); uint8_t debug_data[4096] = {0}; size_t data_length = parse_hex_string(&command[6], debug_data); if (data_length > 0) @@ -181,8 +175,6 @@ void *unix_socket_thread(void *arg) ssize_t bytes_read = read_line(client_fd, command_buffer, COMMAND_BUFFER_SIZE); if (bytes_read > 0) { - log_debug("Received command: %s", command_buffer); - // Handle the command char response[MAX_RESPONSE_SIZE] = {0}; handle_unix_socket_commands(command_buffer, response, MAX_RESPONSE_SIZE); diff --git a/webserver/app.py b/webserver/app.py index 8d48707f..3948d387 100644 --- a/webserver/app.py +++ b/webserver/app.py @@ -110,11 +110,15 @@ def handle_status(data: dict) -> dict: result: dict = {"status": response} - # Fetch timing stats and include them in the response - stats_response = runtime_manager.stats_plc() - timing_stats = parse_timing_stats(stats_response) - if timing_stats is not None: - result["timing_stats"] = timing_stats + # Only fetch timing stats if explicitly requested via include_stats parameter. + # This avoids acquiring the stats mutex on every status poll, which could + # introduce latency to the critical PLC scan cycle. + include_stats = data.get("include_stats", "").lower() == "true" + if include_stats: + stats_response = runtime_manager.stats_plc() + timing_stats = parse_timing_stats(stats_response) + if timing_stats is not None: + result["timing_stats"] = timing_stats return result