Commit c511d009 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov
Browse files

selftests/bpf: emit processing progress and add quiet mode to veristat



Emit "Processing <filepath>..." for each BPF object file to be
processed, to show progress. But also add -q (--quiet) flag to silence
such messages. Doing something more clever (like overwriting same output
line) is to cumbersome and easily breakable if there is any other
console output (e.g., errors from libbpf).

Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20220923175913.3272430-5-andrii@kernel.org


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 518fee8b
Loading
Loading
Loading
Loading
+14 −1
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ static struct env {
	char **filenames;
	char **filenames;
	int filename_cnt;
	int filename_cnt;
	bool verbose;
	bool verbose;
	bool quiet;
	enum resfmt out_fmt;
	enum resfmt out_fmt;
	bool comparison_mode;
	bool comparison_mode;


@@ -107,6 +108,7 @@ const char argp_program_doc[] =
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" },
	{ "verbose", 'v', NULL, 0, "Verbose mode" },
	{ "verbose", 'v', NULL, 0, "Verbose mode" },
	{ "quiet", 'q', NULL, 0, "Quiet mode" },
	{ "emit", 'e', "SPEC", 0, "Specify stats to be emitted" },
	{ "emit", 'e', "SPEC", 0, "Specify stats to be emitted" },
	{ "sort", 's', "SPEC", 0, "Specify sort order" },
	{ "sort", 's', "SPEC", 0, "Specify sort order" },
	{ "output-format", 'o', "FMT", 0, "Result output format (table, csv), default is table." },
	{ "output-format", 'o', "FMT", 0, "Result output format (table, csv), default is table." },
@@ -131,6 +133,9 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
	case 'v':
	case 'v':
		env.verbose = true;
		env.verbose = true;
		break;
		break;
	case 'q':
		env.quiet = true;
		break;
	case 'e':
	case 'e':
		err = parse_stats(arg, &env.output_spec);
		err = parse_stats(arg, &env.output_spec);
		if (err)
		if (err)
@@ -569,8 +574,10 @@ static int process_obj(const char *filename)
		return 0;
		return 0;
	}
	}


	old_libbpf_print_fn = libbpf_set_print(libbpf_print_fn);
	if (!env.quiet && env.out_fmt == RESFMT_TABLE)
		printf("Processing '%s'...\n", basename(filename));


	old_libbpf_print_fn = libbpf_set_print(libbpf_print_fn);
	obj = bpf_object__open_file(filename, &opts);
	obj = bpf_object__open_file(filename, &opts);
	if (!obj) {
	if (!obj) {
		/* if libbpf can't open BPF object file, it could be because
		/* if libbpf can't open BPF object file, it could be because
@@ -1268,6 +1275,12 @@ 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.verbose && env.quiet) {
		fprintf(stderr, "Verbose and quiet modes are incompatible, please specify just one or neither!\n");
		argp_help(&argp, stderr, ARGP_HELP_USAGE, "veristat");
		return 1;
	}

	if (env.output_spec.spec_cnt == 0)
	if (env.output_spec.spec_cnt == 0)
		env.output_spec = default_output_spec;
		env.output_spec = default_output_spec;
	if (env.sort_spec.spec_cnt == 0)
	if (env.sort_spec.spec_cnt == 0)