Skip to content

Commit 4420939

Browse files
committed
MINOR: debug/cli: replace "debug dev counters" with "debug counters"
"debug dev" commands are not meant to be used by end-users, and are purposely not documented. Yet due to their usefulness in troubleshooting sessions, users are increasingly invited by developers to use some of them. "debug dev counters" is one of them. Better move it to "debug counters" and document it so that users can check them even if the output can look cryptic at times. This, combined with DEBUG_GLITCHES, can be convenient to observe suspcious activity. The doc however precises that the format may change between versions and that new entries/types might appear within a stable branch.
1 parent 5a3735a commit 4420939

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

doc/management.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,38 @@ commit ssl crl-file <crlfile>
19901990
See also "new ssl crl-file", "set ssl crl-file", "abort ssl crl-file" and
19911991
"add ssl crt-list".
19921992

1993+
debug counters [reset|show|all|bug|chk|cnt|glt|?]*
1994+
List internal counters placed in the code, which may vary depending on some
1995+
build options. Some of them depend on DEBUG_STRICT, others on DEBUG_GLITCHES.
1996+
The command takes a combination of multiple arguments, some defining actions
1997+
and others defining filters:
1998+
- bug enables listing the counters for BUG_ON() statements
1999+
- cnt enables listing the counters for COUNT_IF() statements
2000+
- chk enables listing the counters for CHECK_IF() statements
2001+
- glt enables listing the counters for COUNT_GLITCH() statements
2002+
- all enables showing counters that never triggered (value 0)
2003+
- reset action: resets all specified counters
2004+
- show action: shows all specified counters
2005+
2006+
By default, the action is "show" to show counters, and the listed counters
2007+
are all types with a non-zero value. The "show" command is implicit when no
2008+
other action is specified, and is only present to ease the production of
2009+
commands from scripts.
2010+
2011+
The output starts with an integer counter, followed by the type of the
2012+
counter in upper case, then its location in the code (file:line), the
2013+
function name, and optionally ": " followed by a description. Please note
2014+
that the output format might change between major versions, and new types
2015+
and entries might be backported to stable versions for the purpose of
2016+
improved debugging capabilities. Any monitoring performed on them should
2017+
only be done in a very lenient and permissive way, and preferably not.
2018+
2019+
Normally, end users will not use this command, but they may be invited to do
2020+
so by a developer trying to figure the cause of an issue, looking for CNT or
2021+
GLT entries. By the way, non-zero "CHK" entries are not expected to happen
2022+
and should be reported to developers as they might indicate some incorrect
2023+
assumptions in the code.
2024+
19932025
debug dev <command> [args]*
19942026
Call a developer-specific command. Only supported on a CLI connection running
19952027
in expert mode (see "expert-mode on"). Such commands are extremely dangerous

src/debug.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,25 +2210,25 @@ static void debug_release_memstats(struct appctx *appctx)
22102210

22112211
#if !defined(USE_OBSOLETE_LINKER)
22122212

2213-
/* CLI state for "debug dev counters" */
2214-
struct dev_cnt_ctx {
2213+
/* CLI state for "debug counters" */
2214+
struct deb_cnt_ctx {
22152215
struct debug_count *start, *stop; /* begin/end of dump */
22162216
int types; /* OR mask of 1<<type */
22172217
int show_all; /* show all entries if non-null */
22182218
};
22192219

2220-
/* CLI parser for the "debug dev counters" command. Sets a dev_cnt_ctx shown above. */
2220+
/* CLI parser for the "debug counters" command. Sets a deb_cnt_ctx shown above. */
22212221
static int debug_parse_cli_counters(char **args, char *payload, struct appctx *appctx, void *private)
22222222
{
2223-
struct dev_cnt_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));
2223+
struct deb_cnt_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));
22242224
int action;
22252225
int arg;
22262226

22272227
if (!cli_has_level(appctx, ACCESS_LVL_OPER))
22282228
return 1;
22292229

22302230
action = 0; // 0=show, 1=reset
2231-
for (arg = 3; *args[arg]; arg++) {
2231+
for (arg = 2; *args[arg]; arg++) {
22322232
if (strcmp(args[arg], "reset") == 0) {
22332233
action = 1;
22342234
continue;
@@ -2281,7 +2281,7 @@ static int debug_parse_cli_counters(char **args, char *payload, struct appctx *a
22812281
return 0;
22822282
}
22832283

2284-
/* CLI I/O handler for the "debug dev counters" command using a dev_cnt_ctx
2284+
/* CLI I/O handler for the "debug counters" command using a deb_cnt_ctx
22852285
* found in appctx->svcctx. Dumps all mem_stats structs referenced by pointers
22862286
* located between ->start and ->stop. Dumps all entries if ->show_all != 0,
22872287
* otherwise only non-zero calls.
@@ -2294,7 +2294,7 @@ static int debug_iohandler_counters(struct appctx *appctx)
22942294
[DBG_COUNT_IF] = "CNT",
22952295
[DBG_GLITCH] = "GLT",
22962296
};
2297-
struct dev_cnt_ctx *ctx = appctx->svcctx;
2297+
struct deb_cnt_ctx *ctx = appctx->svcctx;
22982298
struct debug_count *ptr;
22992299
int ret = 1;
23002300

@@ -2746,12 +2746,12 @@ REGISTER_PER_THREAD_INIT(feed_post_mortem_late);
27462746

27472747
/* register cli keywords */
27482748
static struct cli_kw_list cli_kws = {{ },{
2749+
#if !defined(USE_OBSOLETE_LINKER)
2750+
{{ "debug", "counters", NULL }, "debug counters [?|all|bug|cnt|chk|glt]* : dump/reset rare event counters", debug_parse_cli_counters, debug_iohandler_counters, NULL, NULL, 0 },
2751+
#endif
27492752
{{ "debug", "dev", "bug", NULL }, "debug dev bug : call BUG_ON() and crash", debug_parse_cli_bug, NULL, NULL, NULL, ACCESS_EXPERT },
27502753
{{ "debug", "dev", "check", NULL }, "debug dev check : call CHECK_IF() and possibly crash", debug_parse_cli_check, NULL, NULL, NULL, ACCESS_EXPERT },
27512754
{{ "debug", "dev", "close", NULL }, "debug dev close <fd> [hard] : close this file descriptor", debug_parse_cli_close, NULL, NULL, NULL, ACCESS_EXPERT },
2752-
#if !defined(USE_OBSOLETE_LINKER)
2753-
{{ "debug", "dev", "counters", NULL }, "debug dev counters [all|bug|cnt|chk|?]* : dump/reset rare event counters", debug_parse_cli_counters, debug_iohandler_counters, NULL, NULL, 0 },
2754-
#endif
27552755
{{ "debug", "dev", "deadlock", NULL }, "debug dev deadlock [nbtask] : deadlock between this number of tasks", debug_parse_cli_deadlock, NULL, NULL, NULL, ACCESS_EXPERT },
27562756
{{ "debug", "dev", "delay", NULL }, "debug dev delay [ms] : sleep this long", debug_parse_cli_delay, NULL, NULL, NULL, ACCESS_EXPERT },
27572757
#if defined(DEBUG_DEV)

0 commit comments

Comments
 (0)