Skip to content

Commit

Permalink
Sort threads array to capture stacktrace of main thread at the top
Browse files Browse the repository at this point in the history
Signed-off-by: Harkrishn Patro <[email protected]>
  • Loading branch information
hpatro committed Jan 13, 2025
1 parent d99457c commit f34c8d3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1708,10 +1708,15 @@ __attribute__((noinline)) static void collect_stacktrace_data(void) {
};
}

static int pidtCompare(const void *a, const void *b) {
return (*(pid_t *)a - *(pid_t *)b);
}

__attribute__((noinline)) static void writeStacktraces(int fd, int uplevel) {
/* get the list of all the process's threads that don't block or ignore the THREADS_SIGNAL */
pid_t tids[TIDS_MAX_SIZE];
size_t len_tids = get_ready_to_signal_threads_tids(THREADS_SIGNAL, tids);
qsort(tids, len_tids, sizeof(pid_t), pidtCompare);
if (!len_tids) {
serverLogRawFromHandler(LL_WARNING, "writeStacktraces(): Failed to get the process's threads.");
}
Expand Down

0 comments on commit f34c8d3

Please sign in to comment.