From: Willy Tarreau Date: Thu, 14 Nov 2024 07:49:38 +0000 (+0100) Subject: MINOR: debug: add a new counter type for glitches X-Git-Tag: v3.1-dev13~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=502790ed7e76ccf73b481aa110c3e6607b2e75d2;p=thirdparty%2Fhaproxy.git MINOR: debug: add a new counter type for glitches COUNT_GLITCH() will implement an unconditional counter on its declaration line when DEBUG_GLITCHES is set, and do nothing otherwise. The output will be reported as "GLT" and can be filtered as "glt" on the CLI. The purpose is to help figure what's happening if some glitches counters start going through the roof. The macro supports an optional string argument to describe the cause of the glitch (e.g. "truncated header"), which is then reported in the dump. For now this is conditioned by DEBUG_GLITCHES but if it turns out to be light enough, maybe we'll keep it enabled full time. In this case it might have to be moved away from debug dev, or at least documented (or done as debug counters maybe so that dev can remain undocumented and updatable within a branch?). --- diff --git a/Makefile b/Makefile index 1ccd45d39e..5ace584836 100644 --- a/Makefile +++ b/Makefile @@ -261,7 +261,8 @@ endif # DEBUG_MEM_STATS, DEBUG_DONT_SHARE_POOLS, DEBUG_FD, DEBUG_POOL_INTEGRITY, # DEBUG_NO_POOLS, DEBUG_FAIL_ALLOC, DEBUG_STRICT_ACTION=[0-3], DEBUG_HPACK, # DEBUG_AUTH, DEBUG_SPOE, DEBUG_UAF, DEBUG_THREAD, DEBUG_STRICT, DEBUG_DEV, -# DEBUG_TASK, DEBUG_MEMORY_POOLS, DEBUG_POOL_TRACING, DEBUG_QPACK, DEBUG_LIST. +# DEBUG_TASK, DEBUG_MEMORY_POOLS, DEBUG_POOL_TRACING, DEBUG_QPACK, DEBUG_LIST, +# DEBUG_GLITCHES. DEBUG = #### Trace options diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index 8183681abd..eb20773cb3 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -172,6 +172,7 @@ enum debug_counter_type { DBG_BUG, DBG_BUG_ONCE, DBG_COUNT_IF, + DBG_GLITCH, DBG_COUNTER_TYPES // must be last }; @@ -230,12 +231,27 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S 1; /* let's return the true condition */ \ }) : 0); } while (0) +/* DEBUG_GLITCHES enables counting the number of glitches per line of code. The + * condition is empty (nothing to write there), except maybe __VA_ARGS at the + * end. + */ +# if !defined(DEBUG_GLITCHES) +# define _COUNT_GLITCH(file, line, ...) do { } while (0) +# else +# define _COUNT_GLITCH(file, line, ...) do { \ + __DBG_COUNT(, file, line, DBG_GLITCH, __VA_ARGS__); \ + } while (0) +# endif #else /* USE_OBSOLETE_LINKER not defined below */ # define __DBG_COUNT(cond, file, line, type, ...) do { } while (0) # define _COUNT_IF(cond, file, line, ...) do { } while (0) +# define _COUNT_GLITCH(file, line, ...) do { } while (0) #endif +/* reports a glitch for current file and line, optionally with an explanation */ +#define COUNT_GLITCH(...) _COUNT_GLITCH(__FILE__, __LINE__, __VA_ARGS__) + /* This is the generic low-level macro dealing with conditional warnings and * bugs. The caller decides whether to crash or not and what prefix and suffix * to pass. The macro returns the boolean value of the condition as an int for diff --git a/src/debug.c b/src/debug.c index c4da8d7db6..78940bfc46 100644 --- a/src/debug.c +++ b/src/debug.c @@ -2253,8 +2253,12 @@ static int debug_parse_cli_counters(char **args, char *payload, struct appctx *a ctx->types |= 1 << DBG_COUNT_IF; continue; } + else if (strcmp(args[arg], "glt") == 0) { + ctx->types |= 1 << DBG_GLITCH; + continue; + } else - return cli_err(appctx, "Expects an optional action ('reset','show'), optional types ('bug','chk','cnt') and optionally 'all' to even dump null counters.\n"); + return cli_err(appctx, "Expects an optional action ('reset','show'), optional types ('bug','chk','cnt','glt') and optionally 'all' to even dump null counters.\n"); } if (action == 1) { // reset @@ -2288,6 +2292,7 @@ static int debug_iohandler_counters(struct appctx *appctx) [DBG_BUG] = "BUG", [DBG_BUG_ONCE] = "CHK", [DBG_COUNT_IF] = "CNT", + [DBG_GLITCH] = "GLT", }; struct dev_cnt_ctx *ctx = appctx->svcctx; struct debug_count *ptr;