]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf annotate: Rename to __hist_entry__tui_annotate()
authorNamhyung Kim <namhyung@kernel.org>
Sat, 16 Aug 2025 03:16:24 +0000 (20:16 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 28 Aug 2025 15:30:57 +0000 (12:30 -0300)
There are three different but similar functions for annotation on TUI.
Rename it to __hist_entry__tui_annotate() and make sure it passes 'he'.
It's not used for now but it'll be needed for later use.

Also remove map_symbol__tui_annotate() which was a simple wrapper.

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250816031635.25318-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/ui/browsers/annotate.c
tools/perf/ui/browsers/hists.c
tools/perf/util/annotate.h
tools/perf/util/hist.h

index 183902dac042ecb0f0ac4588f70398add14f3844..4d5cbb86cbb6d50657b186b64a6188135225661f 100644 (file)
@@ -12,6 +12,7 @@
 #include "../../util/symbol.h"
 #include "../../util/evsel.h"
 #include "../../util/evlist.h"
+#include "../../util/thread.h"
 #include <inttypes.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
@@ -27,10 +28,18 @@ struct annotate_browser {
        struct rb_node             *curr_hot;
        struct annotation_line     *selection;
        struct arch                *arch;
+       /*
+        * perf top can delete hist_entry anytime.  Callers should make sure
+        * its lifetime.
+        */
+       struct hist_entry          *he;
        bool                        searching_backwards;
        char                        search_bf[128];
 };
 
+/* A copy of target hist_entry for perf top. */
+static struct hist_entry annotate_he;
+
 static inline struct annotation *browser__annotation(struct ui_browser *browser)
 {
        struct map_symbol *ms = browser->priv;
@@ -557,7 +566,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser,
        target_ms.map = ms->map;
        target_ms.sym = dl->ops.target.sym;
        annotation__unlock(notes);
-       symbol__tui_annotate(&target_ms, evsel, hbt);
+       __hist_entry__tui_annotate(browser->he, &target_ms, evsel, hbt);
        sym_title(ms->sym, ms->map, title, sizeof(title), annotate_opts.percent_type);
        ui_browser__show_title(&browser->b, title);
        return true;
@@ -1032,12 +1041,6 @@ out:
        return key;
 }
 
-int map_symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
-                            struct hist_browser_timer *hbt)
-{
-       return symbol__tui_annotate(ms, evsel, hbt);
-}
-
 int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel,
                             struct hist_browser_timer *hbt)
 {
@@ -1046,11 +1049,12 @@ int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel,
        SLang_init_tty(0, 0, 0);
        SLtty_set_suspend_state(true);
 
-       return map_symbol__tui_annotate(&he->ms, evsel, hbt);
+       return __hist_entry__tui_annotate(he, &he->ms, evsel, hbt);
 }
 
-int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
-                        struct hist_browser_timer *hbt)
+int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
+                              struct evsel *evsel,
+                              struct hist_browser_timer *hbt)
 {
        struct symbol *sym = ms->sym;
        struct annotation *notes = symbol__annotation(sym);
@@ -1064,6 +1068,7 @@ int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
                        .priv    = ms,
                        .use_navkeypressed = true,
                },
+               .he = he,
        };
        struct dso *dso;
        int ret = -1, err;
@@ -1093,6 +1098,16 @@ int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
                }
        }
 
+       /* Copy necessary information when it's called from perf top */
+       if (hbt != NULL && he != &annotate_he) {
+               annotate_he.hists = he->hists;
+               annotate_he.thread = thread__get(he->thread);
+               annotate_he.cpumode = he->cpumode;
+               map_symbol__copy(&annotate_he.ms, ms);
+
+               browser.he = &annotate_he;
+       }
+
        ui_helpline__push("Press ESC to exit");
 
        browser.b.width = notes->src->widths.max_line_len;
@@ -1108,5 +1123,10 @@ int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
        if (not_annotated && !notes->src->tried_source)
                annotated_source__purge(notes->src);
 
+       if (hbt != NULL && he != &annotate_he) {
+               thread__zput(annotate_he.thread);
+               map_symbol__exit(&annotate_he.ms);
+       }
+
        return ret;
 }
index d9d3fb44477ac6d5d7108a663f21bab760c01613..487c0b08c00387106817e1864015fd88f361d95a 100644 (file)
@@ -2484,8 +2484,8 @@ do_annotate(struct hist_browser *browser, struct popup_action *act)
        else
                evsel = hists_to_evsel(browser->hists);
 
-       err = map_symbol__tui_annotate(&act->ms, evsel, browser->hbt);
        he = hist_browser__selected_entry(browser);
+       err = __hist_entry__tui_annotate(he, &act->ms, evsel, browser->hbt);
        /*
         * offer option to annotate the other branch source or target
         * (if they exists) when returning from annotate
index 8b5131d257b01e3e8ae2c589c6e78870b1f9b0d8..0f640e487174426279033fc56ce390f3d5f7268d 100644 (file)
@@ -471,18 +471,6 @@ int hist_entry__annotate_printf(struct hist_entry *he, struct evsel *evsel);
 int hist_entry__tty_annotate(struct hist_entry *he, struct evsel *evsel);
 int hist_entry__tty_annotate2(struct hist_entry *he, struct evsel *evsel);
 
-#ifdef HAVE_SLANG_SUPPORT
-int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
-                        struct hist_browser_timer *hbt);
-#else
-static inline int symbol__tui_annotate(struct map_symbol *ms __maybe_unused,
-                               struct evsel *evsel  __maybe_unused,
-                               struct hist_browser_timer *hbt __maybe_unused)
-{
-       return 0;
-}
-#endif
-
 void annotation_options__init(void);
 void annotation_options__exit(void);
 
index 70438d03ca9c33b180948611daec1084ea1b34ac..c64005278687cb02ecd4628f4c2914ee4fe3fb46 100644 (file)
@@ -713,8 +713,9 @@ struct block_hist {
 #include "../ui/keysyms.h"
 void attr_to_script(char *buf, struct perf_event_attr *attr);
 
-int map_symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
-                            struct hist_browser_timer *hbt);
+int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
+                              struct evsel *evsel,
+                              struct hist_browser_timer *hbt);
 
 int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel,
                             struct hist_browser_timer *hbt);
@@ -742,9 +743,10 @@ int evlist__tui_browse_hists(struct evlist *evlist __maybe_unused,
 {
        return 0;
 }
-static inline int map_symbol__tui_annotate(struct map_symbol *ms __maybe_unused,
-                                          struct evsel *evsel __maybe_unused,
-                                          struct hist_browser_timer *hbt __maybe_unused)
+static inline int __hist_entry__tui_annotate(struct hist_entry *he __maybe_unused,
+                                            struct map_symbol *ms __maybe_unused,
+                                            struct evsel *evsel __maybe_unused,
+                                            struct hist_browser_timer *hbt __maybe_unused)
 {
        return 0;
 }