// 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
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;
if (r < 0) {
switch (-r) {
case EINPROGRESS:
+ DEBUG(self->ctx, "%s: heartbeat() launched a background task\n",
+ td_source_name(self));
break;
default:
// 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;