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

perf top: Collapse and resort all evsels in a group

And link them, i.e. find the hist entries in the non-leader events and
link them to the ones in the leader.

This should be the same thing already done for the 'perf report' case,
but now we do it periodically.

With this in place we get percentages in from the second overhead column
on, not just on the first (the leader).

Try it using:

perf top --stdio -e '{cycles,instructions}'

You should see something like:

PerfTop: 20776 irqs/sec kernel:68.7% exact: 0.0% lost: 0/0 drop: 0/0 [cycles], (all, 8 CPUs)
---------------------------------------------------------------------------------------------------

4.44% 0.44% [kernel] [k] do_syscall_64
2.27% 0.17% [kernel] [k] entry_SYSCALL_64
1.73% 0.27% [kernel] [k] syscall_return_via_sysret
1.60% 0.91% [kernel] [k] _raw_spin_lock_irqsave
1.45% 3.53% libglib-2.0.so.0.6000.4 [.] g_string_insert_unichar
1.39% 0.21% [kernel] [k] copy_user_enhanced_fast_string
1.26% 1.15% [kernel] [k] psi_task_change
1.16% 0.14% libpixman-1.so.0.38.0 [.] 0x000000000006f403
1.00% 0.32% [kernel] [k] __sched_text_start
0.97% 2.11% [kernel] [k] n_tty_write
0.96% 0.04% [kernel] [k] queued_spin_lock_slowpath
0.93% 0.88% [kernel] [k] menu_select
0.87% 0.14% [kernel] [k] try_to_wake_up
0.77% 0.10% libpixman-1.so.0.38.0 [.] 0x000000000006f40b
0.73% 0.09% libpixman-1.so.0.38.0 [.] 0x000000000006f413
0.69% 0.48% libc-2.29.so [.] __memmove_avx_unaligned_erms
0.68% 0.29% [kernel] [k] _raw_spin_lock_irq
0.61% 0.04% libpixman-1.so.0.38.0 [.] 0x000000000006f423
0.60% 0.37% [kernel] [k] native_sched_clock
0.57% 0.23% [kernel] [k] do_idle
0.57% 0.23% [kernel] [k] __fget
0.56% 0.30% [kernel] [k] __switch_to_asm
0.56% 0.00% libc-2.29.so [.] __memset_avx2_erms
0.52% 0.32% [kernel] [k] _raw_spin_lock
0.49% 0.24% [kernel] [k] n_tty_poll
0.49% 0.54% libglib-2.0.so.0.6000.4 [.] g_mutex_lock
0.48% 0.62% [kernel] [k] _raw_spin_unlock_irqrestore
0.47% 0.27% [kernel] [k] __switch_to
0.47% 0.25% [kernel] [k] pick_next_task_fair
0.45% 0.17% [kernel] [k] filldir64
0.40% 0.16% [kernel] [k] update_rq_clock
0.39% 0.19% [kernel] [k] enqueue_task_fair
#

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-uw8cjeifxvjpkjp6x2iil0ar@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+26 -4
+26 -4
tools/perf/builtin-top.c
··· 264 264 pthread_mutex_unlock(&notes->lock); 265 265 } 266 266 267 + static void evlist__resort_hists(struct evlist *evlist) 268 + { 269 + struct evsel *pos; 270 + 271 + evlist__for_each_entry(evlist, pos) { 272 + struct hists *hists = evsel__hists(pos); 273 + 274 + hists__collapse_resort(hists, NULL); 275 + 276 + /* Non-group events are considered as leader */ 277 + if (symbol_conf.event_group && 278 + !perf_evsel__is_group_leader(pos)) { 279 + struct hists *leader_hists = evsel__hists(pos->leader); 280 + 281 + hists__match(leader_hists, hists); 282 + hists__link(leader_hists, hists); 283 + } 284 + } 285 + 286 + evlist__for_each_entry(evlist, pos) { 287 + perf_evsel__output_resort(pos, NULL); 288 + } 289 + } 290 + 267 291 static void perf_top__print_sym_table(struct perf_top *top) 268 292 { 269 293 char bf[160]; ··· 328 304 } 329 305 } 330 306 331 - hists__collapse_resort(hists, NULL); 332 - perf_evsel__output_resort(evsel, NULL); 307 + evlist__resort_hists(top->evlist); 333 308 334 309 hists__output_recalc_col_len(hists, top->print_entries - printed); 335 310 putchar('\n'); ··· 593 570 } 594 571 } 595 572 596 - hists__collapse_resort(hists, NULL); 597 - perf_evsel__output_resort(evsel, NULL); 573 + evlist__resort_hists(t->evlist); 598 574 599 575 if (t->lost || t->drop) 600 576 pr_warning("Too slow to read ring buffer (change period (-c/-F) or limit CPUs (-C)\n");