From d9a659ed967cf072a65eefa3d203f76748b5b5d0 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 28 Apr 2025 15:19:35 +0200 Subject: [PATCH] MINOR: threads/cli: display the lock history on "show threads" This will display the lock labels and modes for each non-empty step at the end of "show threads" when these are defined. This allows to emit up to the last 8 locking operation for each thread on 64 bit machines. --- include/haproxy/thread.h | 1 + src/debug.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/haproxy/thread.h b/include/haproxy/thread.h index e6c8e4b9d..4ed2dd677 100644 --- a/include/haproxy/thread.h +++ b/include/haproxy/thread.h @@ -49,6 +49,7 @@ int thread_map_to_groups(); int thread_resolve_group_mask(struct thread_set *ts, int defgrp, char **err); void thread_detect_count(void); int parse_thread_set(const char *arg, struct thread_set *ts, char **err); +const char *lock_label(enum lock_label label); extern int thread_cpus_enabled_at_boot; diff --git a/src/debug.c b/src/debug.c index 9daf2b0e1..1d6b30a7a 100644 --- a/src/debug.c +++ b/src/debug.c @@ -352,6 +352,23 @@ void ha_thread_dump_one(struct buffer *buf, int is_caller) chunk_appendf(buf, " curr_task="); ha_task_dump(buf, th_ctx->current, " "); +#if defined(USE_THREAD) && ((DEBUG_THREAD > 0) || defined(DEBUG_FULL)) + /* List the lock history */ + if (th_ctx->lock_history) { + int lkh, lkl; + + chunk_appendf(buf, " lock_hist:"); + for (lkl = 7; lkl >= 0; lkl--) { + lkh = (th_ctx->lock_history >> (lkl * 8)) & 0xff; + if (!lkh) + continue; + chunk_appendf(buf, " %c:%s", + "URSW"[lkh & 3], lock_label((lkh >> 2) - 1)); + } + chunk_appendf(buf, "\n"); + } +#endif + if (!(HA_ATOMIC_LOAD(&tg_ctx->threads_idle) & ti->ltid_bit)) { /* only dump the stack of active threads */ #ifdef USE_LUA