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?).
This commit is contained in:
Willy Tarreau 2024-11-14 08:49:38 +01:00
parent e119095290
commit 502790ed7e
3 changed files with 24 additions and 2 deletions

View File

@ -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

View 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

View 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;