[PATCH v4 6/9] perf annotate: Add 'T' hot key to toggle data type display

Namhyung Kim posted 9 patches 2 months, 1 week ago
There is a newer version of this series
[PATCH v4 6/9] perf annotate: Add 'T' hot key to toggle data type display
Posted by Namhyung Kim 2 months, 1 week ago
Support data type display with a key press so that users can toggle the
output dynamically on TUI.  Also display "[Type]" in the title line if
it's enabled.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/ui/browsers/annotate.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index cdee1969f3131a7c..4b059e0bafd33fcf 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -525,9 +525,10 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser)
 static int sym_title(struct symbol *sym, struct map *map, char *title,
 		     size_t sz, int percent_type)
 {
-	return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name,
+	return snprintf(title, sz, "%s  %s [Percent: %s] %s", sym->name,
 			dso__long_name(map__dso(map)),
-			percent_type_str(percent_type));
+			percent_type_str(percent_type),
+			annotate_opts.code_with_type ? "[Type]" : "");
 }
 
 /*
@@ -901,7 +902,8 @@ static int annotate_browser__run(struct annotate_browser *browser,
 		"b             Toggle percent base [period/hits]\n"
 		"B             Branch counter abbr list (Optional)\n"
 		"?             Search string backwards\n"
-		"f             Toggle showing offsets to full address\n");
+		"f             Toggle showing offsets to full address\n"
+		"T             Toggle data type display\n");
 			continue;
 		case 'r':
 			script_browse(NULL, NULL);
@@ -1021,6 +1023,12 @@ static int annotate_browser__run(struct annotate_browser *browser,
 		case 'f':
 			annotation__toggle_full_addr(notes, ms);
 			continue;
+		case 'T':
+			annotate_opts.code_with_type ^= 1;
+			if (browser->dbg == NULL)
+				browser->dbg = debuginfo__new(dso__long_name(map__dso(ms->map)));
+			annotate_browser__show(&browser->b, title, help);
+			continue;
 		case K_LEFT:
 		case '<':
 		case '>':
@@ -1115,8 +1123,7 @@ int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
 
 	ret = annotate_browser__run(&browser, evsel, hbt);
 
-	if (annotate_opts.code_with_type)
-		debuginfo__delete(browser.dbg);
+	debuginfo__delete(browser.dbg);
 	if (not_annotated && !notes->src->tried_source)
 		annotated_source__purge(notes->src);
 
-- 
2.50.1
Re: [PATCH v4 6/9] perf annotate: Add 'T' hot key to toggle data type display
Posted by Ian Rogers 2 months, 1 week ago
On Fri, Jul 25, 2025 at 12:38 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Support data type display with a key press so that users can toggle the
> output dynamically on TUI.  Also display "[Type]" in the title line if
> it's enabled.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/ui/browsers/annotate.c | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
> index cdee1969f3131a7c..4b059e0bafd33fcf 100644
> --- a/tools/perf/ui/browsers/annotate.c
> +++ b/tools/perf/ui/browsers/annotate.c
> @@ -525,9 +525,10 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser)
>  static int sym_title(struct symbol *sym, struct map *map, char *title,
>                      size_t sz, int percent_type)
>  {
> -       return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name,
> +       return snprintf(title, sz, "%s  %s [Percent: %s] %s", sym->name,
>                         dso__long_name(map__dso(map)),
> -                       percent_type_str(percent_type));
> +                       percent_type_str(percent_type),
> +                       annotate_opts.code_with_type ? "[Type]" : "");
>  }
>
>  /*
> @@ -901,7 +902,8 @@ static int annotate_browser__run(struct annotate_browser *browser,
>                 "b             Toggle percent base [period/hits]\n"
>                 "B             Branch counter abbr list (Optional)\n"
>                 "?             Search string backwards\n"
> -               "f             Toggle showing offsets to full address\n");
> +               "f             Toggle showing offsets to full address\n"
> +               "T             Toggle data type display\n");
>                         continue;
>                 case 'r':
>                         script_browse(NULL, NULL);
> @@ -1021,6 +1023,12 @@ static int annotate_browser__run(struct annotate_browser *browser,
>                 case 'f':
>                         annotation__toggle_full_addr(notes, ms);
>                         continue;
> +               case 'T':
> +                       annotate_opts.code_with_type ^= 1;
> +                       if (browser->dbg == NULL)
> +                               browser->dbg = debuginfo__new(dso__long_name(map__dso(ms->map)));

browser->dbg = dso__debuginfo(map__dso(ms->map));

There was a conversation about dso not necessarily having to have
long_name in the future, etc.

Thanks,
Ian

> +                       annotate_browser__show(&browser->b, title, help);
> +                       continue;
>                 case K_LEFT:
>                 case '<':
>                 case '>':
> @@ -1115,8 +1123,7 @@ int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
>
>         ret = annotate_browser__run(&browser, evsel, hbt);
>
> -       if (annotate_opts.code_with_type)
> -               debuginfo__delete(browser.dbg);
> +       debuginfo__delete(browser.dbg);
>         if (not_annotated && !notes->src->tried_source)
>                 annotated_source__purge(notes->src);
>
> --
> 2.50.1
>