@cryptotaxi247 / netdata-1 / commits / 19444ecf9

daemon status 27f (#20104)

while shutting down, keep track of the shutdown timings

Costa Tsaousis committed Apr 9, 2025 at 22:51 UTC 19444ecf9138246fe0c1717d0e80536e872c674c
6 files changed +13 -9
src/daemon/daemon-shutdown-watcher.c
+5 -2
@@ -41,7 +41,7 @@ static void watcher_wait_for_step(const watcher_step_id_t step_id, usec_t shutdo
41 {
42 if(!steps_timings) {
43 steps_timings = buffer_create(0, NULL);
44 - buffer_strcat(steps_timings, "# shutdown steps timings");
44 + buffer_strcat(steps_timings, STACK_TRACE_INFO_PREFIX " shutdown steps timings");
45 }
46
47 usec_t step_start_time = now_monotonic_usec();
@@ -61,7 +61,7 @@ static void watcher_wait_for_step(const watcher_step_id_t step_id, usec_t shutdo
61 watcher_steps[step_id].msg);
62 #endif
63
64 - daemon_status_file_shutdown_step(watcher_steps[step_id].msg);
64 + daemon_status_file_shutdown_step(watcher_steps[step_id].msg, buffer_tostring(steps_timings));
65
66 // Wait with a timeout
67 time_t timeout = 135; // systemd gives us 150, we timeout at 135
@@ -154,6 +154,9 @@ void *watcher_main(void *arg)
154 netdata_log_error("Shutdown process ended in %llu milliseconds",
155 shutdown_duration / USEC_PER_MS);
156
157 + daemon_status_file_shutdown_step(NULL, buffer_tostring(steps_timings));
158 + daemon_status_file_update_status(DAEMON_STATUS_EXITED);
159 +
160 return NULL;
161 }
162
src/daemon/daemon-shutdown.c
-3
@@ -328,9 +328,6 @@ static void netdata_cleanup_and_exit(EXIT_REASON reason, bool abnormal, bool exi
328 watcher_shutdown_end();
329 watcher_thread_stop();
330
331 - daemon_status_file_shutdown_step(NULL);
332 - daemon_status_file_update_status(DAEMON_STATUS_EXITED);
333 -
331 #if defined(FSANITIZE_ADDRESS)
332 fprintf(stderr, "\n");
333
src/daemon/status-file.c
+4 -2
@@ -76,7 +76,6 @@ static void copy_and_clean_thread_name_if_empty(DAEMON_STATUS_FILE *ds, const ch
76 *p = '\0';
77 }
78
79 -#define STACK_TRACE_INFO_PREFIX "info: "
79 static bool stack_trace_is_empty(DAEMON_STATUS_FILE *ds) {
80 return !ds->fatal.stack_trace[0] || strncmp(ds->fatal.stack_trace, STACK_TRACE_INFO_PREFIX, strlen(STACK_TRACE_INFO_PREFIX)) == 0;
81 }
@@ -1532,7 +1531,7 @@ void daemon_status_file_shutdown_timeout(BUFFER *trace) {
1531 // keep the spinlock locked, to prevent further steps updating the status
1532 }
1533
1535 -void daemon_status_file_shutdown_step(const char *step) {
1534 +void daemon_status_file_shutdown_step(const char *step, const char *step_timings) {
1535 if(session_status.fatal.filename[0] || !spinlock_trylock(&shutdown_timeout_spinlock))
1536 // we have a fatal logged
1537 return;
@@ -1542,6 +1541,9 @@ void daemon_status_file_shutdown_step(const char *step) {
1541 else
1542 session_status.fatal.function[0] = '\0';
1543
1544 + if(step_timings && *step_timings && stack_trace_is_empty(&session_status))
1545 + safecpy(session_status.fatal.stack_trace, step_timings);
1546 +
1547 daemon_status_file_update_status(DAEMON_STATUS_EXITING);
1548
1549 spinlock_unlock(&shutdown_timeout_spinlock);
src/daemon/status-file.h
+1 -1
@@ -146,7 +146,7 @@ bool daemon_status_file_has_last_crashed(DAEMON_STATUS_FILE *ds);
146 bool daemon_status_file_was_incomplete_shutdown(void);
147
148 void daemon_status_file_startup_step(const char *step);
149 -void daemon_status_file_shutdown_step(const char *step);
149 +void daemon_status_file_shutdown_step(const char *step, const char *step_timings);
150 void daemon_status_file_shutdown_timeout(BUFFER *trace);
151
152 void daemon_status_file_init(void);
src/libnetdata/log/nd_log-stacktrace.c
+1 -1
@@ -4,7 +4,7 @@
4
5 bool nd_log_forked = false;
6
7 -#define NO_STACK_TRACE_PREFIX "info: stack trace is not available, "
7 +#define NO_STACK_TRACE_PREFIX STACK_TRACE_INFO_PREFIX "stack trace is not available, "
8
9 // The signal handler function name to filter out in stack traces
10 static const char *signal_handler_function = "nd_signal_handler";
src/libnetdata/log/nd_log.h
+2
@@ -33,7 +33,9 @@ const char *nd_log_id2priority(ND_LOG_FIELD_PRIORITY priority);
33 const char *nd_log_method_for_external_plugins(const char *s);
34 ND_UUID nd_log_get_invocation_id(void);
35
36 +#define STACK_TRACE_INFO_PREFIX "info: "
37 void capture_stack_trace(BUFFER *wb);
38 +
39 void capture_stack_trace_init(void);
40 void capture_stack_trace_flush(void);
41 bool capture_stack_trace_available(void);