Skip to contentSkip to conversation

perf report: Change sort order by a specified event in group

PATCH Superseded Jin Yao 2 participants 7 messages Dec 18, 2019 – Dec 19, 2019 perf events

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Jin Yao

author
#0 lore raw

PATCH v4 1/3 perf report: Change sort order by a specified event in group

When performing "perf report --group", it shows the event group information together. By default, the output is sorted by the first event in group.

It would be nice for user to select any event for sorting. This patch introduces a new option "--group-sort-idx" to sort the output by the event at the index n in event group.

For example,

Before:

  # perf report --group --stdio

# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, BR_MISP_RETIRED.ALL_BRANCHES:pp, cpu/event=0xc0,umask=1,cmask=1, # Event count (approx.): 6451235635
#

  #                         Overhead  Command    Shared Object            Symbol
  # ................................  .........  .......................  ...................................
  #
      92.19%  98.68%   0.00%  93.30%  mgen       mgen                     [.] LOOP1
       3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
       1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
       1.56%   0.01%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494ce
       1.56%   0.00%   0.00%   0.00%  mgen       [kernel.kallsyms]        [k] task_tick_fair
       0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
       0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
       0.00%   0.03%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] g_main_context_check
       0.00%   0.03%   0.00%   0.00%  swapper    [kernel.kallsyms]        [k] apic_timer_interrupt
       ...

After:

  # perf report --group --stdio --group-sort-idx 3

# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, BR_MISP_RETIRED.ALL_BRANCHES:pp, cpu/event=0xc0,umask=1,cmask=1, # Event count (approx.): 6451235635
#

  #                         Overhead  Command    Shared Object            Symbol
  # ................................  .........  .......................  ...................................
  #
      92.19%  98.68%   0.00%  93.30%  mgen       mgen                     [.] LOOP1
       0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
       3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
       0.00%   0.00%   0.00%   0.06%  swapper    [kernel.kallsyms]        [k] hrtimer_start_range_ns
       1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
       0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
       0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] update_curr
       0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] apic_timer_interrupt
       0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] native_apic_msr_eoi_write
       0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] __update_load_avg_se
       0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] scheduler_tick

Now the output is sorted by the fourth event in group.

v4:
---
1. Update Documentation/perf-report.txt to mention '--group-sort-idx' support multiple groups with different amount of events and it should be used on grouped events.

2. Update __hpp__group_sort_idx(), just return when the idx is out of limit.

3. Return failure on symbol_conf.group_sort_idx && !session->evlist->nr_groups. So now we don't need to use together with --group.

v3:
---
Refine the code in __hpp__group_sort_idx().

Before:

   for (i = 1; i < nr_members; i++) {
        if (i == idx) {
                ret = field_cmp(fields_a[i], fields_b[i]);
                if (ret)
                        goto out;
        }

}

After:

   if (idx >= 1 && idx < nr_members) {
        ret = field_cmp(fields_a[idx], fields_b[idx]);
        if (ret)
                goto out;

}

v2:
---
No change

---
 tools/perf/Documentation/perf-report.txt |   5 ++
 tools/perf/builtin-report.c              |  10 +++
 tools/perf/ui/hist.c                     | 104 +++++++++++++++++++----
 tools/perf/util/symbol_conf.h            |   1 +
 4 files changed, 105 insertions(+), 15 deletions(-)
tools/perf/Documentation/perf-report.txt +5 -0
index 8dbe2119686a..fbb715bcb512 100644
@@ -371,6 +371,11 @@ OPTIONS
 	Show event group information together. It forces group output also
 	if there are no groups defined in data file.
 
+--group-sort-idx::
+	Sort the output by the event at the index n in group. If n is invalid,
+	sort by the first event. It can support multiple groups with different
+	amount of events. WARNING: This should be used on grouped events.
+
 --demangle::
 	Demangle symbol names to human readable form. It's enabled by default,
 	disable with --no-demangle.
tools/perf/builtin-report.c +10 -0
index 387311c67264..664e2e94d97d 100644
@@ -1210,6 +1210,10 @@ int cmd_report(int argc, const char **argv)
 		    "Show a column with the sum of periods"),
 	OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &report.group_set,
 		    "Show event group information together"),
+	OPT_INTEGER(0, "group-sort-idx", &symbol_conf.group_sort_idx,
+		    "Sort the output by the event at the index n in group. "
+		    "If n is invalid, sort by the first event. "
+		    "WARNING: should be used on grouped events."),
 	OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "",
 		    "use branch records for per branch histogram filling",
 		    parse_branch_mode),
@@ -1349,6 +1353,12 @@ int cmd_report(int argc, const char **argv)
 
 	setup_forced_leader(&report, session->evlist);
 
+	if (symbol_conf.group_sort_idx && !session->evlist->nr_groups) {
+		parse_options_usage(NULL, options, "group-sort-idx", 0);
+		ret = -EINVAL;
+		goto error;
+	}
+
 	if (itrace_synth_opts.last_branch)
 		has_br_stack = true;
 
tools/perf/ui/hist.c +89 -15

126 lines not on this page · raw message

tools/perf/util/symbol_conf.h +1 -0
index 10f1ec3e0349..b916afb95ec5 100644
@@ -73,6 +73,7 @@ struct symbol_conf {
 	const char	*symfs;
 	int		res_sample;
 	int		pad_output_len_dso;
+	int		group_sort_idx;
 };
 
 extern struct symbol_conf symbol_conf;
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v4 2/3 perf report: Support a new key to reload the browser

Sometimes we may need to reload the browser to update the output since some options are changed.

This patch creates a new key K_RELOAD. Once the __cmd_report() returns K_RELOAD, it would repeat the whole process, such as, read samples from data file, sort the data and display in the browser.

v4:
---
Need to quit in perf_evsel_menu__run if key is K_RELOAD.

v3:
---
No change.

v2:
---
This is a new patch created in v2.

---
 tools/perf/builtin-report.c    | 4 ++--
 tools/perf/ui/browsers/hists.c | 1 +
 tools/perf/ui/keysyms.h        | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)
tools/perf/builtin-report.c +2 -2
index 664e2e94d97d..defd734ca31c 100644
@@ -635,7 +635,7 @@ static int report__browse_hists(struct report *rep)
 		 * Usually "ret" is the last pressed key, and we only
 		 * care if the key notifies us to switch data file.
 		 */
-		if (ret != K_SWITCH_INPUT_DATA)
+		if (ret != K_SWITCH_INPUT_DATA && ret != K_RELOAD)
 			ret = 0;
 		break;
 	case 2:
@@ -1538,7 +1538,7 @@ int cmd_report(int argc, const char **argv)
 	sort__setup_elide(stdout);
 
 	ret = __cmd_report(&report);
-	if (ret == K_SWITCH_INPUT_DATA) {
+	if (ret == K_SWITCH_INPUT_DATA || ret == K_RELOAD) {
 		perf_session__delete(session);
 		goto repeat;
 	} else
tools/perf/ui/browsers/hists.c +1 -0
index d4d3558fdef4..096b3bc0fbef 100644
@@ -3335,6 +3335,7 @@ static int perf_evsel_menu__run(struct evsel_menu *menu,
 					pos = perf_evsel__prev(pos);
 				goto browse_hists;
 			case K_SWITCH_INPUT_DATA:
+			case K_RELOAD:
 			case 'q':
 			case CTRL('c'):
 				goto out;
tools/perf/ui/keysyms.h +1 -0
index fbfac29077f2..04cc4e5c031f 100644
@@ -25,5 +25,6 @@
 #define K_ERROR	 -2
 #define K_RESIZE -3
 #define K_SWITCH_INPUT_DATA -4
+#define K_RELOAD -5
 
 #endif /* _PERF_KEYSYMS_H_ */
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v4 3/3 perf report: support hotkey to let user select any event for sorting

In reply to Jin Yao

When performing "perf report --group", it shows the event group information together. In previous patch, we have supported a new option "--group-sort-idx" to sort the output by the event at the index n in event group.

It would be nice if we can use a hotkey in browser to select a event to sort.

For example,

  # perf report --group

Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, ...

                        Overhead  Command    Shared Object            Symbol
  92.19%  98.68%   0.00%  93.30%  mgen       mgen                     [.] LOOP1
   3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
   1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
   1.56%   0.01%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494ce
   1.56%   0.00%   0.00%   0.00%  mgen       [kernel.kallsyms]        [k] task_tick_fair
   0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
   0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
   0.00%   0.03%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] g_main_context_check
   0.00%   0.03%   0.00%   0.00%  swapper    [kernel.kallsyms]        [k] apic_timer_interrupt
   0.00%   0.03%   0.00%   0.00%  swapper    [kernel.kallsyms]        [k] check_preempt_curr

When user press hotkey '3' (event index, starting from 0), it indicates to sort output by the forth event in group.

Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, ...

                        Overhead  Command    Shared Object            Symbol
  92.19%  98.68%   0.00%  93.30%  mgen       mgen                     [.] LOOP1
   0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
   3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
   0.00%   0.00%   0.00%   0.06%  swapper    [kernel.kallsyms]        [k] hrtimer_start_range_ns
   1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
   0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
   0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] update_curr
   0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] apic_timer_interrupt
   0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] native_apic_msr_eoi_write
   0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] __update_load_avg_se

v4:
---
No change

v3:
---
No change

v2:
---
1. Report warning at helpline when index is invalid.
2. Report warning at helpline when it's not group event.
3. Use "case '0' ... '9'" to refine the code
4. Split K_RELOAD implementation to another patch.

---
 tools/perf/ui/browsers/hists.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
tools/perf/ui/browsers/hists.c +24 -1
index 096b3bc0fbef..22e76bd1a2d9 100644
@@ -2876,7 +2876,8 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events,
 	"s             Switch to another data file in PWD\n"
 	"t             Zoom into current Thread\n"
 	"V             Verbose (DSO names in callchains, etc)\n"
-	"/             Filter symbol by name";
+	"/             Filter symbol by name\n"
+	"0-9           Sort by event n in group";
 	static const char top_help[] = HIST_BROWSER_HELP_COMMON
 	"P             Print histograms to perf.hist.N\n"
 	"t             Zoom into current Thread\n"
@@ -2937,6 +2938,28 @@ static int perf_evsel__hists_browse(struct evsel *evsel, int nr_events,
 			 * go to the next or previous
 			 */
 			goto out_free_stack;
+		case '0' ... '9':
+			if (!symbol_conf.event_group ||
+			    evsel->core.nr_members < 2) {
+				snprintf(buf, sizeof(buf),
+					 "Sort by index only available with group events!");
+				helpline = buf;
+				continue;
+			}
+
+			symbol_conf.group_sort_idx = key - '0';
+
+			if (symbol_conf.group_sort_idx >= evsel->core.nr_members) {
+				snprintf(buf, sizeof(buf),
+					 "Max event group index to sort is %d (index from 0 to %d)",
+					 evsel->core.nr_members - 1,
+					 evsel->core.nr_members - 1);
+				helpline = buf;
+				continue;
+			}
+
+			key = K_RELOAD;
+			goto out_free_stack;
 		case 'a':
 			if (!hists__has(hists, sym)) {
 				ui_browser__warning(&browser->b, delay_secs * 2,
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH v4 3/3] perf report: support hotkey to let user select any event for sorting

Quoted 28 lines · Jin Yao

When performing "perf report --group", it shows the event group information together. In previous patch, we have supported a new option "--group-sort-idx" to sort the output by the event at the index n in event group.

It would be nice if we can use a hotkey in browser to select a event to sort.

For example,

  # perf report --group

Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, ...

                        Overhead  Command    Shared Object            Symbol
  92.19%  98.68%   0.00%  93.30%  mgen       mgen                     [.] LOOP1
   3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
   1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
   1.56%   0.01%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494ce
   1.56%   0.00%   0.00%   0.00%  mgen       [kernel.kallsyms]        [k] task_tick_fair
   0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
   0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
   0.00%   0.03%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] g_main_context_check
   0.00%   0.03%   0.00%   0.00%  swapper    [kernel.kallsyms]        [k] apic_timer_interrupt
   0.00%   0.03%   0.00%   0.00%  swapper    [kernel.kallsyms]        [k] check_preempt_curr

When user press hotkey '3' (event index, starting from 0), it indicates to sort output by the forth event in group.

Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, ...

Quoted 11 lines
                        Overhead  Command    Shared Object            Symbol
  92.19%  98.68%   0.00%  93.30%  mgen       mgen                     [.] LOOP1
   0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
   3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
   0.00%   0.00%   0.00%   0.06%  swapper    [kernel.kallsyms]        [k] hrtimer_start_range_ns
   1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
   0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
   0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] update_curr
   0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] apic_timer_interrupt
   0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] native_apic_msr_eoi_write
   0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] __update_load_avg_se

when I press 0...9 I'm getting extra columns:

Samples: 134 of events 'anon group { cycles:u, instructions:u, cache-misses:u, cycles:u, instructions:u }', Event count (approx.): 7107344

                                Overhead  Command  Shared Object     Symbol                                                                  Self
  17.95%  41.20%   0.00%  12.44%  41.30%  ls       libc-2.29.so      [.] __strcoll_l                       17.95%  41.20%   0.00%  12.44%  41.30%       N/A
   0.00%  13.22%   0.00%   0.00%   0.00%  ls       ls                [.] 0x000000000000871c                 0.00%  13.22%   0.00%   0.00%   0.00%       N/A
   8.32%  11.49%   0.00%   2.62%   9.34%  ls       ld-2.29.so        [.] do_lookup_x                        8.32%  11.49%   0.00%   2.62%   9.34%       N/A
   0.00%   8.29%  31.18%  13.34%   3.05%  ls       ld-2.29.so        [.] _dl_lookup_symbol_x                0.00%   8.29%  31.18%  13.34%   3.05%       N/A
   0.00%   6.47%   0.00%   0.00%   0.00%  ls       libc-2.29.so      [.] __strlen_avx2                      0.00%   6.47%   0.00%   0.00%   0.00%       N/A
   0.00%   5.97%   0.00%   0.00%   0.00%  ls       ls                [.] 0x0000000000014001                 0.00%   5.97%   0.00%   0.00%   0.00%       N/A
   5.77%   5.83%   7.79%   4.78%   5.04%  ls       ld-2.29.so        [.] strcmp                             5.77%   5.83%   7.79%   4.78%   5.04%       N/A
   2.31%   4.35%   8.30%   0.00%   0.00%  ls       ld-2.29.so        [.] _dl_map_object_from_fd             2.31%   4.35%   8.30%   0.00%   0.00%       N/A
   0.00%   2.96%   0.00%   1.30%   2.22%  ls       ld-2.29.so        [.] __GI___tunables_init               0.00%   2.96%   0.00%   1.30%   2.22%       N/A
   0.66%   0.22%   0.68%   0.00%   0.21%  ls       ld-2.29.so        [.] _dl_start                          0.66%   0.22%   0.68%   0.00%   0.21%       N/A
   2.42%   0.00%   0.02%   3.16%   0.00%  ls       [unknown]         [k] 0xffffffffa2a012b0                 2.42%   0.00%   0.02%   3.16%   0.00%       N/A
   0.16%   0.00%   0.01%   0.20%   0.00%  ls       ld-2.29.so        [.] _start                             0.16%   0.00%   0.01%   0.20%   0.00%       N/A
   0.00%   0.00%  11.47%   0.00%   0.00%  ls       libcap.so.2.26    [.] 0x0000000000002420                 0.00%   0.00%  11.47%   0.00%   0.00%       N/A
   0.00%   0.00%  10.50%   0.00%   0.00%  ls       libc-2.29.so      [.] __GI___tcgetattr                   0.00%   0.00%  10.50%   0.00%   0.00%       N/A
   0.00%   0.00%   9.14%   0.00%   0.00%  ls       ls                [.] 0x000000000000767a                 0.00%   0.00%   9.14%   0.00%   0.00%       N/A
  13.60%   0.00%   7.14%   2.31%   0.00%  ls       ld-2.29.so        [.] _dl_relocate_object               13.60%   0.00%   7.14%   2.31%   0.00%       N/A
   2.13%   0.00%   6.14%   0.00%   0.00%  ls       ld-2.29.so        [.] _dl_map_object_deps                2.13%   0.00%   6.14%   0.00%   0.00%       N/A
   0.00%   0.00%   5.27%   0.00%   0.00%  ls       ld-2.29.so        [.] strlen                             0.00%   0.00%   5.27%   0.00%   0.00%       N/A
   1.31%   0.00%   2.37%   1.08%   0.00%  ls       ld-2.29.so        [.] _dl_sysdep_start                   1.31%   0.00%   2.37%   1.08%   0.00%       N/A

jirka

author
#4 lore raw

Re: [PATCH v4 3/3] perf report: support hotkey to let user select any event for sorting

Quoted 66 lines · Jiri Olsa
Quoted 27 lines · Jin Yao

When performing "perf report --group", it shows the event group information together. In previous patch, we have supported a new option "--group-sort-idx" to sort the output by the event at the index n in event group.

It would be nice if we can use a hotkey in browser to select a event to sort.

For example,

   # perf report --group

Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, ...

                         Overhead  Command    Shared Object            Symbol
   92.19%  98.68%   0.00%  93.30%  mgen       mgen                     [.] LOOP1
    3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
    1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
    1.56%   0.01%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494ce
    1.56%   0.00%   0.00%   0.00%  mgen       [kernel.kallsyms]        [k] task_tick_fair
    0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
    0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
    0.00%   0.03%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] g_main_context_check
    0.00%   0.03%   0.00%   0.00%  swapper    [kernel.kallsyms]        [k] apic_timer_interrupt
    0.00%   0.03%   0.00%   0.00%  swapper    [kernel.kallsyms]        [k] check_preempt_curr

When user press hotkey '3' (event index, starting from 0), it indicates to sort output by the forth event in group.

Quoted 12 lines
   Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, ...
                         Overhead  Command    Shared Object            Symbol
   92.19%  98.68%   0.00%  93.30%  mgen       mgen                     [.] LOOP1
    0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
    3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
    0.00%   0.00%   0.00%   0.06%  swapper    [kernel.kallsyms]        [k] hrtimer_start_range_ns
    1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
    0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
    0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] update_curr
    0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] apic_timer_interrupt
    0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] native_apic_msr_eoi_write
    0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] __update_load_avg_se

when I press 0...9 I'm getting extra columns:

Samples: 134 of events 'anon group { cycles:u, instructions:u, cache-misses:u, cycles:u, instructions:u }', Event count (approx.): 7107344

                                 Overhead  Command  Shared Object     Symbol                                                                  Self
   17.95%  41.20%   0.00%  12.44%  41.30%  ls       libc-2.29.so      [.] __strcoll_l                       17.95%  41.20%   0.00%  12.44%  41.30%       N/A
    0.00%  13.22%   0.00%   0.00%   0.00%  ls       ls                [.] 0x000000000000871c                 0.00%  13.22%   0.00%   0.00%   0.00%       N/A
    8.32%  11.49%   0.00%   2.62%   9.34%  ls       ld-2.29.so        [.] do_lookup_x                        8.32%  11.49%   0.00%   2.62%   9.34%       N/A
    0.00%   8.29%  31.18%  13.34%   3.05%  ls       ld-2.29.so        [.] _dl_lookup_symbol_x                0.00%   8.29%  31.18%  13.34%   3.05%       N/A
    0.00%   6.47%   0.00%   0.00%   0.00%  ls       libc-2.29.so      [.] __strlen_avx2                      0.00%   6.47%   0.00%   0.00%   0.00%       N/A
    0.00%   5.97%   0.00%   0.00%   0.00%  ls       ls                [.] 0x0000000000014001                 0.00%   5.97%   0.00%   0.00%   0.00%       N/A
    5.77%   5.83%   7.79%   4.78%   5.04%  ls       ld-2.29.so        [.] strcmp                             5.77%   5.83%   7.79%   4.78%   5.04%       N/A
    2.31%   4.35%   8.30%   0.00%   0.00%  ls       ld-2.29.so        [.] _dl_map_object_from_fd             2.31%   4.35%   8.30%   0.00%   0.00%       N/A
    0.00%   2.96%   0.00%   1.30%   2.22%  ls       ld-2.29.so        [.] __GI___tunables_init               0.00%   2.96%   0.00%   1.30%   2.22%       N/A
    0.66%   0.22%   0.68%   0.00%   0.21%  ls       ld-2.29.so        [.] _dl_start                          0.66%   0.22%   0.68%   0.00%   0.21%       N/A
    2.42%   0.00%   0.02%   3.16%   0.00%  ls       [unknown]         [k] 0xffffffffa2a012b0                 2.42%   0.00%   0.02%   3.16%   0.00%       N/A
    0.16%   0.00%   0.01%   0.20%   0.00%  ls       ld-2.29.so        [.] _start                             0.16%   0.00%   0.01%   0.20%   0.00%       N/A
    0.00%   0.00%  11.47%   0.00%   0.00%  ls       libcap.so.2.26    [.] 0x0000000000002420                 0.00%   0.00%  11.47%   0.00%   0.00%       N/A
    0.00%   0.00%  10.50%   0.00%   0.00%  ls       libc-2.29.so      [.] __GI___tcgetattr                   0.00%   0.00%  10.50%   0.00%   0.00%       N/A
    0.00%   0.00%   9.14%   0.00%   0.00%  ls       ls                [.] 0x000000000000767a                 0.00%   0.00%   9.14%   0.00%   0.00%       N/A
   13.60%   0.00%   7.14%   2.31%   0.00%  ls       ld-2.29.so        [.] _dl_relocate_object               13.60%   0.00%   7.14%   2.31%   0.00%       N/A
    2.13%   0.00%   6.14%   0.00%   0.00%  ls       ld-2.29.so        [.] _dl_map_object_deps                2.13%   0.00%   6.14%   0.00%   0.00%       N/A
    0.00%   0.00%   5.27%   0.00%   0.00%  ls       ld-2.29.so        [.] strlen                             0.00%   0.00%   5.27%   0.00%   0.00%       N/A
    1.31%   0.00%   2.37%   1.08%   0.00%  ls       ld-2.29.so        [.] _dl_sysdep_start                   1.31%   0.00%   2.37%   1.08%   0.00%       N/A
Quoted 2 lines

jirka

Looks it's an existing issue in perf. We can reproduce it by following steps.

1. perf record -a -e cycles,instructions -- sleep 3
2. perf report --group
3. In browser, we use hotkey 's' to switch to another perf.data
4. Now in browser, the extra columns 'Self' and 'Children' will be shown.

But I have not figured out which patch caused this issue. :(

Thanks
Jin Yao

author
#5 lore raw

Re: [PATCH v4 3/3] perf report: support hotkey to let user select any event for sorting

Quoted 80 lines · Yao
Quoted 62 lines · Jiri Olsa
Quoted 30 lines · Jin Yao

When performing "perf report --group", it shows the event group information together. In previous patch, we have supported a new option "--group-sort-idx" to sort the output by the event at the index n in event group.

It would be nice if we can use a hotkey in browser to select a event to sort.

For example,

   # perf report --group

  Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, ... Overhead  Command    Shared Object            Symbol
   92.19%  98.68%   0.00%  93.30%  mgen mgen                     [.] LOOP1

    3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
    1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
    1.56%   0.01%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494ce
    1.56%   0.00%   0.00%   0.00%  mgen       [kernel.kallsyms]        [k] task_tick_fair
    0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
    0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
    0.00%   0.03%   0.00%   0.00%  gsd-color  libglib-2.0.so.0.5600.4  [.] g_main_context_check
    0.00%   0.03%   0.00%   0.00%  swapper    [kernel.kallsyms]        [k] apic_timer_interrupt
    0.00%   0.03%   0.00%   0.00%  swapper    [kernel.kallsyms]        [k] check_preempt_curr

When user press hotkey '3' (event index, starting from 0), it indicates to sort output by the forth event in group.

   Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, ... Overhead  Command    Shared Object            Symbol
   92.19%  98.68%   0.00%  93.30%  mgen mgen                     [.] LOOP1

Quoted 9 lines
    0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
    3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
    0.00%   0.00%   0.00%   0.06%  swapper    [kernel.kallsyms]        [k] hrtimer_start_range_ns
    1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
    0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
    0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] update_curr
    0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] apic_timer_interrupt
    0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] native_apic_msr_eoi_write
    0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] __update_load_avg_se

when I press 0...9 I'm getting extra columns:

Samples: 134  of events 'anon group { cycles:u, instructions:u, cache-misses:u, cycles:u, instructions:u }', Event count (approx.): 7107344
                                 Overhead  Command  Shared Object Symbol                                                                  Self

   17.95%  41.20%   0.00%  12.44%  41.30%  ls       libc-2.29.so [.] __strcoll_l                       17.95%  41.20%   0.00%  12.44% 41.30%       N/A
    0.00%  13.22%   0.00%   0.00%   0.00%  ls       ls [.] 0x000000000000871c                 0.00%  13.22%   0.00%   0.00% 0.00%       N/A
    8.32%  11.49%   0.00%   2.62%   9.34%  ls       ld-2.29.so [.] do_lookup_x                        8.32%  11.49%   0.00%   2.62% 9.34%       N/A
    0.00%   8.29%  31.18%  13.34%   3.05%  ls       ld-2.29.so [.] _dl_lookup_symbol_x                0.00%   8.29%  31.18%  13.34% 3.05%       N/A

    0.00%   6.47%   0.00%   0.00%   0.00%  ls       libc-2.29.so      [.] __strlen_avx2                      0.00%   6.47%   0.00%   0.00%   0.00%       N/A
    0.00%   5.97%   0.00%   0.00%   0.00%  ls       ls                [.] 0x0000000000014001                 0.00%   5.97%   0.00%   0.00%   0.00%       N/A
    5.77%   5.83%   7.79%   4.78%   5.04%  ls       ld-2.29.so        [.] strcmp                             5.77%   5.83%   7.79%   4.78%   5.04%       N/A
    2.31%   4.35%   8.30%   0.00%   0.00%  ls       ld-2.29.so        [.] _dl_map_object_from_fd             2.31%   4.35%   8.30%   0.00%   0.00%       N/A
    0.00%   2.96%   0.00%   1.30%   2.22%  ls       ld-2.29.so        [.] __GI___tunables_init               0.00%   2.96%   0.00%   1.30%   2.22%       N/A
    0.66%   0.22%   0.68%   0.00%   0.21%  ls       ld-2.29.so        [.] _dl_start                          0.66%   0.22%   0.68%   0.00%   0.21%       N/A
    2.42%   0.00%   0.02%   3.16%   0.00%  ls       [unknown]         [k] 0xffffffffa2a012b0                 2.42%   0.00%   0.02%   3.16%   0.00%       N/A
    0.16%   0.00%   0.01%   0.20%   0.00%  ls       ld-2.29.so        [.] _start                             0.16%   0.00%   0.01%   0.20%   0.00%       N/A

    0.00%   0.00%  11.47%   0.00%   0.00%  ls       libcap.so.2.26 [.] 0x0000000000002420                 0.00%   0.00%  11.47%   0.00% 0.00%       N/A
    0.00%   0.00%  10.50%   0.00%   0.00%  ls       libc-2.29.so [.] __GI___tcgetattr                   0.00%   0.00%  10.50%   0.00% 0.00%       N/A
    0.00%   0.00%   9.14%   0.00%   0.00%  ls       ls [.] 0x000000000000767a                 0.00%   0.00%   9.14%   0.00% 0.00%       N/A
   13.60%   0.00%   7.14%   2.31%   0.00%  ls       ld-2.29.so [.] _dl_relocate_object               13.60%   0.00%   7.14%   2.31% 0.00%       N/A

Quoted 7 lines
    2.13%   0.00%   6.14%   0.00%   0.00%  ls       ld-2.29.so        [.] _dl_map_object_deps                2.13%   0.00%   6.14%   0.00%   0.00%       N/A
    0.00%   0.00%   5.27%   0.00%   0.00%  ls       ld-2.29.so        [.] strlen                             0.00%   0.00%   5.27%   0.00%   0.00%       N/A
    1.31%   0.00%   2.37%   1.08%   0.00%  ls       ld-2.29.so        [.] _dl_sysdep_start                   1.31%   0.00%   2.37%   1.08%   0.00%       N/A

jirka

Looks it's an existing issue in perf. We can reproduce it by following steps.

1. perf record -a -e cycles,instructions -- sleep 3
2. perf report --group
3. In browser, we use hotkey 's' to switch to another perf.data
4. Now in browser, the extra columns 'Self' and 'Children' will be shown.

Quoted 4 lines

But I have not figured out which patch caused this issue. :(

Thanks
Jin Yao

I have debugged this issue and I find that's because setup_sorting() is executed again after repeat path, so dimensions are added again.

Could you help to review following fix? Thanks!

tools/perf/builtin-report.c +1 -0
index 387311c67264..de988589d99b 100644
@@ -1076,6 +1076,7 @@ int cmd_report(int argc, const char **argv)
        struct stat st;
        bool has_br_stack = false;
        int branch_mode = -1;
+       int last_key = 0;
        bool branch_call_mode = false;
 #define CALLCHAIN_DEFAULT_OPT  "graph,0.5,caller,function,percent"
        static const char report_callchain_help[] = "Display call graph 

(stack chain/backtrace):\n\n"
@@ -1450,7 +1451,8 @@ int cmd_report(int argc, const char **argv)

                sort_order = sort_tmp;
        }

- if (setup_sorting(session->evlist) < 0) {
+ if ((last_key != K_SWITCH_INPUT_DATA) &&

+           (setup_sorting(session->evlist) < 0)) {
                if (sort_order)
                        parse_options_usage(report_usage, options, "s", 1);
                if (field_order)
@@ -1530,6 +1532,7 @@ int cmd_report(int argc, const char **argv)
        ret = __cmd_report(&report);
        if (ret == K_SWITCH_INPUT_DATA) {
                perf_session__delete(session);
+               last_key = K_SWITCH_INPUT_DATA;
                goto repeat;
        } else
                ret = 0;

Thanks
Jin Yao

Acked-by on v4 1/3
#6 lore raw
In reply to Jin Yao

On Wed, Dec 18, 2019 at 10:24:41AM +0800, Jin Yao wrote:

SNIP

Quoted 35 lines

After:

  # perf report --group --stdio --group-sort-idx 3

# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 12K of events 'cpu/instructions,period=2000003/, cpu/cpu-cycles,period=200003/, BR_MISP_RETIRED.ALL_BRANCHES:pp, cpu/event=0xc0,umask=1,cmask=1, # Event count (approx.): 6451235635
#

  #                         Overhead  Command    Shared Object            Symbol
  # ................................  .........  .......................  ...................................
  #
      92.19%  98.68%   0.00%  93.30%  mgen       mgen                     [.] LOOP1
       0.00%   0.13%   0.00%   6.08%  swapper    [kernel.kallsyms]        [k] intel_idle
       3.12%   0.29%   0.00%   0.16%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x0000000000049515
       0.00%   0.00%   0.00%   0.06%  swapper    [kernel.kallsyms]        [k] hrtimer_start_range_ns
       1.56%   0.03%   0.00%   0.04%  gsd-color  libglib-2.0.so.0.5600.4  [.] 0x00000000000494b7
       0.00%   0.15%   0.00%   0.04%  perf       [kernel.kallsyms]        [k] smp_call_function_single
       0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] update_curr
       0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] apic_timer_interrupt
       0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] native_apic_msr_eoi_write
       0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] __update_load_avg_se
       0.00%   0.00%   0.00%   0.02%  mgen       [kernel.kallsyms]        [k] scheduler_tick

Now the output is sorted by the fourth event in group.

v4:
---
1. Update Documentation/perf-report.txt to mention '--group-sort-idx' support multiple groups with different amount of events and it should be used on grouped events.

Quoted 5 lines

2. Update __hpp__group_sort_idx(), just return when the idx is out of limit.

3. Return failure on symbol_conf.group_sort_idx && !session->evlist->nr_groups. So now we don't need to use together with --group.

thanks,
jirka