Skip to content

Commit 502790e

Browse files
committed
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?).
1 parent e119095 commit 502790e

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ endif
261261
# DEBUG_MEM_STATS, DEBUG_DONT_SHARE_POOLS, DEBUG_FD, DEBUG_POOL_INTEGRITY,
262262
# DEBUG_NO_POOLS, DEBUG_FAIL_ALLOC, DEBUG_STRICT_ACTION=[0-3], DEBUG_HPACK,
263263
# DEBUG_AUTH, DEBUG_SPOE, DEBUG_UAF, DEBUG_THREAD, DEBUG_STRICT, DEBUG_DEV,
264-
# DEBUG_TASK, DEBUG_MEMORY_POOLS, DEBUG_POOL_TRACING, DEBUG_QPACK, DEBUG_LIST.
264+
# DEBUG_TASK, DEBUG_MEMORY_POOLS, DEBUG_POOL_TRACING, DEBUG_QPACK, DEBUG_LIST,
265+
# DEBUG_GLITCHES.
265266
DEBUG =
266267

267268
#### Trace options

include/haproxy/bug.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ enum debug_counter_type {
172172
DBG_BUG,
173173
DBG_BUG_ONCE,
174174
DBG_COUNT_IF,
175+
DBG_GLITCH,
175176
DBG_COUNTER_TYPES // must be last
176177
};
177178

@@ -230,12 +231,27 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt HA_SECTION_S
230231
1; /* let's return the true condition */ \
231232
}) : 0); } while (0)
232233

234+
/* DEBUG_GLITCHES enables counting the number of glitches per line of code. The
235+
* condition is empty (nothing to write there), except maybe __VA_ARGS at the
236+
* end.
237+
*/
238+
# if !defined(DEBUG_GLITCHES)
239+
# define _COUNT_GLITCH(file, line, ...) do { } while (0)
240+
# else
241+
# define _COUNT_GLITCH(file, line, ...) do { \
242+
__DBG_COUNT(, file, line, DBG_GLITCH, __VA_ARGS__); \
243+
} while (0)
244+
# endif
233245

234246
#else /* USE_OBSOLETE_LINKER not defined below */
235247
# define __DBG_COUNT(cond, file, line, type, ...) do { } while (0)
236248
# define _COUNT_IF(cond, file, line, ...) do { } while (0)
249+
# define _COUNT_GLITCH(file, line, ...) do { } while (0)
237250
#endif
238251

252+
/* reports a glitch for current file and line, optionally with an explanation */
253+
#define COUNT_GLITCH(...) _COUNT_GLITCH(__FILE__, __LINE__, __VA_ARGS__)
254+
239255
/* This is the generic low-level macro dealing with conditional warnings and
240256
* bugs. The caller decides whether to crash or not and what prefix and suffix
241257
* to pass. The macro returns the boolean value of the condition as an int for

src/debug.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2253,8 +2253,12 @@ static int debug_parse_cli_counters(char **args, char *payload, struct appctx *a
22532253
ctx->types |= 1 << DBG_COUNT_IF;
22542254
continue;
22552255
}
2256+
else if (strcmp(args[arg], "glt") == 0) {
2257+
ctx->types |= 1 << DBG_GLITCH;
2258+
continue;
2259+
}
22562260
else
2257-
return cli_err(appctx, "Expects an optional action ('reset','show'), optional types ('bug','chk','cnt') and optionally 'all' to even dump null counters.\n");
2261+
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");
22582262
}
22592263

22602264
if (action == 1) { // reset
@@ -2288,6 +2292,7 @@ static int debug_iohandler_counters(struct appctx *appctx)
22882292
[DBG_BUG] = "BUG",
22892293
[DBG_BUG_ONCE] = "CHK",
22902294
[DBG_COUNT_IF] = "CNT",
2295+
[DBG_GLITCH] = "GLT",
22912296
};
22922297
struct dev_cnt_ctx *ctx = appctx->svcctx;
22932298
struct debug_count *ptr;

0 commit comments

Comments
 (0)