mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 13:51:26 +02:00
MINOR: debug: write panic dump to stderr one thread at a time
Currently large setups cannot dump all their threads because they're first dumped to the trash buffer, then copied to stderr. Here we can now change this, instead we dump one thread at a time into the trash and immediately send it to stderr. We also keep a copy into a local trash chunk that's assigned to thread_dump_buffer so that a core file still contains a copy of a large number of threads, which is generally sufficient for the vast majority of situations. It was verified that dumping 256 threads now produces ~55kB of output and all of them are properly dumped.
This commit is contained in:
parent
9a6ecbd590
commit
880d1684a7
24
src/debug.c
24
src/debug.c
@ -70,7 +70,6 @@
|
||||
* non-null. It's only used by debuggers for core dump analysis.
|
||||
*/
|
||||
struct buffer *thread_dump_buffer = NULL;
|
||||
unsigned int panic_started = 0;
|
||||
unsigned int debug_commands_issued = 0;
|
||||
|
||||
/* dumps a backtrace of the current thread that is appended to buffer <buf>.
|
||||
@ -397,10 +396,19 @@ static int debug_parse_cli_show_libs(char **args, char *payload, struct appctx *
|
||||
}
|
||||
#endif
|
||||
|
||||
/* dumps a state of all threads into the trash and on fd #2, then aborts. */
|
||||
/* Dumps a state of all threads into the trash and on fd #2, then aborts.
|
||||
* A copy will be put into a trash chunk that's assigned to thread_dump_buffer
|
||||
* so that the debugger can easily find it. This buffer might be truncated if
|
||||
* too many threads are being dumped, but at least we'll dump them all on stderr.
|
||||
* If thread_dump_buffer is set, it means that a panic has already begun.
|
||||
*/
|
||||
void ha_panic()
|
||||
{
|
||||
if (HA_ATOMIC_FETCH_ADD(&panic_started, 1) != 0) {
|
||||
struct buffer *old;
|
||||
unsigned int thr;
|
||||
|
||||
old = NULL;
|
||||
if (!HA_ATOMIC_CAS(&thread_dump_buffer, &old, get_trash_chunk())) {
|
||||
/* a panic dump is already in progress, let's not disturb it,
|
||||
* we'll be called via signal DEBUGSIG. By returning we may be
|
||||
* able to leave a current signal handler (e.g. WDT) so that
|
||||
@ -408,11 +416,17 @@ void ha_panic()
|
||||
*/
|
||||
return;
|
||||
}
|
||||
thread_dump_buffer = &trash;
|
||||
|
||||
chunk_reset(&trash);
|
||||
chunk_appendf(&trash, "Thread %u is about to kill the process.\n", tid + 1);
|
||||
ha_thread_dump_all_to_trash();
|
||||
|
||||
for (thr = 0; thr < global.nbthread; thr++) {
|
||||
ha_thread_dump(&trash, thr);
|
||||
DISGUISE(write(2, trash.area, trash.data));
|
||||
b_force_xfer(thread_dump_buffer, &trash, b_room(thread_dump_buffer));
|
||||
chunk_reset(&trash);
|
||||
}
|
||||
|
||||
for (;;)
|
||||
abort();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user