From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CB9B15ECD7; Sat, 16 Aug 2025 03:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314206; cv=none; b=avHmSwUpYznRppp7zPd5uko/f5lGGM2zNV0hVOwztm42xSXhHOO8P3RwFoZZQ1on0uy8+Pxo9Oo6VMMg9KY7hf6WOevY9nTpewBAHRK83ercY+kgmjlRXZWEigCIIXDi5su7HiUoPQoxUnNmx2e23FG+wSSuSujhNuwaf3r6fmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314206; c=relaxed/simple; bh=8viBihXr7IdSkuQAI4GVNdT91S4WOOZlsIbBjgSb8IM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VKlL2iA+bmEbPlv1osl0+idJjRUrSQiQWF2diaRd0XVilRI7p+0SvxA0sywdcxCmRsKUrhYwD8Iz+6nwsRbY3syzcHq9t9dGSSuNckiR30aioXwx3xmvdCXlsYS3nDa4NFpRnTCFQfZVD7buaA2FD6nP+jkv9uZtT8tSQTX8Zlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DghwMxa9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DghwMxa9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60915C4CEF4; Sat, 16 Aug 2025 03:16:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314205; bh=8viBihXr7IdSkuQAI4GVNdT91S4WOOZlsIbBjgSb8IM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DghwMxa9HOLeFuGGQAenP0f+oONpwyWX7LWpZyQ191gi6K8h7qf/YtrROApUPnSfx wrPejDrghsj5iwhfKe4s8teMRSL/jxjCZU2zz4P+acYi0ss2fh51q6fT72IanknUHb b3fX3ULCoPVFkZJfFr8P+UVdkzh8wTUqERe6lRbxrD9sKq53YheeGU0+I1QZzrLmGe hMAqD6DlMJl0XtMoTMDJdGdXJElEMeNMnm5iu/PY44YJwsXcnlDMLc4NZZCMsLcb6T zIEB494WmDX2Eax/5Bigg/k5eXpbWluVAOuTtf/+DFYVlO68Or/O4hhIj1MWrgCsks yw7wx+btpN+5A== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 01/12] perf annotate: Rename to __hist_entry__tui_annotate() Date: Fri, 15 Aug 2025 20:16:24 -0700 Message-ID: <20250816031635.25318-2-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/annotate.c | 40 +++++++++++++++++++++++-------- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/util/annotate.h | 12 ---------- tools/perf/util/hist.h | 12 ++++++---- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 183902dac042ecb0..4d5cbb86cbb6d506 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -12,6 +12,7 @@ #include "../../util/symbol.h" #include "../../util/evsel.h" #include "../../util/evlist.h" +#include "../../util/thread.h" #include #include #include @@ -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]; }; =20 +/* A copy of target hist_entry for perf top. */ +static struct hist_entry annotate_he; + static inline struct annotation *browser__annotation(struct ui_browser *br= owser) { struct map_symbol *ms =3D browser->priv; @@ -557,7 +566,7 @@ static bool annotate_browser__callq(struct annotate_bro= wser *browser, target_ms.map =3D ms->map; target_ms.sym =3D 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_t= ype); ui_browser__show_title(&browser->b, title); return true; @@ -1032,12 +1041,6 @@ static int annotate_browser__run(struct annotate_bro= wser *browser, return key; } =20 -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); =20 - return map_symbol__tui_annotate(&he->ms, evsel, hbt); + return __hist_entry__tui_annotate(he, &he->ms, evsel, hbt); } =20 -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 *m= s, + struct evsel *evsel, + struct hist_browser_timer *hbt) { struct symbol *sym =3D ms->sym; struct annotation *notes =3D symbol__annotation(sym); @@ -1064,6 +1068,7 @@ int symbol__tui_annotate(struct map_symbol *ms, struc= t evsel *evsel, .priv =3D ms, .use_navkeypressed =3D true, }, + .he =3D he, }; struct dso *dso; int ret =3D -1, err; @@ -1093,6 +1098,16 @@ int symbol__tui_annotate(struct map_symbol *ms, stru= ct evsel *evsel, } } =20 + /* Copy necessary information when it's called from perf top */ + if (hbt !=3D NULL && he !=3D &annotate_he) { + annotate_he.hists =3D he->hists; + annotate_he.thread =3D thread__get(he->thread); + annotate_he.cpumode =3D he->cpumode; + map_symbol__copy(&annotate_he.ms, ms); + + browser.he =3D &annotate_he; + } + ui_helpline__push("Press ESC to exit"); =20 browser.b.width =3D notes->src->widths.max_line_len; @@ -1108,5 +1123,10 @@ int symbol__tui_annotate(struct map_symbol *ms, stru= ct evsel *evsel, if (not_annotated && !notes->src->tried_source) annotated_source__purge(notes->src); =20 + if (hbt !=3D NULL && he !=3D &annotate_he) { + thread__zput(annotate_he.thread); + map_symbol__exit(&annotate_he.ms); + } + return ret; } diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index d9d3fb44477ac6d5..487c0b08c0038710 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -2484,8 +2484,8 @@ do_annotate(struct hist_browser *browser, struct popu= p_action *act) else evsel =3D hists_to_evsel(browser->hists); =20 - err =3D map_symbol__tui_annotate(&act->ms, evsel, browser->hbt); he =3D hist_browser__selected_entry(browser); + err =3D __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 diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 8b5131d257b01e3e..0f640e4871744262 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -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); =20 -#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_unuse= d, - 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); =20 diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 70438d03ca9c33b1..c64005278687cb02 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -713,8 +713,9 @@ struct block_hist { #include "../ui/keysyms.h" void attr_to_script(char *buf, struct perf_event_attr *attr); =20 -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 *m= s, + struct evsel *evsel, + struct hist_browser_timer *hbt); =20 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 __m= aybe_unused, { return 0; } -static inline int map_symbol__tui_annotate(struct map_symbol *ms __maybe_u= nused, - 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; } --=20 2.50.1 From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CBE618DF9D; Sat, 16 Aug 2025 03:16:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314206; cv=none; b=bsLFIe5W7gZKdbBYzCezCSYw2d5LvyQ+ulUdrXfBD5zqH5oCOooxn/8eCaJfNwczeF6KIL3aJ7A07AiPypx01tTYxqK5FUv1X7zTmMsiqeB7IakCtuCWALDmZ92xqF1JwiZy/0SnidVlUKAEE5VxLIJ9qnyyhAzjdjVfwo5A16k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314206; c=relaxed/simple; bh=QECyPubR/tntQ5r5osUsf57sJgrlHghmrbJxowtVoQw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=od9VoXOXQKQle3IezBu1DZiTIVoElYeDsRA9qnMh9UGTIBw64fYX2+LAx1yz0QCIF2d6pWpU/nk7FZ3+Qq08X0i9gP1cFQjpCvcIomkrtbkQ/vX7hgTUMeOL2zER4i2bf1lPZTFgxHr8IuCbqrSMHXfz8gUravmkYbbFPp9p+cM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QvP7pgQz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QvP7pgQz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9428C4CEF5; Sat, 16 Aug 2025 03:16:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314206; bh=QECyPubR/tntQ5r5osUsf57sJgrlHghmrbJxowtVoQw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QvP7pgQzHQ7AuYhQocI+ideIDY+T+fp33uT5nuSbWIKgpTw+AUTYYv4SiAeUyDQVp XGc8PERp4zVazgWykwwe5mTQD4WdkCCaY85Bk39eNoZRMOjSIIFpBhJoFDO4Nj2D7K 5CaKl9zkh6ys0LIxfWg7Db7qZFDbW6tXev5E2RcqxbQwopXgbkYu40IVFA+MuZczU0 v2y6Hbv5s2NKdIF5hk7HFCxLqgTKTP7qVeJZSj1wEUiCi0OGeZQEJQ0B0kPunxKn/Y 27H8jjikg8vVos7Zyx2jObJApw0VIveCn+rGsApBJtVvubXxFxuNwOmg60yebqUVsq gC0pf4PsdsjKg== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 02/12] perf annotate: Remove annotation_print_data.start Date: Fri, 15 Aug 2025 20:16:25 -0700 Message-ID: <20250816031635.25318-3-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The start field is to control whether the output shows full address or offset from the function start. But actually it can be changed dynamically in annotation__toggle_full_addr(). The informaiton should be available through struct annotation. Let's use it directly. Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 0dd475a744b6dfac..b699e14102b0587a 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -770,7 +770,6 @@ struct annotation_print_data { struct evsel *evsel; struct arch *arch; struct debuginfo *dbg; - u64 start; int addr_fmt_width; }; =20 @@ -845,7 +844,7 @@ annotation_line__print(struct annotation_line *al, stru= ct annotation_print_data =20 printf(" : "); =20 - disasm_line__print(dl, apd->start, apd->addr_fmt_width); + disasm_line__print(dl, notes->src->start, apd->addr_fmt_width); =20 if (opts->code_with_type && apd->dbg) { struct annotated_data_type *data_type; @@ -1230,7 +1229,6 @@ int hist_entry__annotate_printf(struct hist_entry *he= , struct evsel *evsel) struct annotation_print_data apd =3D { .he =3D he, .evsel =3D evsel, - .start =3D map__rip_2objdump(map, sym->start), }; int printed =3D 2, queue_len =3D 0; int more =3D 0; @@ -1267,7 +1265,7 @@ int hist_entry__annotate_printf(struct hist_entry *he= , struct evsel *evsel) symbol__annotate_hits(sym, evsel); =20 apd.addr_fmt_width =3D annotated_source__addr_fmt_width(¬es->src->sour= ce, - apd.start); + notes->src->start); evsel__get_arch(evsel, &apd.arch); apd.dbg =3D debuginfo__new(filename); =20 --=20 2.50.1 From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 438571CAA79; Sat, 16 Aug 2025 03:16:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314207; cv=none; b=f0xpJl3dr2yh/VBKkp775nQWQKvapYj9Sl5FvWLyszhVlN/ydCMtJfUfEHENcCdXQ5rygLhwDcrJRCEzx6MArPITDM2Tl11QqjTq7jspIXpIn5N++zxZoXM4nCl18WB5NqbD+/8vJGHxjVq6gWpI7cOkCtc+CZL95o7rJIyjt/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314207; c=relaxed/simple; bh=jsU4y+K6YseHQje4CBTJWta00/M0LzB4LyLhMKbDINs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GStb3iyRwNXIYLRKGoPQ4w0vs3g4Wxfa7TZbU5hBbN3oPmkEbCelK2lohoYn7A0KfsHuK078IwdSiiMYz/axGZOAzuG+iQC0pgNScbNdhtwoXahNvoRbRHbZINSUMM/fejW/5yJZD06vGenAZju4z6suQ3xL/nvGU8UehGCN7tY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uy8CmhcF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uy8CmhcF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BD5EC4CEEB; Sat, 16 Aug 2025 03:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314206; bh=jsU4y+K6YseHQje4CBTJWta00/M0LzB4LyLhMKbDINs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uy8CmhcFSXyx3QAB857vOZXoFBouNA9pbk+Xn6H2ZEUqRwVHizxbwwjjF+lD92udq ei+U7j7bKBBcWGE49Fm9PZYmH8EXdG6cFaEGtl0PVzNFzXMzXw4CkytYLhwFM8CBC6 57krvPb9KwGDsZDFgj5EExIPVspZV42MqOMwHnxK95+uZzrmHDUXdt0uJvOApgFcrq Y5d37eda8mMSKNbQMgIAuDpBhiSNhm2Nsy1rF+hZLdzrJlv8nJHBZX9LSz+9TDGbfa zfzJWB75eNAjzBq0BosnlrNXe3mSZbJEUNoNZP3k0dresZXP9d118pRkDANvmse1QU S8rApCr/bP8/Q== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 03/12] perf annotate: Remove __annotation_line__write() Date: Fri, 15 Aug 2025 20:16:26 -0700 Message-ID: <20250816031635.25318-4-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Get rid of the internal function and convert function arguments into local variables if they are used more than once. Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 46 ++++++++++++++++---------------------- tools/perf/util/annotate.h | 2 +- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index b699e14102b0587a..7929f108e35b4e65 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1933,24 +1933,26 @@ int annotation_br_cntr_entry(char **str, int br_cnt= r_nr, return -ENOMEM; } =20 -static void __annotation_line__write(struct annotation_line *al, struct an= notation *notes, - bool first_line, bool current_entry, bool change_color, int width, - void *obj, unsigned int percent_type, - int (*obj__set_color)(void *obj, int color), - void (*obj__set_percent_color)(void *obj, double percent, bool cu= rrent), - int (*obj__set_jumps_percent_color)(void *obj, int nr, bool curr= ent), - void (*obj__printf)(void *obj, const char *fmt, ...), - void (*obj__write_graph)(void *obj, int graph)) - -{ - double percent_max =3D annotation_line__max_percent(al, percent_type); - int pcnt_width =3D annotation__pcnt_width(notes), - cycles_width =3D annotation__cycles_width(notes); +void annotation_line__write(struct annotation_line *al, struct annotation = *notes, + const struct annotation_write_ops *wops) +{ + bool current_entry =3D wops->current_entry; + bool change_color =3D wops->change_color; + double percent_max =3D annotation_line__max_percent(al, annotate_opts.per= cent_type); + int width =3D wops->width; + int pcnt_width =3D annotation__pcnt_width(notes); + int cycles_width =3D annotation__cycles_width(notes); bool show_title =3D false; char bf[256]; int printed; - - if (first_line && (al->offset =3D=3D -1 || percent_max =3D=3D 0.0)) { + void *obj =3D wops->obj; + int (*obj__set_color)(void *obj, int color) =3D wops->set_color; + void (*obj__set_percent_color)(void *obj, double percent, bool current) = =3D wops->set_percent_color; + int (*obj__set_jumps_percent_color)(void *obj, int nr, bool current) =3D= wops->set_jumps_percent_color; + void (*obj__printf)(void *obj, const char *fmt, ...) =3D wops->printf; + void (*obj__write_graph)(void *obj, int graph) =3D wops->write_graph; + + if (wops->first_line && (al->offset =3D=3D -1 || percent_max =3D=3D 0.0))= { if (notes->branch && al->cycles) { if (al->cycles->ipc =3D=3D 0.0 && al->cycles->avg =3D=3D 0) show_title =3D true; @@ -1964,7 +1966,8 @@ static void __annotation_line__write(struct annotatio= n_line *al, struct annotati for (i =3D 0; i < al->data_nr; i++) { double percent; =20 - percent =3D annotation_data__percent(&al->data[i], percent_type); + percent =3D annotation_data__percent(&al->data[i], + annotate_opts.percent_type); =20 obj__set_percent_color(obj, percent, current_entry); if (symbol_conf.show_total_period) { @@ -2113,17 +2116,6 @@ static void __annotation_line__write(struct annotati= on_line *al, struct annotati =20 } =20 -void annotation_line__write(struct annotation_line *al, struct annotation = *notes, - struct annotation_write_ops *wops) -{ - __annotation_line__write(al, notes, wops->first_line, wops->current_entry, - wops->change_color, wops->width, wops->obj, - annotate_opts.percent_type, - wops->set_color, wops->set_percent_color, - wops->set_jumps_percent_color, wops->printf, - wops->write_graph); -} - int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel, struct arch **parch) { diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 0f640e4871744262..2e28a24fa13a736a 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -200,7 +200,7 @@ struct annotation_write_ops { }; =20 void annotation_line__write(struct annotation_line *al, struct annotation = *notes, - struct annotation_write_ops *ops); + const struct annotation_write_ops *ops); =20 int __annotation__scnprintf_samples_period(struct annotation *notes, char *bf, size_t size, --=20 2.50.1 From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F5E51D61AA; Sat, 16 Aug 2025 03:16:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314207; cv=none; b=oCkP0wQf2L26coZ1VlxN9RCdzz1tMFCeN94GqyMLq2iDg1s2TrCcMzzo2oAqCceAkjnx3dvirgz6oaaLLkA5477JE4e8Vq1939CPKmT+pblzFMP5FWxUT7beeWk5FYqP5xY0eZ7H4WW9J6jyWXeGfYnMkWwjWAu8hPFJiI8G0n0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314207; c=relaxed/simple; bh=XZjti3XHrCfQO6sBCH1rEoGQI33dDS/jESNitnkg8sY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XmTQSzk2dyakcajlDBfOLbKqLlC3iOijAnGsy7JpPb1dKJzOXKJOWsaO3OiJVkAr4D4koNs0y8kgJS7U4jEWE/7oCoh/8Z2wxHP701GAmFrPN1M6a4eUL3NnLK0TH+J+uu3CqGrm5zlxtNME1+wmA7fKeAaWytvmOf7WFfDlWeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L1kZrns5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L1kZrns5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D467BC4CEF7; Sat, 16 Aug 2025 03:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314207; bh=XZjti3XHrCfQO6sBCH1rEoGQI33dDS/jESNitnkg8sY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L1kZrns5iInf7ajEa1hUfZXInS8s231+tgMQ4BCH9X/Umo//hrBcWlw7Qru3tf9Xy hxGF2a7jlrXG5976aIHNC63QFyp70wpCC2z2H335qdlamC0XTCoRshWjX/bDjBPnas rADct71SOqizWIaIdVtyciaYckIyc1PuQgpXG3Fp1i1AIE/n7bWtJ8S8zvAmKz2rxd 6hwNZDjA1ihPqhel/Aky/mGRIXaPy9KATNsse7XbCNWeMq6J7kY3qC+ii33XM6DU1b nIn5fnJSkHJVFNA1TkOHp+1ZlU2cYLo5guY1nxv82sSfY/RO6+mvcjQ+KcBGFpO2lP we8vOMO8YKcAA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 04/12] perf annotate: Pass annotation_print_data to annotation_line__write() Date: Fri, 15 Aug 2025 20:16:27 -0700 Message-ID: <20250816031635.25318-5-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It will be used for data type display later. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/annotate.c | 13 ++++++++++-- tools/perf/util/annotate.c | 33 ++++++++++++++++++------------- tools/perf/util/annotate.h | 15 ++++++++++++-- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 4d5cbb86cbb6d506..3e8b111e3f12b030 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -33,6 +33,8 @@ struct annotate_browser { * its lifetime. */ struct hist_entry *he; + struct debuginfo *dbg; + struct evsel *evsel; bool searching_backwards; char search_bf[128]; }; @@ -116,12 +118,18 @@ static void annotate_browser__write(struct ui_browser= *browser, void *entry, int .printf =3D annotate_browser__printf, .write_graph =3D annotate_browser__write_graph, }; + struct annotation_print_data apd =3D { + .he =3D ab->he, + .arch =3D ab->arch, + .evsel =3D ab->evsel, + .dbg =3D ab->dbg, + }; =20 /* The scroll bar isn't being used */ if (!browser->navkeypressed) ops.width +=3D 1; =20 - annotation_line__write(al, notes, &ops); + annotation_line__write(al, notes, &ops, &apd); =20 if (ops.current_entry) ab->selection =3D al; @@ -984,7 +992,7 @@ static int annotate_browser__run(struct annotate_browse= r *browser, continue; } case 'P': - map_symbol__annotation_dump(ms, evsel); + map_symbol__annotation_dump(ms, evsel, browser->he); continue; case 't': if (symbol_conf.show_total_period) { @@ -1069,6 +1077,7 @@ int __hist_entry__tui_annotate(struct hist_entry *he,= struct map_symbol *ms, .use_navkeypressed =3D true, }, .he =3D he, + .evsel =3D evsel, }; struct dso *dso; int ret =3D -1, err; diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 7929f108e35b4e65..2544d83a52a0a596 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -765,14 +765,6 @@ __hist_entry__get_data_type(struct hist_entry *he, str= uct arch *arch, struct debuginfo *dbg, struct disasm_line *dl, int *type_offset); =20 -struct annotation_print_data { - struct hist_entry *he; - struct evsel *evsel; - struct arch *arch; - struct debuginfo *dbg; - int addr_fmt_width; -}; - static int annotation_line__print(struct annotation_line *al, struct annotation_print= _data *apd, struct annotation_options *opts, int printed, @@ -1355,7 +1347,8 @@ static void FILE__write_graph(void *fp, int graph) fputs(s, fp); } =20 -static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp) +static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp, + struct annotation_print_data *apd) { struct annotation *notes =3D symbol__annotation(sym); struct annotation_write_ops wops =3D { @@ -1372,7 +1365,7 @@ static int symbol__annotate_fprintf2(struct symbol *s= ym, FILE *fp) list_for_each_entry(al, ¬es->src->source, node) { if (annotation_line__filter(al)) continue; - annotation_line__write(al, notes, &wops); + annotation_line__write(al, notes, &wops, apd); fputc('\n', fp); wops.first_line =3D false; } @@ -1380,13 +1373,18 @@ static int symbol__annotate_fprintf2(struct symbol = *sym, FILE *fp) return 0; } =20 -int map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel) +int map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel, + struct hist_entry *he) { const char *ev_name =3D evsel__name(evsel); char buf[1024]; char *filename; int err =3D -1; FILE *fp; + struct annotation_print_data apd =3D { + .he =3D he, + .evsel =3D evsel, + }; =20 if (asprintf(&filename, "%s.annotation", ms->sym->name) < 0) return -1; @@ -1402,7 +1400,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms= , struct evsel *evsel) =20 fprintf(fp, "%s() %s\nEvent: %s\n\n", ms->sym->name, dso__long_name(map__dso(ms->map)), ev_name); - symbol__annotate_fprintf2(ms->sym, fp); + symbol__annotate_fprintf2(ms->sym, fp, &apd); =20 fclose(fp); err =3D 0; @@ -1654,6 +1652,10 @@ int hist_entry__tty_annotate2(struct hist_entry *he,= struct evsel *evsel) struct symbol *sym =3D ms->sym; struct rb_root source_line =3D RB_ROOT; struct hists *hists =3D evsel__hists(evsel); + struct annotation_print_data apd =3D { + .he =3D he, + .evsel =3D evsel, + }; char buf[1024]; int err; =20 @@ -1676,7 +1678,7 @@ int hist_entry__tty_annotate2(struct hist_entry *he, = struct evsel *evsel) hists__scnprintf_title(hists, buf, sizeof(buf)); fprintf(stdout, "%s, [percent: %s]\n%s() %s\n", buf, percent_type_str(annotate_opts.percent_type), sym->name, dso__long_= name(dso)); - symbol__annotate_fprintf2(sym, stdout); + symbol__annotate_fprintf2(sym, stdout, &apd); =20 annotated_source__purge(symbol__annotation(sym)->src); =20 @@ -1934,7 +1936,8 @@ int annotation_br_cntr_entry(char **str, int br_cntr_= nr, } =20 void annotation_line__write(struct annotation_line *al, struct annotation = *notes, - const struct annotation_write_ops *wops) + const struct annotation_write_ops *wops, + struct annotation_print_data *apd) { bool current_entry =3D wops->current_entry; bool change_color =3D wops->change_color; @@ -2112,6 +2115,8 @@ void annotation_line__write(struct annotation_line *a= l, struct annotation *notes disasm_line__write(disasm_line(al), notes, obj, bf, sizeof(bf), obj__pri= ntf, obj__write_graph); =20 obj__printf(obj, "%-*s", width - pcnt_width - cycles_width - 3 - printed= , bf); + + (void)apd; } =20 } diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 2e28a24fa13a736a..86e858f5bf173152 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -199,8 +199,18 @@ struct annotation_write_ops { void (*write_graph)(void *obj, int graph); }; =20 +struct annotation_print_data { + struct hist_entry *he; + struct evsel *evsel; + struct arch *arch; + struct debuginfo *dbg; + /* It'll be set in hist_entry__annotate_printf() */ + int addr_fmt_width; +}; + void annotation_line__write(struct annotation_line *al, struct annotation = *notes, - const struct annotation_write_ops *ops); + const struct annotation_write_ops *ops, + struct annotation_print_data *apd); =20 int __annotation__scnprintf_samples_period(struct annotation *notes, char *bf, size_t size, @@ -463,7 +473,8 @@ void symbol__annotate_zero_histogram(struct symbol *sym= , struct evsel *evsel); void symbol__annotate_decay_histogram(struct symbol *sym, struct evsel *ev= sel); void annotated_source__purge(struct annotated_source *as); =20 -int map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel= ); +int map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel, + struct hist_entry *he); =20 bool ui__has_annotation(void); =20 --=20 2.50.1 From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 178DE1D9A5D; Sat, 16 Aug 2025 03:16:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314208; cv=none; b=WNqm+itGfHOdnpJPCvNSiGCYM1oeyF3oRRO8M5ugJggorM4yDC1WT+x4bRGsq5cG92QKsNjJkRX0PH7QCHn8rK5TZVIyCBvGEg+iadQy26VvryTlPJM+s/jiltTW61QX409o75X14h20pskR9XmZhk5olJerTgR077YPMd/R5SM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314208; c=relaxed/simple; bh=UYC9rFsxpN+onryemYIQyLiFHC9fW6/Ag397Hiu3TNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CIuFYCEGgBSe/ill6gxzhXxiBZ5+vWid4ERouz7GVnAeSCq0kPhtMF9sWnrWgjQJic2nthPz1rjZY9YEJkcRUNxafX0tpj3k+bDdxPX6wpaXLsbGYZUrgOubJLWsdWhhVJH915iDw9SRH/MyNbcbsSOKBol1YAz6qO4FLQUv7b0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JixsBtMd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JixsBtMd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58914C4CEF6; Sat, 16 Aug 2025 03:16:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314207; bh=UYC9rFsxpN+onryemYIQyLiFHC9fW6/Ag397Hiu3TNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JixsBtMd/v3c6N/sjaBx+qF64fzDJ3+8k8p7gG1rSED8BluoH5kMDKbD6tpTn/YFQ PmbdMQB70ip5hEjX8BlIAhbKmq12S2NrxM6ahTazuFnOBixxC/cQwS6/Sa7dUY9HbX R0DTKD0fmVYtLW7Swr7PSnIIigx1v7QIRCCj7SyQQyhuhJ/XHM17zIqH0XD1uYk/iN o2JRq5BgivnnZBGhWb/D6bjXagWRMzEgcv/aGvayfzwd1Xpt0J9nHnfabrBj53MgXX yPO6E3NZchX5/FTxhlt+4Qu0MN38ZM4bJY4dDYX2yH0CPb83XYkCOV7NK3IjZ87kbZ 9Mx5VcgJEkS3g== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 05/12] perf annotate: Simplify width calculation in annotation_line__write() Date: Fri, 15 Aug 2025 20:16:28 -0700 Message-ID: <20250816031635.25318-6-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The width is updated after each part is printed. It can skip the output processing if the total printed size is bigger than the width. No function changes intended. Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2544d83a52a0a596..6389292ad8f95d89 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1993,6 +1993,7 @@ void annotation_line__write(struct annotation_line *a= l, struct annotation *notes symbol_conf.show_nr_samples ? "Samples" : "Percent"); } } + width -=3D pcnt_width; =20 if (notes->branch) { if (al->cycles && al->cycles->ipc) @@ -2056,11 +2057,13 @@ void annotation_line__write(struct annotation_line = *al, struct annotation *notes obj__printf(obj, "%*s", ANNOTATION__AVG_IPC_WIDTH, bf); } } + width -=3D cycles_width; =20 obj__printf(obj, " "); + width -=3D 1; =20 if (!*al->line) - obj__printf(obj, "%-*s", width - pcnt_width - cycles_width, " "); + obj__printf(obj, "%-*s", width, " "); else if (al->offset =3D=3D -1) { if (al->line_nr && annotate_opts.show_linenr) printed =3D scnprintf(bf, sizeof(bf), "%-*d ", @@ -2069,7 +2072,8 @@ void annotation_line__write(struct annotation_line *a= l, struct annotation *notes printed =3D scnprintf(bf, sizeof(bf), "%-*s ", notes->src->widths.addr, " "); obj__printf(obj, bf); - obj__printf(obj, "%-*s", width - printed - pcnt_width - cycles_width + 1= , al->line); + width -=3D printed; + obj__printf(obj, "%-*s", width, al->line); } else { u64 addr =3D al->offset; int color =3D -1; @@ -2112,9 +2116,11 @@ void annotation_line__write(struct annotation_line *= al, struct annotation *notes if (change_color) obj__set_color(obj, color); =20 + width -=3D printed; + disasm_line__write(disasm_line(al), notes, obj, bf, sizeof(bf), obj__pri= ntf, obj__write_graph); =20 - obj__printf(obj, "%-*s", width - pcnt_width - cycles_width - 3 - printed= , bf); + obj__printf(obj, "%-*s", width, bf); =20 (void)apd; } --=20 2.50.1 From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 422701DC988; Sat, 16 Aug 2025 03:16:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314208; cv=none; b=mWGW7Cx75gcA5H1LEWaj5oEA35XiHJQ1pEVqr+pe7v2MwgeYy7f2HxhcKZbk03ujVRxaLNPeAYPRVjStutK2GawzbuzTUG4UXKA2QDsCwmukuUHHLvEYC3M39+afOwnRT3MKBrWo6cFVl3uwXHuhCrSk4ypJll68u1D8pigQgVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314208; c=relaxed/simple; bh=6t1acRc6hqOEWUSOnk4iV6/B/TzQ0IIv9Z8zDuepklk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RTb02n/RzF55HUdLmWwdSqW6Sm3CMwBoHMur8ywYNDbQEu3bGQdWMTpTf0+CqbPYEfdNgZtAvFDkVPoMeZfkfII5Pdc5+YKdVsEdtsULlaj3eNqtdGCMgPzZHObS3BTuJz0ehwF7Noc2/mQJTyxiXqCGxYMP0VgV7VqKIGihKS0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ovI02Pui; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ovI02Pui" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA7DAC4CEEB; Sat, 16 Aug 2025 03:16:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314208; bh=6t1acRc6hqOEWUSOnk4iV6/B/TzQ0IIv9Z8zDuepklk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ovI02PuiO26hJuDHcPi97m3nCgMuh+m6GypYr9uDsTEUCNrnJLtXk1RXubwIOI+D4 /p3V4a4A9pQYS3Igoh8jwuixZ4lfPA82YbemOoH5NZEb9x3an30At1vR90cDuR1jZf onpY+FeETInPZmp0wtHgv8Y2osW7/QoE5G8Pfwq59Bt6/zy87WEtmNbu0QWFF0uOB1 Th2V17oGbOVFt0LDlxnyV2MigjsfsMt1JlfpKOmkGZB2LVko77dKxhFTR6tYJ3OpyB VfPmvkjKkmFCcduhZUH2T268qAXekB8MbIcrZDtw6q3+pp3DGpd07jiTLPC4pXKuXP FGukVk+iHI+LA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 06/12] perf annotate: Return printed number from disasm_line__write() Date: Fri, 15 Aug 2025 20:16:29 -0700 Message-ID: <20250816031635.25318-7-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Like other print functions, make disasm_line__write() return the number of printed characters. It'll be used to skip unnecessary operations when the screen is full. Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 6389292ad8f95d89..698bc4f559e83043 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1743,7 +1743,7 @@ static double annotation_line__max_percent(struct ann= otation_line *al, return percent_max; } =20 -static void disasm_line__write(struct disasm_line *dl, struct annotation *= notes, +static int disasm_line__write(struct disasm_line *dl, struct annotation *n= otes, void *obj, char *bf, size_t size, void (*obj__printf)(void *obj, const char *fmt, ...), void (*obj__write_graph)(void *obj, int graph)) @@ -1771,8 +1771,8 @@ static void disasm_line__write(struct disasm_line *dl= , struct annotation *notes, obj__printf(obj, " "); } =20 - disasm_line__scnprintf(dl, bf, size, !annotate_opts.use_offset, - notes->src->widths.max_ins_name); + return disasm_line__scnprintf(dl, bf, size, !annotate_opts.use_offset, + notes->src->widths.max_ins_name) + 2; } =20 static void ipc_coverage_string(char *bf, int size, struct annotation *not= es) --=20 2.50.1 From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07E5E1DF256; Sat, 16 Aug 2025 03:16:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314209; cv=none; b=JsjEDQxls43JK1/LB6s7V2f7Qj/sBwxsU+DoPEA06q876YZbAb80Z2dD4oiS/t+i6HTqH9SQyztrQtGBJc0XB11VGG+OnRKaUGVpnPRkQ9aaBnc6tYUh0aMUi02KQp4jgsYlfWypvClTt8z6QAbBptu4ormwqNr+mTwje20G1WQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314209; c=relaxed/simple; bh=f55lAbXw2gvkAvto69pqFf64NHcOnxAXKXI89Ga3qVw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ms1oZbMfjhSI9+fps47U2TnTfk7LKjj0LVTcntBNEswMMwtmv5H2r65zmLCzRG6eV5KQ2YlIvkoPC5e5/TYfKfi2+7ObpSqAvzs0rgXAzA7p2Wi6rbPuIrFdn7zoXGeiK4ncvcMl5xuzoUgIYWfNKZ/w1k79MpL03rFYnBeLveM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EzezQ+Z+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EzezQ+Z+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A928C4CEFB; Sat, 16 Aug 2025 03:16:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314208; bh=f55lAbXw2gvkAvto69pqFf64NHcOnxAXKXI89Ga3qVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EzezQ+Z+lqnk5gfRfFDPL/1HGykdwfYPjYp/VQHtSzkLm0MarV5tC0QUQxVBoWtPM ZdTRqoAj4G5B7Y8vAxh5ayGC3GDnqN7/LJ3bqIV5WMEcmIX2A022f28mS5E3KEPyfz /5C3DYuzSqgfeXi70uAxPzp3IByUHhEgSIIKJs0j92J6/C2qpJn0Z+82PV6Vj9eEsz RQyZZoC/uiR2EL2OGYYvApe6ImOK1u4eazP+r0rxoe2icTw2t7NgISh2Nd7kZ34e3x rSl++8lLwaal8ce2W4WlLY0Al9XLYGpLJVyN9r/TrJtomDiiLxi30lRtW8VSjrPOnJ yw7krAx4aVa9g== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 07/12] perf annotate: Add --code-with-type support for TUI Date: Fri, 15 Aug 2025 20:16:30 -0700 Message-ID: <20250816031635.25318-8-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Until now, the --code-with-type option is available only on stdio. But it was an artifical limitation because of an implemention issue. Implement the same logic in annotation_line__write() for stdio2/TUI and remove the limitation and update the man page. Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/Documentation/perf-annotate.txt | 1 - tools/perf/builtin-annotate.c | 5 --- tools/perf/ui/browsers/annotate.c | 6 +++ tools/perf/util/annotate.c | 47 ++++++++++++++++++++-- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Docume= ntation/perf-annotate.txt index 46090c5b42b4762f..547f1a2680185e3c 100644 --- a/tools/perf/Documentation/perf-annotate.txt +++ b/tools/perf/Documentation/perf-annotate.txt @@ -170,7 +170,6 @@ include::itrace.txt[] =20 --code-with-type:: Show data type info in code annotation (for memory instructions only). - Currently it only works with --stdio option. =20 =20 SEE ALSO diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 5d57d2913f3d9a33..646f43b0f7c4c9b0 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -917,11 +917,6 @@ int cmd_annotate(int argc, const char **argv) symbol_conf.annotate_data_sample =3D true; } else if (annotate_opts.code_with_type) { symbol_conf.annotate_data_member =3D true; - - if (!annotate.use_stdio) { - pr_err("--code-with-type only works with --stdio.\n"); - goto out_delete; - } } =20 setup_browser(true); diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 3e8b111e3f12b030..e5b35336f0d33d7e 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -4,6 +4,7 @@ #include "../ui.h" #include "../../util/annotate.h" #include "../../util/debug.h" +#include "../../util/debuginfo.h" #include "../../util/dso.h" #include "../../util/hist.h" #include "../../util/sort.h" @@ -1119,6 +1120,9 @@ int __hist_entry__tui_annotate(struct hist_entry *he,= struct map_symbol *ms, =20 ui_helpline__push("Press ESC to exit"); =20 + if (annotate_opts.code_with_type) + browser.dbg =3D debuginfo__new(dso__long_name(dso)); + browser.b.width =3D notes->src->widths.max_line_len; browser.b.nr_entries =3D notes->src->nr_entries; browser.b.entries =3D ¬es->src->source; @@ -1129,6 +1133,8 @@ int __hist_entry__tui_annotate(struct hist_entry *he,= struct map_symbol *ms, =20 ret =3D annotate_browser__run(&browser, evsel, hbt); =20 + if (annotate_opts.code_with_type) + debuginfo__delete(browser.dbg); if (not_annotated && !notes->src->tried_source) annotated_source__purge(notes->src); =20 diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 698bc4f559e83043..99e976d254493de2 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1362,6 +1362,11 @@ static int symbol__annotate_fprintf2(struct symbol *= sym, FILE *fp, }; struct annotation_line *al; =20 + if (annotate_opts.code_with_type) { + evsel__get_arch(apd->evsel, &apd->arch); + apd->dbg =3D debuginfo__new(dso__long_name(map__dso(apd->he->ms.map))); + } + list_for_each_entry(al, ¬es->src->source, node) { if (annotation_line__filter(al)) continue; @@ -1370,6 +1375,9 @@ static int symbol__annotate_fprintf2(struct symbol *s= ym, FILE *fp, wops.first_line =3D false; } =20 + if (annotate_opts.code_with_type) + debuginfo__delete(apd->dbg); + return 0; } =20 @@ -1935,6 +1943,36 @@ int annotation_br_cntr_entry(char **str, int br_cntr= _nr, return -ENOMEM; } =20 +static int disasm_line__snprint_type_info(struct disasm_line *dl, + char *buf, int len, + struct annotation_print_data *apd) +{ + struct annotated_data_type *data_type; + char member[256]; + int offset =3D 0; + int printed; + + scnprintf(buf, len, " "); + + if (!annotate_opts.code_with_type || apd->dbg =3D=3D NULL) + return 1; + + data_type =3D __hist_entry__get_data_type(apd->he, apd->arch, apd->dbg, d= l, &offset); + if (data_type =3D=3D NULL || data_type =3D=3D NO_TYPE) + return 1; + + printed =3D scnprintf(buf, len, "\t\t# data-type: %s", data_type->self.ty= pe_name); + + if (data_type !=3D &stackop_type && data_type !=3D &canary_type && len > = printed) + printed +=3D scnprintf(buf + printed, len - printed, " +%#x", offset); + + if (annotated_data_type__get_member_name(data_type, member, sizeof(member= ), offset) && + len > printed) { + printed +=3D scnprintf(buf + printed, len - printed, " (%s)", member); + } + return printed; +} + void annotation_line__write(struct annotation_line *al, struct annotation = *notes, const struct annotation_write_ops *wops, struct annotation_print_data *apd) @@ -2118,11 +2156,14 @@ void annotation_line__write(struct annotation_line = *al, struct annotation *notes =20 width -=3D printed; =20 - disasm_line__write(disasm_line(al), notes, obj, bf, sizeof(bf), obj__pri= ntf, obj__write_graph); + printed =3D disasm_line__write(disasm_line(al), notes, obj, bf, sizeof(b= f), + obj__printf, obj__write_graph); =20 - obj__printf(obj, "%-*s", width, bf); + obj__printf(obj, "%s", bf); + width -=3D printed; =20 - (void)apd; + disasm_line__snprint_type_info(disasm_line(al), bf, sizeof(bf), apd); + obj__printf(obj, "%-*s", width, bf); } =20 } --=20 2.50.1 From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E60B1E0DE3; Sat, 16 Aug 2025 03:16:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314209; cv=none; b=eLO/uISipnqXvjPHfieS4yyBCyzOu7ZtG+rZBC04c+/uJvQpchgUXsAlu2CyG5S88aKnBLcPPYZiVdiT4DiglEpoQ0HR687xGlLKyEHAZ1TtWRm0fNz1anQuc3PSc5DAzCCHCbcpUO7hxmOKAj/qYqDL2NrCwtn6KOsfDVc3RIg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314209; c=relaxed/simple; bh=/q5ZMgNzBTPuHcNQWblbJy/veaZuKraOJBpsFCRXNSU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UQbTCmmSr4qrQ3F6tIGRq0Gb+hGl9zX3k8dCGItuWFMQdn8iEaQBuLr05aFDdI948WseI13hdbBg98csM+I1gAnJjNTVAWfs53+1Y924+uh88kb+XoKSqwXDXA6tGl9dlcgx/j3MCr54EE6MyXYDOHvS8NXK+RaU7wlVFqQ/Auo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c536WIue; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c536WIue" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD3B9C4CEF4; Sat, 16 Aug 2025 03:16:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314209; bh=/q5ZMgNzBTPuHcNQWblbJy/veaZuKraOJBpsFCRXNSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c536WIueefK10+Vy+Y8heltG3GMiV5GDcvvQBrwmvfiuqVFWF9LPcqPtGhFo7p+uW EM7Ykj95cZXDulKOI/Gp9kYWJfjP/S3ddqoJ2a1KRwlZncmjZKtDJNotfjksvOw3XN i7gKQJdjlB7lET+qqi9bCgoxoUqXFF3BWBmTsa0rDF+w77bYHJKD+rE8NT/sF9RmwT j8aQIYnuIOZ3Xgo3Go4i3z8cunz+yCdqAiPCeFT9dFFl85oieauA5YKqWVW4BYOntX m7KjM41HqtIHQMhoERJ4T430bnEDrWGqLPq5rj2gbczMC3zjEg4uPzubL2aCNjZJzJ YVcBx3GHOck7A== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 08/12] perf annotate: Add 'T' hot key to toggle data type display Date: Fri, 15 Aug 2025 20:16:31 -0700 Message-ID: <20250816031635.25318-9-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Tested-by: Arnaldo Carvalho de Melo --- 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/ann= otate.c index e5b35336f0d33d7e..dfe869c20e35da77 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -533,9 +533,10 @@ static void ui_browser__init_asm_mode(struct ui_browse= r *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]" : ""); } =20 /* @@ -909,7 +910,8 @@ static int annotate_browser__run(struct annotate_browse= r *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); @@ -1029,6 +1031,12 @@ static int annotate_browser__run(struct annotate_bro= wser *browser, case 'f': annotation__toggle_full_addr(notes, ms); continue; + case 'T': + annotate_opts.code_with_type ^=3D 1; + if (browser->dbg =3D=3D NULL) + browser->dbg =3D debuginfo__new(dso__long_name(map__dso(ms->map))); + annotate_browser__show(&browser->b, title, help); + continue; case K_LEFT: case '<': case '>': @@ -1133,8 +1141,7 @@ int __hist_entry__tui_annotate(struct hist_entry *he,= struct map_symbol *ms, =20 ret =3D annotate_browser__run(&browser, evsel, hbt); =20 - 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); =20 --=20 2.50.1 From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A86F21E1E1C; Sat, 16 Aug 2025 03:16:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314209; cv=none; b=KPc44uXDI9duX001/p94xTGbpfmIQOTACjD1SELE0XWAC4It3WaB2/sQ7GyseaEDgRRG+STkAPwMD4NDvMzCoh3OtfLCwiBEaBqC272dmYBYywNkPYYvAVQXaeqwGMTe2HTrWZgjWPKCQVdYza8IT5unJmVRmvCKT5T14hAKdX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314209; c=relaxed/simple; bh=xIE0yPJqoPDcFz62BS6iiEO0J3tG4qsg4AmQSIsboX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Si1n36hGB4u2+h1ouJk32G4+1gEViaKIxRP12ND5X6s2Kmf3N5ggv3JEoh22naM4gTw7FXL6Oy5RsCBBUjQA/j4DZ1OdL9JlayXlHg7f5/SIrvVMyLbxPqllmDMTABi3grrnVvj11xQBj0McmCbA0/4kia3RjbzAsYB0ciLPaB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VMypgYUv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VMypgYUv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B487C4CEF5; Sat, 16 Aug 2025 03:16:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314209; bh=xIE0yPJqoPDcFz62BS6iiEO0J3tG4qsg4AmQSIsboX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VMypgYUvgB3KkED9QYjIE7FP8Pk7EpSJEbsOBw/yytgZ3uj5qplgnrqEVGB6wVBDG LnSWR/I9TQ/MfgWjtz1vU5zSgU1I8upCggCv1My6XJgdAKoJKR3TjPPkj98bPjvOFq YGmxB0CgJo6QaRosVDU3Trsmji6NKmVR7pPiKW3bAWBu6nrd8TC2vx2YQdzCoW65pX AMHebDia0UAsAXt7W4Oy4fM6JQ+W41dhQcgiubhSvnEO/E0/hRBZrEpqLXKiI6cN9l 9HV4urmdIEukeqN1PaM4hti5betFxHcReIO9Ij5rkp8kjpb3NUejs0u7AP8ifYYH4k H2cm01tgYYQ7w== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 09/12] perf annotate: Show warning when debuginfo is not available Date: Fri, 15 Aug 2025 20:16:32 -0700 Message-ID: <20250816031635.25318-10-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When user requests data-type annotation but no DWARF info is available, show a warning message about it. Warning: DWARF debuginfo not found. Data-type in this DSO will not be displayed. Please make sure to have debug information. Press any key... Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/annotate.c | 17 +++++++++++++++++ tools/perf/util/dso.h | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index dfe869c20e35da77..e3e7004f32251666 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -812,6 +812,20 @@ static int annotate__scnprintf_title(struct hists *his= ts, char *bf, size_t size) return printed; } =20 +static void annotate_browser__debuginfo_warning(struct annotate_browser *b= rowser) +{ + struct map_symbol *ms =3D browser->b.priv; + struct dso *dso =3D map__dso(ms->map); + + if (browser->dbg =3D=3D NULL && annotate_opts.code_with_type && + !dso__debuginfo_warned(dso)) { + ui__warning("DWARF debuginfo not found.\n\n" + "Data-type in this DSO will not be displayed.\n" + "Please make sure to have debug information."); + dso__set_debuginfo_warned(dso); + } +} + static int annotate_browser__run(struct annotate_browser *browser, struct evsel *evsel, struct hist_browser_timer *hbt) @@ -842,6 +856,8 @@ static int annotate_browser__run(struct annotate_browse= r *browser, =20 annotation_br_cntr_abbr_list(&br_cntr_text, evsel, false); =20 + annotate_browser__debuginfo_warning(browser); + while (1) { key =3D ui_browser__run(&browser->b, delay_secs); =20 @@ -1036,6 +1052,7 @@ static int annotate_browser__run(struct annotate_brow= ser *browser, if (browser->dbg =3D=3D NULL) browser->dbg =3D debuginfo__new(dso__long_name(map__dso(ms->map))); annotate_browser__show(&browser->b, title, help); + annotate_browser__debuginfo_warning(browser); continue; case K_LEFT: case '<': diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 3457d713d3c56df6..7df1673f08d3ddb4 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -299,6 +299,7 @@ DECLARE_RC_STRUCT(dso) { u8 hit:1; u8 annotate_warned:1; u8 auxtrace_warned:1; + u8 debuginfo_warned:1; u8 short_name_allocated:1; u8 long_name_allocated:1; u8 is_64_bit:1; @@ -362,6 +363,16 @@ static inline void dso__set_annotate_warned(struct dso= *dso) RC_CHK_ACCESS(dso)->annotate_warned =3D 1; } =20 +static inline bool dso__debuginfo_warned(const struct dso *dso) +{ + return RC_CHK_ACCESS(dso)->debuginfo_warned; +} + +static inline void dso__set_debuginfo_warned(struct dso *dso) +{ + RC_CHK_ACCESS(dso)->debuginfo_warned =3D 1; +} + static inline bool dso__auxtrace_warned(const struct dso *dso) { return RC_CHK_ACCESS(dso)->auxtrace_warned; --=20 2.50.1 From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E3D51EA7D2; Sat, 16 Aug 2025 03:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314210; cv=none; b=RsM45SE6A20SNNpzRIhfzeu52azSHFoqvIYXzyMZj2HQziJz7Y6Te1KFKd4uDoDpOFTs1NdEMoD+XD9hMhFPcWGSRpSCwrjMN6dt17GN7sh5Ws/10lQSS/bZSc1pDNacVk67ez3X7kyJeApq1C27OzJy+UFXkxsUxYFZES6FH94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314210; c=relaxed/simple; bh=RAhFOShrd57RG4i4WBYOJrKz76jaNj/ofUtwL8psRyU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fta5zOcVTl/dvj+h2PXqu7zX0UA/OmXCyiPt2of4fgTGwRpsyAo4O+7nHEfVTUz8DbSD39fqJchOdYpEo5TPxCy5bClD8IJ3YHclPR0xWzOSGQijSwmav7YTc2HZB5fG+sazbi82yHoMSI6ALFyqhfZ94iRn2dJ1fmr2C/pmvlQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g0ZAg+KB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="g0ZAg+KB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2295C4CEF6; Sat, 16 Aug 2025 03:16:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314210; bh=RAhFOShrd57RG4i4WBYOJrKz76jaNj/ofUtwL8psRyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g0ZAg+KBVUHaOH4FakMcg5AAiEnnT9zqlk1s1InmACeJi6IliQ3iDSTfbAruRx+ZC XCiSodYXdHsU62RNjXA22hDRrGcqgkhqCHLwspuCzp+kCWFvU/EjVf1hdx2iwfSr9m 8fXSMwYJEszqml/FShjUphuUe+4CVjGBuMRB+zFwC5t6rbmXL0qmbskpz0vORfkJlY tbJvYSNFI1j5JYpEBNlhqja0ILZlBHSQBZiwaEqb0semqHi1WYTw4atMTGzsiCGK7A JwtjuVMYgpjY6E0pkuWC4ladWP3vom4fzMXaymizXl7B+GUo1dzx3yoHUzOVEt1k6o jRA1qhmsXg1EQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 10/12] perf annotate: Hide data-type for stack operation and canary Date: Fri, 15 Aug 2025 20:16:33 -0700 Message-ID: <20250816031635.25318-11-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's mostly unnecessary to print when it has no actual type information like in the stack operations and canary. Let's have them if -v option is given. Before: $ perf annotate --code-with-type ... : 0 0xd640 <_dl_relocate_object>: 0.00 : 0: endbr64 0.00 : 4: pushq %rbp # data-type: (stack operati= on) 0.00 : 5: movq %rsp, %rbp 0.00 : 8: pushq %r15 # data-type: (stack operati= on) 0.00 : a: pushq %r14 # data-type: (stack operati= on) 0.00 : c: pushq %r13 # data-type: (stack operati= on) 0.00 : e: pushq %r12 # data-type: (stack operati= on) 0.00 : 10: pushq %rbx # data-type: (stack operati= on) 0.00 : 11: subq $0xf8, %rsp ... 0.00 : d4: testl %eax, %eax 0.00 : d6: jne 0xf424 0.00 : dc: movq 0xf0(%r14), %rbx # data-type= : struct link_map +0xf0 0.00 : e3: testq %rbx, %rbx 0.00 : e6: jne 0xf2dd 0.00 : ec: cmpq $0, 0xf8(%r14) # data-type: struct= link_map +0xf8 ... After: : 0 0xd640 <_dl_relocate_object>: 0.00 : 0: endbr64 0.00 : 4: pushq %rbp 0.00 : 5: movq %rsp, %rbp 0.00 : 8: pushq %r15 0.00 : a: pushq %r14 0.00 : c: pushq %r13 0.00 : e: pushq %r12 0.00 : 10: pushq %rbx 0.00 : 11: subq $0xf8, %rsp ... 0.00 : d4: testl %eax, %eax 0.00 : d6: jne 0xf424 0.00 : dc: movq 0xf0(%r14), %rbx # data-type= : struct link_map +0xf0 0.00 : e3: testq %rbx, %rbx 0.00 : e6: jne 0xf2dd 0.00 : ec: cmpq $0, 0xf8(%r14) # data-type: struct= link_map +0xf8 ... Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 99e976d254493de2..ea68b32da7ce584a 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -765,6 +765,17 @@ __hist_entry__get_data_type(struct hist_entry *he, str= uct arch *arch, struct debuginfo *dbg, struct disasm_line *dl, int *type_offset); =20 +static bool needs_type_info(struct annotated_data_type *data_type) +{ + if (data_type =3D=3D NULL || data_type =3D=3D NO_TYPE) + return false; + + if (verbose) + return true; + + return (data_type !=3D &stackop_type) && (data_type !=3D &canary_type); +} + static int annotation_line__print(struct annotation_line *al, struct annotation_print= _data *apd, struct annotation_options *opts, int printed, @@ -844,7 +855,7 @@ annotation_line__print(struct annotation_line *al, stru= ct annotation_print_data =20 data_type =3D __hist_entry__get_data_type(apd->he, apd->arch, apd->dbg, dl, &offset); - if (data_type && data_type !=3D NO_TYPE) { + if (needs_type_info(data_type)) { char buf[4096]; =20 printf("\t\t# data-type: %s", @@ -1958,7 +1969,7 @@ static int disasm_line__snprint_type_info(struct disa= sm_line *dl, return 1; =20 data_type =3D __hist_entry__get_data_type(apd->he, apd->arch, apd->dbg, d= l, &offset); - if (data_type =3D=3D NULL || data_type =3D=3D NO_TYPE) + if (!needs_type_info(data_type)) return 1; =20 printed =3D scnprintf(buf, len, "\t\t# data-type: %s", data_type->self.ty= pe_name); --=20 2.50.1 From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D0DF15ECD7; Sat, 16 Aug 2025 03:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314210; cv=none; b=iYluR3vu6k9ggcq402NG6hLEAT2yMTKa/NGpXqu8L3EX+zdjXuxUCDNtbJLKWyo0FsPKhLBrcnKl4UnDFq1I8didzQ8XU4GEuoSa9uAtAkogsUjpwAA1k480YLk6MZESztg7ZLD3can5gps38WDojHfzRluMvTZPqHbHgAONeqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314210; c=relaxed/simple; bh=TFn+AkeCWJxWEIXjxpP39LZNlBV3hJRx78OUGBy8puE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bcoXe53fq34zyx8Nco6vTtHcUEky0AV5NIEMjw9vmXKwooTs2KbgWnSQXyVWtM4UAM/At5wpu8DgtndwqJFr7PjvtRRh7C6jDKwHBDMrPJKOpgdwCXpiytZRy0DoWlVxjqHKIOdoVrwAiiHECmg92O5ERA0Wuck/QC1wwptPsMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cmphe5G4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cmphe5G4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33AC2C4CEF7; Sat, 16 Aug 2025 03:16:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314210; bh=TFn+AkeCWJxWEIXjxpP39LZNlBV3hJRx78OUGBy8puE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cmphe5G4FucFklBNAoa04onGP4LfkrGx5Alg4J42pe9d4T9tEM8WrtCxF2qztGN4X 6ZehTEX+VxW+gzoLArUTY/+dTiXvyAuqXKyArWPWMb2l8GseCNdaH7vIPtLdgEKkW4 0esctm0r9dtcQCrAiy3EEWnseVZSsh72r4dhGnHVXivYVNyNaCmmcHVXAVaFGYMnfc XEgP3pne1K/wm67bONP4/NNR+bgU6i5zZpsxKiUNnIHbZW3GIYllG9H+XQkcLuWC0U 6wprYftWjXhgb3BIbcAgeytp6PHZiEiaKtgWaJ73cDg1SFG0T5xcf1PK1DgtI++tm0 dvJOMcujInE/Q== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 11/12] perf annotate: Add dso__debuginfo() helper Date: Fri, 15 Aug 2025 20:16:34 -0700 Message-ID: <20250816031635.25318-12-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It'd be great if it can get the correct debug information using DSO build-Id not just the path name. Instead of adding new callsites of debuginfo__new(), let's add dso__debuginfo() which can hide the access using the pathname and help the future conversion. Suggested-by: Ian Rogers Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/annotate.c | 4 ++-- tools/perf/util/annotate.c | 6 +++--- tools/perf/util/dso.h | 10 ++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index e3e7004f32251666..9aa3c1ba22f52789 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -1050,7 +1050,7 @@ static int annotate_browser__run(struct annotate_brow= ser *browser, case 'T': annotate_opts.code_with_type ^=3D 1; if (browser->dbg =3D=3D NULL) - browser->dbg =3D debuginfo__new(dso__long_name(map__dso(ms->map))); + browser->dbg =3D dso__debuginfo(map__dso(ms->map)); annotate_browser__show(&browser->b, title, help); annotate_browser__debuginfo_warning(browser); continue; @@ -1146,7 +1146,7 @@ int __hist_entry__tui_annotate(struct hist_entry *he,= struct map_symbol *ms, ui_helpline__push("Press ESC to exit"); =20 if (annotate_opts.code_with_type) - browser.dbg =3D debuginfo__new(dso__long_name(dso)); + browser.dbg =3D dso__debuginfo(dso); =20 browser.b.width =3D notes->src->widths.max_line_len; browser.b.nr_entries =3D notes->src->nr_entries; diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index ea68b32da7ce584a..bea3457a00632fd7 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1270,7 +1270,7 @@ int hist_entry__annotate_printf(struct hist_entry *he= , struct evsel *evsel) apd.addr_fmt_width =3D annotated_source__addr_fmt_width(¬es->src->sour= ce, notes->src->start); evsel__get_arch(evsel, &apd.arch); - apd.dbg =3D debuginfo__new(filename); + apd.dbg =3D dso__debuginfo(dso); =20 list_for_each_entry(pos, ¬es->src->source, node) { int err; @@ -1375,7 +1375,7 @@ static int symbol__annotate_fprintf2(struct symbol *s= ym, FILE *fp, =20 if (annotate_opts.code_with_type) { evsel__get_arch(apd->evsel, &apd->arch); - apd->dbg =3D debuginfo__new(dso__long_name(map__dso(apd->he->ms.map))); + apd->dbg =3D dso__debuginfo(map__dso(apd->he->ms.map)); } =20 list_for_each_entry(al, ¬es->src->source, node) { @@ -2882,7 +2882,7 @@ struct annotated_data_type *hist_entry__get_data_type= (struct hist_entry *he) di_cache.dso =3D dso__get(map__dso(ms->map)); =20 debuginfo__delete(di_cache.dbg); - di_cache.dbg =3D debuginfo__new(dso__long_name(di_cache.dso)); + di_cache.dbg =3D dso__debuginfo(di_cache.dso); } =20 if (di_cache.dbg =3D=3D NULL) { diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 7df1673f08d3ddb4..fd8e95de77f78dfc 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -10,6 +10,7 @@ #include #include #include "build-id.h" +#include "debuginfo.h" #include "mutex.h" #include =20 @@ -914,4 +915,13 @@ u64 dso__findnew_global_type(struct dso *dso, u64 addr= , u64 offset); bool perf_pid_map_tid(const char *dso_name, int *tid); bool is_perf_pid_map_name(const char *dso_name); =20 +/* + * In the future, we may get debuginfo using build-ID (w/o path). + * Add this helper is for the smooth conversion. + */ +static inline struct debuginfo *dso__debuginfo(struct dso *dso) +{ + return debuginfo__new(dso__long_name(dso)); +} + #endif /* __PERF_DSO */ --=20 2.50.1 From nobody Sat Oct 4 12:41:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 203EC1F2B8D; Sat, 16 Aug 2025 03:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314211; cv=none; b=H8JVBfYFRNHzDBjRKmE67GmISwybd1IH9EZy3LNqJJywA5taKGJ+oa1G1Z3AmvmkrvSP9A+Tl42Jz9bc1a8wNmX7PTdbE1vlIShd3StjOOcwrxFgYH7jWBhYkrFOo7ms74BPZf5zzRvD8/y9Pi17oosueIkJAYjwhEncmnnfAwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755314211; c=relaxed/simple; bh=d4MR7IarDUQWcMZzNUI3SIJc3F04Njj30gYOkDquj+w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jnsWFG8+aRjQVYFcgyyafcYeDQy2XWIuozIWXlh+3qQlaznLSxUB3aWT4+mwZCkmX8W4sVVpl5WdH1lwoeXVliZ0iV3xdKwis9eiUzVQSMuWmYbnwKf9i2p1AtJt2kRzcSjQxHAM+UzjveOhQn//POxIPNzMNLicWVe/lCidBjg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qBZ8Ur7d; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qBZ8Ur7d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5B06C4CEF5; Sat, 16 Aug 2025 03:16:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755314211; bh=d4MR7IarDUQWcMZzNUI3SIJc3F04Njj30gYOkDquj+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qBZ8Ur7d2FxufiFUAdLqc7iH6IyzGz2RMR46MZn/Z5Hi/oVfqSFfihtfep0uiszr7 Kugozp2I+DUeiY/JtHGyZ1sGivNDZ16/KLH6ylK92x7czhEpKax78o6UL7bQkx6/8C 8EgUhnx/nLfOd+JNSgb6cQkn2dXDp0R09WJsZlSOfy9UECcnIgKN83Vj54leY/JIYY Ih1aCz+ibKtL0J4LzVGtR8v3eMSdueZcRpNao8MY9FzRDEZRzIfgTe+KR6wv13ucPW b/zH3ysA5niWbwSXKDMqb0TIhGicQnQHIFKU+0PJjf5Uju5ibmUiNQCjKfrjni8sBT 1abTAwDkFkFjQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH v5 12/12] perf annotate: Use a hashmap to save type data Date: Fri, 15 Aug 2025 20:16:35 -0700 Message-ID: <20250816031635.25318-13-namhyung@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250816031635.25318-1-namhyung@kernel.org> References: <20250816031635.25318-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It can slowdown annotation browser if objdump is processing large DWARF data. Let's add a hashmap to save the data type info for each line. Note that this is needed for TUI only because stdio only processes each line once. TUI will display the same line whenever it refreshes the screen. Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/annotate.c | 34 ++++++++++++++++++++++++++++++- tools/perf/util/annotate.c | 27 ++++++++++++++++++++++-- tools/perf/util/annotate.h | 2 ++ 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 9aa3c1ba22f52789..9677a3763a290a3d 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -6,6 +6,7 @@ #include "../../util/debug.h" #include "../../util/debuginfo.h" #include "../../util/dso.h" +#include "../../util/hashmap.h" #include "../../util/hist.h" #include "../../util/sort.h" #include "../../util/map.h" @@ -15,6 +16,7 @@ #include "../../util/evlist.h" #include "../../util/thread.h" #include +#include #include #include #include @@ -36,6 +38,7 @@ struct annotate_browser { struct hist_entry *he; struct debuginfo *dbg; struct evsel *evsel; + struct hashmap *type_hash; bool searching_backwards; char search_bf[128]; }; @@ -43,6 +46,16 @@ struct annotate_browser { /* A copy of target hist_entry for perf top. */ static struct hist_entry annotate_he; =20 +static size_t type_hash(long key, void *ctx __maybe_unused) +{ + return key; +} + +static bool type_equal(long key1, long key2, void *ctx __maybe_unused) +{ + return key1 =3D=3D key2; +} + static inline struct annotation *browser__annotation(struct ui_browser *br= owser) { struct map_symbol *ms =3D browser->priv; @@ -130,6 +143,9 @@ static void annotate_browser__write(struct ui_browser *= browser, void *entry, int if (!browser->navkeypressed) ops.width +=3D 1; =20 + if (!IS_ERR_OR_NULL(ab->type_hash)) + apd.type_hash =3D ab->type_hash; + annotation_line__write(al, notes, &ops, &apd); =20 if (ops.current_entry) @@ -1051,6 +1067,10 @@ static int annotate_browser__run(struct annotate_bro= wser *browser, annotate_opts.code_with_type ^=3D 1; if (browser->dbg =3D=3D NULL) browser->dbg =3D dso__debuginfo(map__dso(ms->map)); + if (browser->type_hash =3D=3D NULL) { + browser->type_hash =3D hashmap__new(type_hash, type_equal, + /*ctx=3D*/NULL); + } annotate_browser__show(&browser->b, title, help); annotate_browser__debuginfo_warning(browser); continue; @@ -1145,8 +1165,10 @@ int __hist_entry__tui_annotate(struct hist_entry *he= , struct map_symbol *ms, =20 ui_helpline__push("Press ESC to exit"); =20 - if (annotate_opts.code_with_type) + if (annotate_opts.code_with_type) { browser.dbg =3D dso__debuginfo(dso); + browser.type_hash =3D hashmap__new(type_hash, type_equal, /*ctx=3D*/NULL= ); + } =20 browser.b.width =3D notes->src->widths.max_line_len; browser.b.nr_entries =3D notes->src->nr_entries; @@ -1159,6 +1181,16 @@ int __hist_entry__tui_annotate(struct hist_entry *he= , struct map_symbol *ms, ret =3D annotate_browser__run(&browser, evsel, hbt); =20 debuginfo__delete(browser.dbg); + + if (!IS_ERR_OR_NULL(browser.type_hash)) { + struct hashmap_entry *cur; + size_t bkt; + + hashmap__for_each_entry(browser.type_hash, cur, bkt) + free(cur->pvalue); + hashmap__free(browser.type_hash); + } + if (not_annotated && !notes->src->tried_source) annotated_source__purge(notes->src); =20 diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index bea3457a00632fd7..77414e04d99bb4f2 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1954,11 +1954,17 @@ int annotation_br_cntr_entry(char **str, int br_cnt= r_nr, return -ENOMEM; } =20 +struct type_hash_entry { + struct annotated_data_type *type; + int offset; +}; + static int disasm_line__snprint_type_info(struct disasm_line *dl, char *buf, int len, struct annotation_print_data *apd) { - struct annotated_data_type *data_type; + struct annotated_data_type *data_type =3D NULL; + struct type_hash_entry *entry =3D NULL; char member[256]; int offset =3D 0; int printed; @@ -1968,7 +1974,24 @@ static int disasm_line__snprint_type_info(struct dis= asm_line *dl, if (!annotate_opts.code_with_type || apd->dbg =3D=3D NULL) return 1; =20 - data_type =3D __hist_entry__get_data_type(apd->he, apd->arch, apd->dbg, d= l, &offset); + if (apd->type_hash) { + hashmap__find(apd->type_hash, dl->al.offset, &entry); + if (entry !=3D NULL) { + data_type =3D entry->type; + offset =3D entry->offset; + } + } + if (data_type =3D=3D NULL) + data_type =3D __hist_entry__get_data_type(apd->he, apd->arch, apd->dbg, = dl, &offset); + if (apd->type_hash && entry =3D=3D NULL) { + entry =3D malloc(sizeof(*entry)); + if (entry !=3D NULL) { + entry->type =3D data_type; + entry->offset =3D offset; + hashmap__add(apd->type_hash, dl->al.offset, entry); + } + } + if (!needs_type_info(data_type)) return 1; =20 diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 86e858f5bf173152..eaf6c8aa7f473959 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -204,6 +204,8 @@ struct annotation_print_data { struct evsel *evsel; struct arch *arch; struct debuginfo *dbg; + /* save data type info keyed by al->offset */ + struct hashmap *type_hash; /* It'll be set in hist_entry__annotate_printf() */ int addr_fmt_width; }; --=20 2.50.1