]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: add a new counter type for glitches
authorWilly Tarreau <w@1wt.eu>
Thu, 14 Nov 2024 07:49:38 +0000 (08:49 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 14 Nov 2024 07:49:38 +0000 (08:49 +0100)
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?).

Makefile
include/haproxy/bug.h
src/debug.c

index 1ccd45d39edefa38bdd74317ed7ed157df66bf12..5ace584836b1f3f92582517be8278bf5e6310d8c 100644 (file)
--- 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
index 8183681abda5345f3192f91f9ebb588cc8ccc24f..eb20773cb3a9e0504e3ed148d559db21b5d3644e 100644 (file)
@@ -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
index c4da8d7db6623abd5cb03e0331d6931fee1a9ff0..78940bfc4628fe3c680eb1c775465527df6a0775 100644 (file)
@@ -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;