Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf data: Correct -h output

There is currently only 1 'perf data' command, but supporting extra
commands was breaking the help output. Simplify for now so that the help
output is correct.

Before:
$ perf data -h

Usage: perf data [<common options>] <command> [<options>]

$ perf data
Usage:
perf data [<common options>] <command> [<options>]

Available commands:
convert - converts data file between formats

After:
$ perf data

Usage: perf data convert [<options>]

-f, --force don't complain, do it
-i, --input <file> input file name
-v, --verbose be more verbose
--all Convert all events
--to-ctf ... Convert to CTF format
--to-json ... Convert to JSON format
--tod Convert time to wall clock time

$ perf data -h

Usage: perf data convert [<options>]

-f, --force don't complain, do it
-i, --input <file> input file name
-v, --verbose be more verbose
--all Convert all events
--to-ctf ... Convert to CTF format
--to-json ... Convert to JSON format
--tod Convert time to wall clock time

Signed-off-by: Joshua Martinez <joshuamart@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20210824205829.52822-1-irogers@google.com
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Joshua Martinez and committed by
Arnaldo Carvalho de Melo
760f5e77 cb5a2ebb

+20 -44
+20 -44
tools/perf/builtin-data.c
··· 21 21 #define for_each_cmd(cmd) \ 22 22 for (cmd = data_cmds; cmd && cmd->name; cmd++) 23 23 24 - static const struct option data_options[] = { 25 - OPT_END() 26 - }; 27 - 28 24 static const char * const data_subcommands[] = { "convert", NULL }; 29 25 30 26 static const char *data_usage[] = { 31 - "perf data [<common options>] <command> [<options>]", 32 - NULL 33 - }; 34 - 35 - static void print_usage(void) 36 - { 37 - struct data_cmd *cmd; 38 - 39 - printf("Usage:\n"); 40 - printf("\t%s\n\n", data_usage[0]); 41 - printf("\tAvailable commands:\n"); 42 - 43 - for_each_cmd(cmd) { 44 - printf("\t %s\t- %s\n", cmd->name, cmd->summary); 45 - } 46 - 47 - printf("\n"); 48 - } 49 - 50 - static const char * const data_convert_usage[] = { 51 27 "perf data convert [<options>]", 52 28 NULL 53 29 }; 54 30 55 - static int cmd_data_convert(int argc, const char **argv) 56 - { 57 - const char *to_json = NULL; 58 - const char *to_ctf = NULL; 59 - struct perf_data_convert_opts opts = { 60 - .force = false, 61 - .all = false, 62 - }; 63 - const struct option options[] = { 31 + const char *to_json; 32 + const char *to_ctf; 33 + struct perf_data_convert_opts opts = { 34 + .force = false, 35 + .all = false, 36 + }; 37 + 38 + const struct option data_options[] = { 64 39 OPT_INCR('v', "verbose", &verbose, "be more verbose"), 65 40 OPT_STRING('i', "input", &input_name, "file", "input file name"), 66 41 OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"), ··· 48 73 OPT_END() 49 74 }; 50 75 51 - argc = parse_options(argc, argv, options, 52 - data_convert_usage, 0); 76 + static int cmd_data_convert(int argc, const char **argv) 77 + { 78 + 79 + argc = parse_options(argc, argv, data_options, 80 + data_usage, 0); 53 81 if (argc) { 54 - usage_with_options(data_convert_usage, options); 82 + usage_with_options(data_usage, data_options); 55 83 return -1; 56 84 } 57 85 ··· 94 116 struct data_cmd *cmd; 95 117 const char *cmdstr; 96 118 97 - /* No command specified. */ 98 - if (argc < 2) 99 - goto usage; 100 - 101 119 argc = parse_options_subcommand(argc, argv, data_options, data_subcommands, data_usage, 102 120 PARSE_OPT_STOP_AT_NON_OPTION); 103 - if (argc < 1) 104 - goto usage; 121 + 122 + if (!argc) { 123 + usage_with_options(data_usage, data_options); 124 + return -1; 125 + } 105 126 106 127 cmdstr = argv[0]; 107 128 ··· 112 135 } 113 136 114 137 pr_err("Unknown command: %s\n", cmdstr); 115 - usage: 116 - print_usage(); 138 + usage_with_options(data_usage, data_options); 117 139 return -1; 118 140 }