From: Michael Tremer Date: Fri, 10 Jul 2026 11:58:26 +0000 (+0000) Subject: source: Only log the heartbeat runtime if we called heartbeat() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b334dcb5fcfeb72330e240ffe6f067ab1dcf1697;p=telemetry.git source: Only log the heartbeat runtime if we called heartbeat() Signed-off-by: Michael Tremer --- diff --git a/src/daemon/source.c b/src/daemon/source.c index 3ad5a22..0342df2 100644 --- a/src/daemon/source.c +++ b/src/daemon/source.c @@ -221,7 +221,7 @@ static int td_source_error_detection(td_source* self, int result, uint64_t runti // Complain if an iteration took too long if (runtime >= RUNTIME_THRESHOLD) { - ERROR(self->ctx, "Heartbeat for %s stalled the event loop for %.2lfms\n", + ERROR(self->ctx, "%s stalled the event loop for %.2lfms\n", td_source_name(self), USEC_TO_MSEC((double)runtime)); // Decrease the priority for this source so it won't stall any other sources @@ -229,13 +229,8 @@ static int td_source_error_detection(td_source* self, int result, uint64_t runti if (r < 0) return r; - // Otherwise just log the runtime and reset the priority + // Otherwise just reset the priority } else { - // Log the runtime - DEBUG(self->ctx, "Heartbeat for %s took %.2lfms\n", - td_source_name(self), USEC_TO_MSEC((double)runtime)); - - // Decrease the priority for this source so it won't stall any other sources r = sd_event_source_set_priority(self->events.heartbeat, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return r; @@ -318,6 +313,8 @@ static int td_source_heartbeat(sd_event_source* source, uint64_t usec, void* dat if (r < 0) { switch (-r) { case EINPROGRESS: + DEBUG(self->ctx, "%s: heartbeat() launched a background task\n", + td_source_name(self)); break; default: @@ -330,8 +327,15 @@ static int td_source_heartbeat(sd_event_source* source, uint64_t usec, void* dat // Fetch the end timestamp t_end = td_source_elapsed_time(); + // Determine the runtime + uint64_t runtime = t_end - t_start; + + // Log the runtime + DEBUG(self->ctx, "Heartbeat for %s took %.2lfms\n", + td_source_name(self), USEC_TO_MSEC((double)runtime)); + // Run error detection - r = td_source_error_detection(self, r, t_end - t_start); + r = td_source_error_detection(self, r, runtime); if (r < 0) return r;