From: Artem Savkov <asavkov@redhat.com>
To: linux-perf-users@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
linux-kernel@vger.kernel.org, Artem Savkov <asavkov@redhat.com>
Subject: [PATCH v2 2/2] perf tools: allow running annotation browser from c2c-report
Date: Thu, 8 Jun 2023 10:44:07 +0200 [thread overview]
Message-ID: <20230608084407.140323-3-asavkov@redhat.com> (raw)
In-Reply-To: <20230608084407.140323-1-asavkov@redhat.com>
Add a shortcut to run annotation browser for selected symbol from
c2c report TUI.
Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
tools/perf/builtin-c2c.c | 73 +++++++++++++++++++++++++++++++++++++---
1 file changed, 68 insertions(+), 5 deletions(-)
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 05dfd98af170b..dce8604837aec 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -24,6 +24,7 @@
#include <perf/cpumap.h>
#include <subcmd/pager.h>
#include <subcmd/parse-options.h>
+#include "map.h"
#include "map_symbol.h"
#include "mem-events.h"
#include "session.h"
@@ -43,6 +44,8 @@
#include "ui/progress.h"
#include "pmus.h"
#include "string2.h"
+#include "util/annotate.h"
+#include "util/dso.h"
#include "util/util.h"
struct c2c_hists {
@@ -111,6 +114,9 @@ struct perf_c2c {
char *cl_sort;
char *cl_resort;
char *cl_output;
+
+ struct evlist *evlist;
+ struct annotation_options annotation_opts;
};
enum {
@@ -327,6 +333,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
c2c_he__set_node(c2c_he, sample);
hists__inc_nr_samples(&c2c_hists->hists, he->filtered);
+ if (use_browser == 1 && al.map != NULL && al.sym != NULL)
+ hist_entry__inc_addr_samples(he, sample, evsel, al.addr);
+
ret = hist_entry__append_callchain(he, sample);
if (!ret) {
@@ -364,6 +373,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
c2c_he__set_node(c2c_he, sample);
hists__inc_nr_samples(&c2c_hists->hists, he->filtered);
+ if (use_browser == 1 && al.map != NULL && al.sym != NULL)
+ hist_entry__inc_addr_samples(he, sample, evsel, al.addr);
+
ret = hist_entry__append_callchain(he, sample);
}
@@ -2612,6 +2624,43 @@ c2c_cacheline_browser__new(struct hists *hists, struct hist_entry *he)
return browser;
}
+static void do_annotate(struct hist_browser *browser, struct evsel *evsel) {
+ struct map_symbol ms = { NULL, NULL, NULL };
+
+ if (!browser->selection ||
+ !browser->selection->map ||
+ !browser->selection->map->dso ||
+ browser->selection->map->dso->annotate_warned) {
+ return;
+ }
+
+ ms.map = browser->selection->map;
+
+ if (!browser->selection->sym) {
+ if (!browser->he_selection)
+ return;
+
+ ms.sym = symbol__new_unresolved(browser->he_selection->ip,
+ browser->selection->map);
+
+ if (!ms.sym)
+ return;
+ } else {
+ if (symbol__annotation(browser->selection->sym)->src == NULL) {
+ ui_browser__warning(&browser->b, 0,
+ "No samples for the \"%s\" symbol.\n\n",
+ browser->selection->sym->name);
+ return;
+ }
+ ms.sym = browser->selection->sym;
+ }
+
+ map_symbol__tui_annotate(&ms, evsel, browser->hbt, &c2c.annotation_opts);
+
+ ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries);
+ ui_browser__handle_resize(&browser->b);
+}
+
static int perf_c2c__browse_cacheline(struct hist_entry *he)
{
struct c2c_hist_entry *c2c_he;
@@ -2621,6 +2670,7 @@ static int perf_c2c__browse_cacheline(struct hist_entry *he)
int key = -1;
static const char help[] =
" ENTER Toggle callchains (if present) \n"
+ " a Annotate current symbol\n"
" n Toggle Node details info \n"
" s Toggle full length of symbol and source line columns \n"
" q Return back to cacheline list \n";
@@ -2650,6 +2700,9 @@ static int perf_c2c__browse_cacheline(struct hist_entry *he)
key = hist_browser__run(browser, "? - help", true, 0);
switch (key) {
+ case 'a':
+ do_annotate(browser, evlist__first(c2c.evlist));
+ break;
case 's':
c2c.symbol_full = !c2c.symbol_full;
break;
@@ -3045,6 +3098,10 @@ static int perf_c2c__report(int argc, const char **argv)
int err = 0;
const char *output_str, *sort_str = NULL;
+ annotation_options__init(&c2c.annotation_opts);
+
+ hists__init();
+
argc = parse_options(argc, argv, options, report_c2c_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
if (argc)
@@ -3118,6 +3175,16 @@ static int perf_c2c__report(int argc, const char **argv)
if (err)
goto out_mem2node;
+ c2c.evlist = session->evlist;
+
+ if (c2c.use_stdio) {
+ use_browser = 0;
+ } else {
+ use_browser = 1;
+ symbol__annotation_init();
+ annotation_config__init(&c2c.annotation_opts);
+ }
+
if (symbol__init(&session->header.env) < 0)
goto out_mem2node;
@@ -3127,11 +3194,6 @@ static int perf_c2c__report(int argc, const char **argv)
goto out_mem2node;
}
- if (c2c.use_stdio)
- use_browser = 0;
- else
- use_browser = 1;
-
setup_browser(false);
err = perf_session__process_events(session);
@@ -3202,6 +3264,7 @@ static int perf_c2c__report(int argc, const char **argv)
out_session:
perf_session__delete(session);
out:
+ annotation_options__exit(&c2c.annotation_opts);
return err;
}
--
2.40.1
next prev parent reply other threads:[~2023-06-08 8:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-08 8:44 [PATCH v2 0/2] perf tools: annotation browser from c2c tui Artem Savkov
2023-06-08 8:44 ` [PATCH v2 1/2] perf util: move symbol__new_unresolved() to util/symbol.c Artem Savkov
2023-06-08 8:44 ` Artem Savkov [this message]
2023-06-08 13:25 ` [PATCH v2 0/2] perf tools: annotation browser from c2c tui Peter Zijlstra
2023-06-08 17:28 ` Namhyung Kim
2023-06-08 21:09 ` Namhyung Kim
2023-06-09 8:37 ` Artem Savkov
2023-06-14 18:38 ` Arnaldo Carvalho de Melo
2023-06-14 18:40 ` Arnaldo Carvalho de Melo
2023-06-19 7:15 ` Artem Savkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230608084407.140323-3-asavkov@redhat.com \
--to=asavkov@redhat.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).