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

perf report: Show all sort keys in help output

Show all the supported sort keys in the command line help output, so
that it's not needed to refer to the manpage.

Before:

% perf report -h
...
-s, --sort <key[,key2...]>
sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ... Please refer the man page for the complete list.

After:

% perf report -h
...
-s, --sort <key[,key2...]>
sort by key(s): overhead overhead_sys overhead_us overhead_guest_sys overhead_guest_us overhead_children sample period pid comm dso symbol parent cpu ...

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
LPU-Reference: 20190314225002.30108-5-andi@firstfloor.org
Link: https://lkml.kernel.org/n/tip-9r3uz2ch4izoi1uln3f889co@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Andi Kleen and committed by
Arnaldo Carvalho de Melo
702fb9b4 c38dab7d

+56 -3
+2 -3
tools/perf/builtin-report.c
··· 1083 1083 OPT_BOOLEAN(0, "header-only", &report.header_only, 1084 1084 "Show only data header."), 1085 1085 OPT_STRING('s', "sort", &sort_order, "key[,key2...]", 1086 - "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..." 1087 - " Please refer the man page for the complete list."), 1086 + sort_help("sort by key(s):")), 1088 1087 OPT_STRING('F', "fields", &field_order, "key[,keys...]", 1089 - "output field(s): overhead, period, sample plus all of sort keys"), 1088 + sort_help("output field(s): overhead period sample ")), 1090 1089 OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization, 1091 1090 "Show sample percentage for different cpu modes"), 1092 1091 OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
+52
tools/perf/util/sort.c
··· 13 13 #include "evsel.h" 14 14 #include "evlist.h" 15 15 #include "strlist.h" 16 + #include "strbuf.h" 16 17 #include <traceevent/event-parse.h> 17 18 #include "mem-events.h" 18 19 #include "annotate.h" ··· 3107 3106 3108 3107 reset_dimensions(); 3109 3108 perf_hpp__reset_output_field(&perf_hpp_list); 3109 + } 3110 + 3111 + #define INDENT (3*8 + 1) 3112 + 3113 + static void add_key(struct strbuf *sb, const char *str, int *llen) 3114 + { 3115 + if (*llen >= 75) { 3116 + strbuf_addstr(sb, "\n\t\t\t "); 3117 + *llen = INDENT; 3118 + } 3119 + strbuf_addf(sb, " %s", str); 3120 + *llen += strlen(str) + 1; 3121 + } 3122 + 3123 + static void add_sort_string(struct strbuf *sb, struct sort_dimension *s, int n, 3124 + int *llen) 3125 + { 3126 + int i; 3127 + 3128 + for (i = 0; i < n; i++) 3129 + add_key(sb, s[i].name, llen); 3130 + } 3131 + 3132 + static void add_hpp_sort_string(struct strbuf *sb, struct hpp_dimension *s, int n, 3133 + int *llen) 3134 + { 3135 + int i; 3136 + 3137 + for (i = 0; i < n; i++) 3138 + add_key(sb, s[i].name, llen); 3139 + } 3140 + 3141 + const char *sort_help(const char *prefix) 3142 + { 3143 + struct strbuf sb; 3144 + char *s; 3145 + int len = strlen(prefix) + INDENT; 3146 + 3147 + strbuf_init(&sb, 300); 3148 + strbuf_addstr(&sb, prefix); 3149 + add_hpp_sort_string(&sb, hpp_sort_dimensions, 3150 + ARRAY_SIZE(hpp_sort_dimensions), &len); 3151 + add_sort_string(&sb, common_sort_dimensions, 3152 + ARRAY_SIZE(common_sort_dimensions), &len); 3153 + add_sort_string(&sb, bstack_sort_dimensions, 3154 + ARRAY_SIZE(bstack_sort_dimensions), &len); 3155 + add_sort_string(&sb, memory_sort_dimensions, 3156 + ARRAY_SIZE(memory_sort_dimensions), &len); 3157 + s = strbuf_detach(&sb, NULL); 3158 + strbuf_release(&sb); 3159 + return s; 3110 3160 }
+2
tools/perf/util/sort.h
··· 296 296 void sort__setup_elide(FILE *fp); 297 297 void perf_hpp__set_elide(int idx, bool elide); 298 298 299 + const char *sort_help(const char *prefix); 300 + 299 301 int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset); 300 302 301 303 bool is_strict_order(const char *order);