| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_STACKTRACE_ARRAY_H |
| 4 | #define NETDATA_STACKTRACE_ARRAY_H 1 |
| 5 | |
| 6 | #include "libnetdata/libnetdata.h" |
| 7 | #include "stacktrace.h" |
| 8 | |
| 9 | // Default maximum number of stacktraces to track per array |
| 10 | #ifndef STACKTRACE_ARRAY_MAX_TRACES |
| 11 | #define STACKTRACE_ARRAY_MAX_TRACES 100 |
| 12 | #endif |
| 13 | |
| 14 | // Structure to track multiple stacktraces |
| 15 | typedef struct stacktrace_array { |
| 16 | SPINLOCK spinlock; // spinlock to protect the stacktraces array |
| 17 | int num_stacktraces; // number of stored stacktraces (0 to STACKTRACE_ARRAY_MAX_TRACES) |
| 18 | STACKTRACE stacktraces[STACKTRACE_ARRAY_MAX_TRACES]; // array of stacktraces from different acquisition points |
| 19 | } STACKTRACE_ARRAY; |
| 20 | |
| 21 | // Initialize a stacktrace array |
| 22 | void stacktrace_array_init(STACKTRACE_ARRAY *array); |
| 23 | |
| 24 | // Add a stacktrace to an array (captures current stacktrace) |
| 25 | // Only adds if it's not already present |
| 26 | // Returns true if the stacktrace was added, false if it was already there or array is full |
| 27 | bool stacktrace_array_add(STACKTRACE_ARRAY *array, int skip_frames); |
| 28 | |
| 29 | // Report stacktraces to a buffer |
| 30 | // If total_count is not NULL, it will be updated with the total number of array elements |
| 31 | // If brief_output is true, only summary information is included |
| 32 | // Returns the number of unique stacktraces reported |
| 33 | size_t stacktrace_array_to_buffer(STACKTRACE_ARRAY *array, BUFFER *wb, size_t *total_count, const char *prefix, bool brief_output); |
| 34 | |
| 35 | #endif /* NETDATA_STACKTRACE_ARRAY_H */ |