CONTRIB: debug: add the possibility to decode the value as certain types only

It's often confusing to have a whole dump on the screen while only
checking for a set of task or stream flags, and appending "|grep ^chn"
isn't very convenient to repeat the opeation. Instead let's add the
ability to filter the output as certain types only by prepending their
name(s) before the value.
This commit is contained in:
Willy Tarreau 2020-02-06 08:33:08 +01:00
parent 8a0eabd536
commit 354b6f5e28
1 changed files with 64 additions and 13 deletions

View File

@ -8,6 +8,21 @@
#include <types/stream_interface.h>
#include <types/task.h>
// 1 bit per flag, no hole permitted here
#define SHOW_AS_ANA 0x00000001
#define SHOW_AS_CHN 0x00000002
#define SHOW_AS_CONN 0x00000004
#define SHOW_AS_CS 0x00000008
#define SHOW_AS_SI 0x00000010
#define SHOW_AS_SIET 0x00000020
#define SHOW_AS_STRM 0x00000040
#define SHOW_AS_TASK 0x00000080
#define SHOW_AS_TXN 0x00000100
// command line names, must be in exact same order as the SHOW_AS_* flags above
// so that show_as_words[i] matches flag 1U<<i.
const char *show_as_words[] = { "ana", "chn", "conn", "cs", "si", "siet", "strm", "task", "txn", };
#define SHOW_FLAG(f,n) \
do { \
if (!((f) & (n))) break; \
@ -15,6 +30,19 @@
printf(#n"%s", (f) ? " | " : ""); \
} while (0)
unsigned int get_show_as(const char *word)
{
int w = 0;
while (1) {
if (w == sizeof(show_as_words) / sizeof(*show_as_words))
return 0;
if (strcmp(word, show_as_words[w]) == 0)
return 1U << w;
w++;
}
}
void show_chn_ana(unsigned int f)
{
printf("chn->ana = ");
@ -365,26 +393,49 @@ void show_strm_flags(unsigned int f)
putchar('\n');
}
void usage_exit(const char *name)
{
fprintf(stderr, "Usage: %s [ana|chn|conn|cs|si|sierr|strm|task|txn]* [0x]value\n", name);
exit(1);
}
int main(int argc, char **argv)
{
unsigned int flags;
unsigned int show_as = 0;
unsigned int f;
const char *name = argv[0];
char *err;
if (argc < 2) {
fprintf(stderr, "Usage: %s 0x<flags|state>\n", argv[0]);
exit(1);
while (argc > 0) {
argv++; argc--;
if (argc < 1)
usage_exit(name);
flags = strtoul(argv[0], &err, 0);
if (*argv[0] && !*err)
break;
f = get_show_as(argv[0]);
if (!f) {
fprintf(stderr, "Unknown argument: <%s>\n", argv[0]);
usage_exit(name);
}
show_as |= f;
}
flags = strtoul(argv[1], NULL, 0);
if (!show_as)
show_as = ~0U;
show_task_state(flags);
show_txn_flags(flags);
show_strm_flags(flags);
show_si_et(flags);
show_si_flags(flags);
show_cs_flags(flags);
show_conn_flags(flags);
show_chn_flags(flags);
show_chn_ana(flags);
if (show_as & SHOW_AS_ANA) show_chn_ana(flags);
if (show_as & SHOW_AS_CHN) show_chn_flags(flags);
if (show_as & SHOW_AS_CONN) show_conn_flags(flags);
if (show_as & SHOW_AS_CS) show_cs_flags(flags);
if (show_as & SHOW_AS_SI) show_si_flags(flags);
if (show_as & SHOW_AS_SIET) show_si_et(flags);
if (show_as & SHOW_AS_STRM) show_strm_flags(flags);
if (show_as & SHOW_AS_TASK) show_task_state(flags);
if (show_as & SHOW_AS_TXN) show_txn_flags(flags);
return 0;
}