Commit 71c8c39f authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

veristat: improve version reporting

For packaging version of the tool is important, so add a simple way to
specify veristat version for upstream mirror at Github.
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20230331222405.3468634-3-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 3ed85ae8
...@@ -140,6 +140,7 @@ static struct env { ...@@ -140,6 +140,7 @@ static struct env {
bool quiet; bool quiet;
int log_level; int log_level;
enum resfmt out_fmt; enum resfmt out_fmt;
bool show_version;
bool comparison_mode; bool comparison_mode;
bool replay_mode; bool replay_mode;
...@@ -176,16 +177,22 @@ static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va ...@@ -176,16 +177,22 @@ static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va
return vfprintf(stderr, format, args); return vfprintf(stderr, format, args);
} }
const char *argp_program_version = "veristat"; #ifndef VERISTAT_VERSION
#define VERISTAT_VERSION "<kernel>"
#endif
const char *argp_program_version = "veristat v" VERISTAT_VERSION;
const char *argp_program_bug_address = "<bpf@vger.kernel.org>"; const char *argp_program_bug_address = "<bpf@vger.kernel.org>";
const char argp_program_doc[] = const char argp_program_doc[] =
"veristat BPF verifier stats collection and comparison tool.\n" "veristat BPF verifier stats collection and comparison tool.\n"
"\n" "\n"
"USAGE: veristat <obj-file> [<obj-file>...]\n" "USAGE: veristat <obj-file> [<obj-file>...]\n"
" OR: veristat -C <baseline.csv> <comparison.csv>\n"; " OR: veristat -C <baseline.csv> <comparison.csv>\n"
" OR: veristat -R <results.csv>\n";
static const struct argp_option opts[] = { static const struct argp_option opts[] = {
{ NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help" }, { NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help" },
{ "version", 'V', NULL, 0, "Print version" },
{ "verbose", 'v', NULL, 0, "Verbose mode" }, { "verbose", 'v', NULL, 0, "Verbose mode" },
{ "log-level", 'l', "LEVEL", 0, "Verifier log level (default 0 for normal mode, 1 for verbose mode)" }, { "log-level", 'l', "LEVEL", 0, "Verifier log level (default 0 for normal mode, 1 for verbose mode)" },
{ "debug", 'd', NULL, 0, "Debug mode (turns on libbpf debug logging)" }, { "debug", 'd', NULL, 0, "Debug mode (turns on libbpf debug logging)" },
...@@ -212,6 +219,9 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) ...@@ -212,6 +219,9 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
case 'h': case 'h':
argp_state_help(state, stderr, ARGP_HELP_STD_HELP); argp_state_help(state, stderr, ARGP_HELP_STD_HELP);
break; break;
case 'V':
env.show_version = true;
break;
case 'v': case 'v':
env.verbose = true; env.verbose = true;
break; break;
...@@ -1991,6 +2001,11 @@ int main(int argc, char **argv) ...@@ -1991,6 +2001,11 @@ int main(int argc, char **argv)
if (argp_parse(&argp, argc, argv, 0, NULL, NULL)) if (argp_parse(&argp, argc, argv, 0, NULL, NULL))
return 1; return 1;
if (env.show_version) {
printf("%s\n", argp_program_version);
return 0;
}
if (env.verbose && env.quiet) { if (env.verbose && env.quiet) {
fprintf(stderr, "Verbose and quiet modes are incompatible, please specify just one or neither!\n\n"); fprintf(stderr, "Verbose and quiet modes are incompatible, please specify just one or neither!\n\n");
argp_help(&argp, stderr, ARGP_HELP_USAGE, "veristat"); argp_help(&argp, stderr, ARGP_HELP_USAGE, "veristat");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment