From nobody Mon Oct 20 05:38:07 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2202FC7EE2F for ; Wed, 31 May 2023 11:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235594AbjEaLvQ (ORCPT ); Wed, 31 May 2023 07:51:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232018AbjEaLvO (ORCPT ); Wed, 31 May 2023 07:51:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C978110F for ; Wed, 31 May 2023 04:50:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685533835; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3gAyEuwafL/hxITBiKfoUbav1sLZb6lLFuGPfJnHhTI=; b=La+VGW3XaDAx+GTIBX2pBZ6KK6y/ui2DZUH9+HZLEx6yuIoNRXvDCORistDpMi3VuahAin jqf+7LdcY0sF2vTz59r51P1sr64eWIsxzD4ZGCUQmxhl0lhbFN4tYD2bl1rJNORLLPrha3 lV+bb7JLLLoqcp71PZgMIYwkfSlju7Y= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-627-rQSyLs64O4KvHgBcbeP99w-1; Wed, 31 May 2023 07:50:31 -0400 X-MC-Unique: rQSyLs64O4KvHgBcbeP99w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0E099811E8E; Wed, 31 May 2023 11:50:31 +0000 (UTC) Received: from samus.usersys.redhat.com (unknown [10.43.17.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 728AB40CFD45; Wed, 31 May 2023 11:50:29 +0000 (UTC) From: Artem Savkov To: linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-kernel@vger.kernel.org, Artem Savkov Subject: [PATCH 1/2] perf util: move symbol__new_unresolved() to util/symbol.c Date: Wed, 31 May 2023 13:50:13 +0200 Message-Id: <20230531115014.161454-2-asavkov@redhat.com> In-Reply-To: <20230531115014.161454-1-asavkov@redhat.com> References: <20230531115014.161454-1-asavkov@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Make symbol__new_unresolved() available through util/symbol.h so it can be later used from builtin-c2c. Signed-off-by: Artem Savkov --- tools/perf/ui/browsers/hists.c | 22 ---------------------- tools/perf/util/symbol.c | 22 ++++++++++++++++++++++ tools/perf/util/symbol.h | 1 + 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 69c81759a64f9..10d2243d27504 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -2471,28 +2471,6 @@ do_annotate(struct hist_browser *browser, struct pop= up_action *act) return 0; } =20 -static struct symbol *symbol__new_unresolved(u64 addr, struct map *map) -{ - struct annotated_source *src; - struct symbol *sym; - char name[64]; - - snprintf(name, sizeof(name), "%.*" PRIx64, BITS_PER_LONG / 4, addr); - - sym =3D symbol__new(addr, ANNOTATION_DUMMY_LEN, 0, 0, name); - if (sym) { - src =3D symbol__hists(sym, 1); - if (!src) { - symbol__delete(sym); - return NULL; - } - - dso__insert_symbol(map__dso(map), sym); - } - - return sym; -} - static int add_annotate_opt(struct hist_browser *browser __maybe_unused, struct popup_action *act, char **optstr, diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 6b9c55784b56a..297a903f72777 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -294,6 +294,28 @@ void maps__fixup_end(struct maps *maps) up_write(maps__lock(maps)); } =20 +struct symbol *symbol__new_unresolved(u64 addr, struct map *map) +{ + struct annotated_source *src; + struct symbol *sym; + char name[64]; + + snprintf(name, sizeof(name), "%.*" PRIx64, BITS_PER_LONG / 4, addr); + + sym =3D symbol__new(addr, ANNOTATION_DUMMY_LEN, 0, 0, name); + if (sym) { + src =3D symbol__hists(sym, 1); + if (!src) { + symbol__delete(sym); + return NULL; + } + + dso__insert_symbol(map__dso(map), sym); + } + + return sym; +} + struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const = char *name) { size_t namelen =3D strlen(name) + 1; diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 7558735543c25..4d47748716627 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -176,6 +176,7 @@ void symbol__exit(void); void symbol__elf_init(void); int symbol__annotation_init(void); =20 +struct symbol *symbol__new_unresolved(u64 addr, struct map *map); struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const = char *name); size_t __symbol__fprintf_symname_offs(const struct symbol *sym, const struct addr_location *al, --=20 2.40.1 From nobody Mon Oct 20 05:38:07 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 779B9C77B73 for ; Wed, 31 May 2023 11:51:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235759AbjEaLv1 (ORCPT ); Wed, 31 May 2023 07:51:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235311AbjEaLvQ (ORCPT ); Wed, 31 May 2023 07:51:16 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 603B810B for ; Wed, 31 May 2023 04:50:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685533834; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=25yV48GzrN5JRrbcRZVzMDMeJIhkLtz0P43vLbvVHR0=; b=AyHnH6TzWO6Mrkl78DDF+rL4gHLC8kDnQub3GANaGtUwAtkuTq9xsvWJI7ukuKFq+cV0EX Jq7sc3MqcP3kKdZU+gE9JuODFxMFcqaIEzXIRGAGDdmRzs6wWC8ofhGtWHljt4o4HU4rp8 EjeE+REL+I4BufAe24iAO1CZCYVD3uY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-cgkqOGKTMNS5dIdK6VMiuQ-1; Wed, 31 May 2023 07:50:33 -0400 X-MC-Unique: cgkqOGKTMNS5dIdK6VMiuQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D812E3C0CEF7; Wed, 31 May 2023 11:50:32 +0000 (UTC) Received: from samus.usersys.redhat.com (unknown [10.43.17.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 475D840CFD45; Wed, 31 May 2023 11:50:31 +0000 (UTC) From: Artem Savkov To: linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-kernel@vger.kernel.org, Artem Savkov Subject: [PATCH 2/2] perf tools: allow running annotation browser from c2c-report Date: Wed, 31 May 2023 13:50:14 +0200 Message-Id: <20230531115014.161454-3-asavkov@redhat.com> In-Reply-To: <20230531115014.161454-1-asavkov@redhat.com> References: <20230531115014.161454-1-asavkov@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a shortcut to run annotation browser for selected symbol from c2c report TUI. Signed-off-by: Artem Savkov --- tools/perf/builtin-c2c.c | 76 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 05dfd98af170b..96e66289c2576 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -19,11 +19,13 @@ #include #include #include +#include #include "debug.h" #include "builtin.h" #include #include #include +#include "map.h" #include "map_symbol.h" #include "mem-events.h" #include "session.h" @@ -43,6 +45,8 @@ #include "ui/progress.h" #include "pmus.h" #include "string2.h" +#include "util/annotate.h" +#include "util/dso.h" #include "util/util.h" =20 struct c2c_hists { @@ -79,6 +83,7 @@ struct c2c_hist_entry { * because of its callchain dynamic entry */ struct hist_entry he; + struct evsel *evsel; }; =20 static char const *coalesce_default =3D "iaddr"; @@ -111,6 +116,8 @@ struct perf_c2c { char *cl_sort; char *cl_resort; char *cl_output; + + struct annotation_options annotation_opts; }; =20 enum { @@ -326,7 +333,12 @@ static int process_sample_event(struct perf_tool *tool= __maybe_unused, c2c_he__set_cpu(c2c_he, sample); c2c_he__set_node(c2c_he, sample); =20 + c2c_he->evsel =3D evsel; + hists__inc_nr_samples(&c2c_hists->hists, he->filtered); + if (use_browser =3D=3D 1 && al.map !=3D NULL && al.sym !=3D NULL) { + hist_entry__inc_addr_samples(he, sample, c2c_he->evsel, al.addr); + } ret =3D hist_entry__append_callchain(he, sample); =20 if (!ret) { @@ -363,7 +375,12 @@ static int process_sample_event(struct perf_tool *tool= __maybe_unused, c2c_he__set_cpu(c2c_he, sample); c2c_he__set_node(c2c_he, sample); =20 + c2c_he->evsel =3D evsel; + hists__inc_nr_samples(&c2c_hists->hists, he->filtered); + if (use_browser =3D=3D 1 && al.map !=3D NULL && al.sym !=3D NULL) { + hist_entry__inc_addr_samples(he, sample, c2c_he->evsel, al.addr); + } ret =3D hist_entry__append_callchain(he, sample); } =20 @@ -2618,9 +2635,12 @@ static int perf_c2c__browse_cacheline(struct hist_en= try *he) struct c2c_hists *c2c_hists; struct c2c_cacheline_browser *cl_browser; struct hist_browser *browser; + struct map_symbol ms =3D { NULL, NULL, NULL }; + int err =3D 0; int key =3D -1; static const char help[] =3D " 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 +2670,44 @@ static int perf_c2c__browse_cacheline(struct hist_en= try *he) key =3D hist_browser__run(browser, "? - help", true, 0); =20 switch (key) { + case 'a': + if (!browser->selection || + !browser->selection->map || + !browser->selection->map->dso || + browser->selection->map->dso->annotate_warned) { + continue; + } + + ms.map =3D browser->selection->map; + + if (!browser->selection->sym) { + if (!browser->he_selection) + continue; + + ms.sym =3D symbol__new_unresolved(browser->he_selection->ip, + browser->selection->map); + + if (!ms.sym) + continue; + } else { + if (symbol__annotation(browser->selection->sym)->src =3D=3D NULL) { + ui_browser__warning(&browser->b, 0, + "No samples for the \"%s\" symbol.\n\n", + browser->selection->sym->name); + continue; + } + ms.sym =3D browser->selection->sym; + } + + err =3D map_symbol__tui_annotate(&ms, c2c_he->evsel, browser->hbt, &c2c= .annotation_opts); + + ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); + if ((err =3D=3D 'q' || err =3D=3D CTRL('c')) && browser->he_selection->= branch_info) + continue; + if (err) + ui_browser__handle_resize(&browser->b); + + continue; case 's': c2c.symbol_full =3D !c2c.symbol_full; break; @@ -3045,6 +3103,10 @@ static int perf_c2c__report(int argc, const char **a= rgv) int err =3D 0; const char *output_str, *sort_str =3D NULL; =20 + annotation_options__init(&c2c.annotation_opts); + + hists__init(); + argc =3D parse_options(argc, argv, options, report_c2c_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (argc) @@ -3118,6 +3180,14 @@ static int perf_c2c__report(int argc, const char **a= rgv) if (err) goto out_mem2node; =20 + if (c2c.use_stdio) { + use_browser =3D 0; + } else { + use_browser =3D 1; + symbol__annotation_init(); + annotation_config__init(&c2c.annotation_opts); + } + if (symbol__init(&session->header.env) < 0) goto out_mem2node; =20 @@ -3127,11 +3197,6 @@ static int perf_c2c__report(int argc, const char **a= rgv) goto out_mem2node; } =20 - if (c2c.use_stdio) - use_browser =3D 0; - else - use_browser =3D 1; - setup_browser(false); =20 err =3D perf_session__process_events(session); @@ -3202,6 +3267,7 @@ static int perf_c2c__report(int argc, const char **ar= gv) out_session: perf_session__delete(session); out: + annotation_options__init(&c2c.annotation_opts); return err; } =20 --=20 2.40.1