[PATCH 5/6] perf report: Add a menu item to annotate data type in TUI

Namhyung Kim posted 6 patches 1 year, 10 months ago
[PATCH 5/6] perf report: Add a menu item to annotate data type in TUI
Posted by Namhyung Kim 1 year, 10 months ago
When the hist entry has the type info, it should be able to display the
annotation browser for the type like in `perf annotate --data-type`.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/builtin-report.c    |  5 +++++
 tools/perf/ui/browsers/hists.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index dcd93ee5fc24..aaa6427a1224 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1694,6 +1694,11 @@ int cmd_report(int argc, const char **argv)
 	else
 		use_browser = 0;
 
+	if (report.data_type && use_browser == 1) {
+		symbol_conf.annotate_data_member = true;
+		symbol_conf.annotate_data_sample = true;
+	}
+
 	if (sort_order && strstr(sort_order, "ipc")) {
 		parse_options_usage(report_usage, options, "s", 1);
 		goto error;
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 0c02b3a8e121..71b32591d61a 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -38,6 +38,7 @@
 #include "../ui.h"
 #include "map.h"
 #include "annotate.h"
+#include "annotate-data.h"
 #include "srcline.h"
 #include "string2.h"
 #include "units.h"
@@ -2505,6 +2506,32 @@ add_annotate_opt(struct hist_browser *browser __maybe_unused,
 	return 1;
 }
 
+static int
+do_annotate_type(struct hist_browser *browser, struct popup_action *act)
+{
+	struct hist_entry *he = browser->he_selection;
+
+	hist_entry__annotate_data_tui(he, act->evsel, browser->hbt);
+	ui_browser__handle_resize(&browser->b);
+	return 0;
+}
+
+static int
+add_annotate_type_opt(struct hist_browser *browser,
+		      struct popup_action *act, char **optstr,
+		      struct hist_entry *he)
+{
+	if (he == NULL || he->mem_type == NULL || he->mem_type->histograms == NULL)
+		return 0;
+
+	if (asprintf(optstr, "Annotate type %s", he->mem_type->self.type_name) < 0)
+		return 0;
+
+	act->evsel = hists_to_evsel(browser->hists);
+	act->fn = do_annotate_type;
+	return 1;
+}
+
 static int
 do_zoom_thread(struct hist_browser *browser, struct popup_action *act)
 {
@@ -3307,6 +3334,10 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
 						       browser->he_selection->ip);
 		}
 skip_annotation:
+		nr_options += add_annotate_type_opt(browser,
+						    &actions[nr_options],
+						    &options[nr_options],
+						    browser->he_selection);
 		nr_options += add_thread_opt(browser, &actions[nr_options],
 					     &options[nr_options], thread);
 		nr_options += add_dso_opt(browser, &actions[nr_options],
-- 
2.44.0.478.gd926399ef9-goog
Re: [PATCH 5/6] perf report: Add a menu item to annotate data type in TUI
Posted by Arnaldo Carvalho de Melo 1 year, 10 months ago
On Tue, Apr 09, 2024 at 04:49:59PM -0700, Namhyung Kim wrote:
> When the hist entry has the type info, it should be able to display the
> annotation browser for the type like in `perf annotate --data-type`.

Trying to test this with:

root@number:~# perf report --header-only |& grep "perf record"
# cmdline : /home/acme/bin/perf record -a -e {cpu_core/mem-loads,ldlat=30/P,cpu_core/mem-stores/P} 
root@number:~# perf evlist -v
cpu_core/mem-loads,ldlat=30/P: type: 4 (cpu_core), size: 136, config: 0x1cd (mem-loads), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD|IDENTIFIER, read_format: ID|LOST, disabled: 1, inherit: 1, freq: 1, precise_ip: 2, sample_id_all: 1, { bp_addr, config1 }: 0x1f
cpu_core/mem-stores/P: type: 4 (cpu_core), size: 136, config: 0x2cd (mem-stores), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD|IDENTIFIER, read_format: ID|LOST, inherit: 1, freq: 1, precise_ip: 3, sample_id_all: 1
dummy:u: type: 1 (software), size: 136, config: 0x9 (PERF_COUNT_SW_DUMMY), { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|CPU|IDENTIFIER, read_format: ID|LOST, inherit: 1, exclude_kernel: 1, exclude_hv: 1, mmap: 1, comm: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1
root@number:~# perf report -s type

And when I press ESC to exit:

root@number:~# perf report -s type
perf: Segmentation fault
-------- backtrace --------
perf[0x61326b]
/lib64/libc.so.6(+0x3e9a0)[0x7f7173a5c9a0]
/lib64/libc.so.6(free+0x25)[0x7f7173abd385]
perf[0x5d5002]
perf[0x4fd007]
perf[0x523ce0]
perf[0x525ad4]
perf[0x503f43]
perf[0x557ad4]
perf[0x557eeb]
perf[0x4e5355]
perf[0x4dea42]
perf[0x528aad]
perf[0x42b559]
perf[0x4c39e9]
perf[0x4c3cf9]
perf[0x410e47]
/lib64/libc.so.6(+0x2814a)[0x7f7173a4614a]
/lib64/libc.so.6(__libc_start_main+0x8b)[0x7f7173a4620b]
perf[0x4113e5]
root@number:~#

Trying to build with debug info...

- Arnaldo
 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/builtin-report.c    |  5 +++++
>  tools/perf/ui/browsers/hists.c | 31 +++++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> index dcd93ee5fc24..aaa6427a1224 100644
> --- a/tools/perf/builtin-report.c
> +++ b/tools/perf/builtin-report.c
> @@ -1694,6 +1694,11 @@ int cmd_report(int argc, const char **argv)
>  	else
>  		use_browser = 0;
>  
> +	if (report.data_type && use_browser == 1) {
> +		symbol_conf.annotate_data_member = true;
> +		symbol_conf.annotate_data_sample = true;
> +	}
> +
>  	if (sort_order && strstr(sort_order, "ipc")) {
>  		parse_options_usage(report_usage, options, "s", 1);
>  		goto error;
> diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
> index 0c02b3a8e121..71b32591d61a 100644
> --- a/tools/perf/ui/browsers/hists.c
> +++ b/tools/perf/ui/browsers/hists.c
> @@ -38,6 +38,7 @@
>  #include "../ui.h"
>  #include "map.h"
>  #include "annotate.h"
> +#include "annotate-data.h"
>  #include "srcline.h"
>  #include "string2.h"
>  #include "units.h"
> @@ -2505,6 +2506,32 @@ add_annotate_opt(struct hist_browser *browser __maybe_unused,
>  	return 1;
>  }
>  
> +static int
> +do_annotate_type(struct hist_browser *browser, struct popup_action *act)
> +{
> +	struct hist_entry *he = browser->he_selection;
> +
> +	hist_entry__annotate_data_tui(he, act->evsel, browser->hbt);
> +	ui_browser__handle_resize(&browser->b);
> +	return 0;
> +}
> +
> +static int
> +add_annotate_type_opt(struct hist_browser *browser,
> +		      struct popup_action *act, char **optstr,
> +		      struct hist_entry *he)
> +{
> +	if (he == NULL || he->mem_type == NULL || he->mem_type->histograms == NULL)
> +		return 0;
> +
> +	if (asprintf(optstr, "Annotate type %s", he->mem_type->self.type_name) < 0)
> +		return 0;
> +
> +	act->evsel = hists_to_evsel(browser->hists);
> +	act->fn = do_annotate_type;
> +	return 1;
> +}
> +
>  static int
>  do_zoom_thread(struct hist_browser *browser, struct popup_action *act)
>  {
> @@ -3307,6 +3334,10 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
>  						       browser->he_selection->ip);
>  		}
>  skip_annotation:
> +		nr_options += add_annotate_type_opt(browser,
> +						    &actions[nr_options],
> +						    &options[nr_options],
> +						    browser->he_selection);
>  		nr_options += add_thread_opt(browser, &actions[nr_options],
>  					     &options[nr_options], thread);
>  		nr_options += add_dso_opt(browser, &actions[nr_options],
> -- 
> 2.44.0.478.gd926399ef9-goog
Re: [PATCH 5/6] perf report: Add a menu item to annotate data type in TUI
Posted by Arnaldo Carvalho de Melo 1 year, 10 months ago
On Wed, Apr 10, 2024 at 05:46:04PM -0300, Arnaldo Carvalho de Melo wrote:
> On Tue, Apr 09, 2024 at 04:49:59PM -0700, Namhyung Kim wrote:
> > When the hist entry has the type info, it should be able to display the
> > annotation browser for the type like in `perf annotate --data-type`.
> 
> Trying to test this with:
> 
> root@number:~# perf report --header-only |& grep "perf record"
> # cmdline : /home/acme/bin/perf record -a -e {cpu_core/mem-loads,ldlat=30/P,cpu_core/mem-stores/P} 
> root@number:~# perf evlist -v
> cpu_core/mem-loads,ldlat=30/P: type: 4 (cpu_core), size: 136, config: 0x1cd (mem-loads), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD|IDENTIFIER, read_format: ID|LOST, disabled: 1, inherit: 1, freq: 1, precise_ip: 2, sample_id_all: 1, { bp_addr, config1 }: 0x1f
> cpu_core/mem-stores/P: type: 4 (cpu_core), size: 136, config: 0x2cd (mem-stores), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD|IDENTIFIER, read_format: ID|LOST, inherit: 1, freq: 1, precise_ip: 3, sample_id_all: 1
> dummy:u: type: 1 (software), size: 136, config: 0x9 (PERF_COUNT_SW_DUMMY), { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|CPU|IDENTIFIER, read_format: ID|LOST, inherit: 1, exclude_kernel: 1, exclude_hv: 1, mmap: 1, comm: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1
> root@number:~# perf report -s type
> 
> And when I press ESC to exit:
> 
> root@number:~# perf report -s type
> perf: Segmentation fault
> -------- backtrace --------
> perf[0x61326b]
> /lib64/libc.so.6(+0x3e9a0)[0x7f7173a5c9a0]
> /lib64/libc.so.6(free+0x25)[0x7f7173abd385]
> perf[0x5d5002]
> perf[0x4fd007]
> perf[0x523ce0]
> perf[0x525ad4]
> perf[0x503f43]
> perf[0x557ad4]
> perf[0x557eeb]
> perf[0x4e5355]
> perf[0x4dea42]
> perf[0x528aad]
> perf[0x42b559]
> perf[0x4c39e9]
> perf[0x4c3cf9]
> perf[0x410e47]
> /lib64/libc.so.6(+0x2814a)[0x7f7173a4614a]
> /lib64/libc.so.6(__libc_start_main+0x8b)[0x7f7173a4620b]
> perf[0x4113e5]
> root@number:~#
> 
> Trying to build with debug info...

Removing the O= dir and then trying with:

⬢[acme@toolbox perf-tools-next]$ alias m
alias m='rm -rf ~/libexec/perf-core/ ; make -k DEBUG=1 CORESIGHT=1 O=/tmp/build/$(basename $PWD)/ -C tools/perf install-bin && perf test python'
⬢[acme@toolbox perf-tools-next]$

I don't get a backtrace :-\ Ooops, sometimes I get it, but again without
resolving symbols:

root@number:~# perf report -s type
perf: Segmentation fault
-------- backtrace --------
perf[0x6b1087]
/lib64/libc.so.6(+0x3e9a0)[0x7fc15fa5c9a0]
/lib64/libc.so.6(free+0x25)[0x7fc15fabd385]
perf[0x66c2c0]
perf[0x66c363]
perf[0x553bc5]
perf[0x553d63]
perf[0x57ed76]
perf[0x58027e]
perf[0x5802bc]
perf[0x580325]
perf[0x5818aa]
perf[0x582241]
perf[0x58233c]
perf[0x5823fd]
perf[0x55c4ca]
perf[0x55c55f]
perf[0x5c36bf]
perf[0x5c1049]
perf[0x5c1197]
perf[0x5c7a4d]
perf[0x5c7ac7]
perf[0x531928]
perf[0x53196d]
perf[0x526a70]
perf[0x526b7d]
perf[0x585fd8]
perf[0x434503]
perf[0x5062c3]
perf[0x506532]
perf[0x506681]
perf[0x506978]
root@number:~#

Will try with gdb:

Lots of forks:

┌Merging related events...────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                 [  [                     from child process 2278982]                                                                                                        │
[Detaching after fork from child process 2278983]─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
[Detaching after fork from child process 2278984]
[Detaching after fork from child process 2278985]
[Detaching after fork from child process 2278986]
[Detaching after fork from child process 2278987]
[Detaching after fork from child process 2278988]
[Detaching after fork from child process 2278989]



                                                                                 ┌───────────────────────────┐                                                                                ▒
                                                                                 │Do you really want to exit?│                                                                                ▒
                                                                                 │                           │                                                                                ▒
                                                                                 │Enter: Yes, ESC: No        │                                                                                ▒
                                                                                 └───────────────────────────Program received signal SIGSEGV, Segmentation fault.                             ▒
                                                                                                                                                                 0x00007ffff6ebd385 in __GI___libc_free (mem=0x69647225202c3866) at malloc.c:3368                                                                                                                                            ▒
Downloading source file /usr/src/debug/glibc-2.38-17.fc39.x86_64/malloc/malloc.c                                                                                                              ▒
3368      if (chunk_is_mmapped (p))                       /* release mmapped memory. */                                                                                                        
(gdb) 

and:

(gdb) bt
#0  0x00007ffff6ebd385 in __GI___libc_free (mem=0x69647225202c3866) at malloc.c:3368                                                                                                          ▒
#1  0x000000000066c2c0 in delete_data_type_histograms (adt=0x8dedf0c0) at util/annotate-data.c:1655                                                                                           ▒
#2  0x000000000066c363 in annotated_data_type__tree_delete (root=0xe6bc68) at util/annotate-data.c:1669                                                                                       ▒
#3  0x0000000000553bc5 in dso__delete (dso=0xe6bbd0) at util/dso.c:1376                                                                                                                       ▒
#4  0x0000000000553d63 in dso__put (dso=0xe6bbd0) at util/dso.c:1409                                                                                                                          ▒
#5  0x000000000057ed76 in __dso__zput (dso=0xf5b540) at util/dso.h:262                                                                                                                        ▒
#6  0x000000000058027e in map__exit (map=0xf5b520) at util/map.c:300                                                                                                                          ▒
#7  0x00000000005802bc in map__delete (map=0xf5b520) at util/map.c:305cord -b ... ; perf report --total-cycles                                                                                ▒
#8  0x0000000000580325 in map__put (map=0xf5b520) at util/map.c:312
#9  0x00000000005818aa in __map__zput (map=0xf3e300) at util/map.h:196
#10 0x0000000000582241 in maps__exit (maps=0xf5aee0) at util/maps.c:246
#11 0x000000000058233c in maps__delete (maps=0xf5aee0) at util/maps.c:268
#12 0x00000000005823fd in maps__put (maps=0xf5aee0) at util/maps.c:285
#13 0x000000000055c4ca in __maps__zput (map=0x47856d8) at util/maps.h:32
#14 0x000000000055c55f in map_symbol__exit (ms=0x47856d8) at util/map_symbol.c:8
#15 0x00000000005c36bf in hist_entry__delete (he=0x4785660) at util/hist.c:1319
#16 0x00000000005c1049 in hists__delete_entry (hists=0xe68fe0, he=0x4785660) at util/hist.c:382
#17 0x00000000005c1197 in hists__delete_entries (hists=0xe68fe0) at util/hist.c:410
#18 0x00000000005c7a4d in hists__delete_all_entries (hists=0xe68fe0) at util/hist.c:2872
#19 0x00000000005c7ac7 in hists_evsel__exit (evsel=0xe68d70) at util/hist.c:2884
#20 0x0000000000531928 in evsel__exit (evsel=0xe68d70) at util/evsel.c:1489
#21 0x000000000053196d in evsel__delete (evsel=0xe68d70) at util/evsel.c:1497
#22 0x0000000000526a70 in evlist__purge (evlist=0xe67a00) at util/evlist.c:163
#23 0x0000000000526b7d in evlist__delete (evlist=0xe67a00) at util/evlist.c:185
#24 0x0000000000585fd8 in perf_session__delete (session=0xe670a0) at util/session.c:313
#25 0x0000000000434503 in cmd_report (argc=0, argv=0x7fffffffe430) at builtin-report.c:1828
#26 0x00000000005062c3 in run_builtin (p=0xe3f160 <commands+288>, argc=3, argv=0x7fffffffe430) at perf.c:350
#27 0x0000000000506532 in handle_internal_command (argc=3, argv=0x7fffffffe430) at perf.c:403
#28 0x0000000000506681 in run_argv (argcp=0x7fffffffe21c, argv=0x7fffffffe210) at perf.c:447
#29 0x0000000000506978 in main (argc=3, argv=0x7fffffffe430) at perf.c:561
(gdb) 

Continuing...
Re: [PATCH 5/6] perf report: Add a menu item to annotate data type in TUI
Posted by Namhyung Kim 1 year, 10 months ago
On Wed, Apr 10, 2024 at 1:50 PM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
> (gdb) bt
> #0  0x00007ffff6ebd385 in __GI___libc_free (mem=0x69647225202c3866) at malloc.c:3368                                                                                                          ▒
> #1  0x000000000066c2c0 in delete_data_type_histograms (adt=0x8dedf0c0) at util/annotate-data.c:1655                                                                                           ▒
> #2  0x000000000066c363 in annotated_data_type__tree_delete (root=0xe6bc68) at util/annotate-data.c:1669                                                                                       ▒
> #3  0x0000000000553bc5 in dso__delete (dso=0xe6bbd0) at util/dso.c:1376                                                                                                                       ▒
> #4  0x0000000000553d63 in dso__put (dso=0xe6bbd0) at util/dso.c:1409                                                                                                                          ▒
> #5  0x000000000057ed76 in __dso__zput (dso=0xf5b540) at util/dso.h:262                                                                                                                        ▒
> #6  0x000000000058027e in map__exit (map=0xf5b520) at util/map.c:300                                                                                                                          ▒
> #7  0x00000000005802bc in map__delete (map=0xf5b520) at util/map.c:305cord -b ... ; perf report --total-cycles                                                                                ▒
> #8  0x0000000000580325 in map__put (map=0xf5b520) at util/map.c:312
> #9  0x00000000005818aa in __map__zput (map=0xf3e300) at util/map.h:196
> #10 0x0000000000582241 in maps__exit (maps=0xf5aee0) at util/maps.c:246
> #11 0x000000000058233c in maps__delete (maps=0xf5aee0) at util/maps.c:268
> #12 0x00000000005823fd in maps__put (maps=0xf5aee0) at util/maps.c:285
> #13 0x000000000055c4ca in __maps__zput (map=0x47856d8) at util/maps.h:32
> #14 0x000000000055c55f in map_symbol__exit (ms=0x47856d8) at util/map_symbol.c:8
> #15 0x00000000005c36bf in hist_entry__delete (he=0x4785660) at util/hist.c:1319
> #16 0x00000000005c1049 in hists__delete_entry (hists=0xe68fe0, he=0x4785660) at util/hist.c:382
> #17 0x00000000005c1197 in hists__delete_entries (hists=0xe68fe0) at util/hist.c:410
> #18 0x00000000005c7a4d in hists__delete_all_entries (hists=0xe68fe0) at util/hist.c:2872
> #19 0x00000000005c7ac7 in hists_evsel__exit (evsel=0xe68d70) at util/hist.c:2884
> #20 0x0000000000531928 in evsel__exit (evsel=0xe68d70) at util/evsel.c:1489
> #21 0x000000000053196d in evsel__delete (evsel=0xe68d70) at util/evsel.c:1497
> #22 0x0000000000526a70 in evlist__purge (evlist=0xe67a00) at util/evlist.c:163
> #23 0x0000000000526b7d in evlist__delete (evlist=0xe67a00) at util/evlist.c:185
> #24 0x0000000000585fd8 in perf_session__delete (session=0xe670a0) at util/session.c:313
> #25 0x0000000000434503 in cmd_report (argc=0, argv=0x7fffffffe430) at builtin-report.c:1828
> #26 0x00000000005062c3 in run_builtin (p=0xe3f160 <commands+288>, argc=3, argv=0x7fffffffe430) at perf.c:350
> #27 0x0000000000506532 in handle_internal_command (argc=3, argv=0x7fffffffe430) at perf.c:403
> #28 0x0000000000506681 in run_argv (argcp=0x7fffffffe21c, argv=0x7fffffffe210) at perf.c:447
> #29 0x0000000000506978 in main (argc=3, argv=0x7fffffffe430) at perf.c:561
> (gdb)
>

Thanks for the report.  I think I missed stack canary not handling
histogram updates.  The data file I tested with TUI didn't have an
entry for stack canary so I didn't catch this.  For some reason, I
still cannot reproduce it on my box.  Anyway I will fix in v2.

For the verification, it'd be nice if you can print the type name
in the delete_data_type__histogram().

  (gdb) p adt->self.type_name


Thanks,
Namhyung