]> git.ipfire.org Git - telemetry.git/commitdiff
source: Only log the heartbeat runtime if we called heartbeat()
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Jul 2026 11:58:26 +0000 (11:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Jul 2026 11:58:26 +0000 (11:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/source.c

index 3ad5a22ba1704adfe8073fdc48f307897bde3a6a..0342df21bcc35f2cd0863969de09c1af4543c8b6 100644 (file)
@@ -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;