mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tianyou Li <tianyou.li@intel.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>
Cc: 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>,
	Kan Liang <kan.liang@linux.intel.com>,
	Ravi Bangoria <ravi.bangoria@amd.com>,
	tianyou.li@intel.com, wangyang.guo@intel.com, pan.deng@intel.com,
	zhiguo.zhou@intel.com, jiebin.sun@intel.com,
	thomas.falcon@intel.com, dapeng1.mi@intel.com,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v6 2/3] perf tools annotate: Fix a crash/hang when switch disassemble and source view
Date: Fri, 10 Oct 2025 16:35:48 +0800	[thread overview]
Message-ID: <20251010083549.1839330-2-tianyou.li@intel.com> (raw)
In-Reply-To: <aOTOEcNOiUiEJ9tz@google.com>

When perf report with annotation, press 'TAB' to navigate among hot lines,
press 's' to switch on the source view, then press 'TAB' again, the perf
report could crash or hang. The 'nd' and 'browser->curr_hot' need to be
updated when switch the disassemble and source view.

Signed-off-by: Tianyou Li <tianyou.li@intel.com>
---
 tools/perf/ui/browsers/annotate.c | 35 ++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 8fe699f98542..32da310b3b62 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -852,6 +852,30 @@ static void annotate_browser__debuginfo_warning(struct annotate_browser *browser
 	}
 }
 
+static u32 rb_node__get_idx_asm(struct rb_node *nd)
+{
+	struct annotation_line *al = NULL;
+
+	if (nd == NULL)
+		return 0;
+
+	al = rb_entry(nd, struct annotation_line, rb_node);
+
+	return al->idx_asm;
+}
+
+static struct rb_node *annotate_browser__rb_node_by_idx_asm(struct annotate_browser *browser,
+									u32 idx_asm)
+{
+	struct annotation_line *al = NULL;
+
+	if (idx_asm == 0)
+		return NULL;
+
+	al = annotate_browser__find_new_asm_line(browser, idx_asm);
+	return al ? &al->rb_node : NULL;
+}
+
 static int annotate_browser__run(struct annotate_browser *browser,
 				 struct evsel *evsel,
 				 struct hist_browser_timer *hbt)
@@ -969,8 +993,17 @@ static int annotate_browser__run(struct annotate_browser *browser,
 			nd = browser->curr_hot;
 			break;
 		case 's':
-			if (annotate_browser__toggle_source(browser, evsel))
+			u32 idx_asm_nd = rb_node__get_idx_asm(nd);
+			u32 idx_asm_curr_hot = rb_node__get_idx_asm(browser->curr_hot);
+
+			if (annotate_browser__toggle_source(browser, evsel)) {
 				ui_helpline__puts(help);
+				/* Update the annotation browser's rb_tree, and reset the nd */
+				annotate_browser__calc_percent(browser, evsel);
+				nd = annotate_browser__rb_node_by_idx_asm(browser, idx_asm_nd);
+				browser->curr_hot = annotate_browser__rb_node_by_idx_asm(browser,
+							idx_asm_curr_hot);
+			}
 			annotate__scnprintf_title(hists, title, sizeof(title));
 			annotate_browser__show(browser, title, help);
 			continue;
-- 
2.47.1


  parent reply	other threads:[~2025-10-10  7:42 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-01  7:51 [PATCH] perf tools c2c: Add annotation support to perf c2c report Tianyou Li
2025-08-19  8:00 ` [PATCH v2] " Tianyou Li
2025-09-03 13:50   ` Arnaldo Carvalho de Melo
2025-09-07 14:53     ` Li, Tianyou
2025-09-07 15:25     ` [PATCH v3] " Tianyou Li
2025-09-11 21:39       ` Namhyung Kim
2025-09-12 15:20         ` Li, Tianyou
2025-09-17  6:34           ` Namhyung Kim
2025-09-24  7:33             ` Li, Tianyou
2025-09-28  9:02             ` [PATCH v4] " Tianyou Li
2025-09-28  8:16               ` Li, Tianyou
2025-09-29  8:07                 ` Namhyung Kim
2025-09-30 11:41                   ` Li, Tianyou
2025-09-30 12:39                   ` [PATCH v5] " Tianyou Li
2025-10-03  5:05                     ` Namhyung Kim
2025-10-03 11:44                       ` Li, Tianyou
2025-10-07  8:23                         ` Namhyung Kim
2025-10-09  3:47                           ` Li, Tianyou
2025-10-09  4:28                           ` [PATCH v6] " Tianyou Li
2025-10-10  5:56                             ` Ravi Bangoria
2025-10-10  7:49                               ` Li, Tianyou
2025-10-10  8:33                           ` [PATCH v6 1/3] " Tianyou Li
2025-10-10  8:33                           ` [PATCH v6 2/3] perf tools annotate: Fix a crash/hang when switch disassemble and source view Tianyou Li
2025-10-10  8:33                           ` [PATCH v6 3/3] perf tools c2c: Highlight the contention line in the annotate browser Tianyou Li
2025-10-10  8:35                           ` [PATCH v6 1/3] perf tools c2c: Add annotation support to perf c2c report Tianyou Li
2025-10-10  8:35                           ` Tianyou Li [this message]
2025-10-10  8:35                           ` [PATCH v6 3/3] perf tools c2c: Highlight the contention line in the annotate browser Tianyou Li
2025-10-10 13:08                             ` Namhyung Kim
2025-10-11  8:16                               ` [PATCH v7 1/2] perf tools c2c: Add annotation support to perf c2c report Tianyou Li
2025-10-13  8:52                                 ` Ravi Bangoria
2025-10-13 13:43                                   ` Li, Tianyou
2025-10-13 14:48                                   ` [PATCH v8 " Tianyou Li
2025-10-20  2:12                                     ` Namhyung Kim
2025-10-13 14:48                                   ` [PATCH v8 2/2] perf tools c2c: Highlight the contention line in the annotate browser Tianyou Li
2025-10-11  8:16                               ` [PATCH v7 " Tianyou Li
2025-10-06 10:54                       ` [PATCH v5] perf tools c2c: Add annotation support to perf c2c report Ravi Bangoria
2025-10-09  5:34                         ` Li, Tianyou

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=20251010083549.1839330-2-tianyou.li@intel.com \
    --to=tianyou.li@intel.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dapeng1.mi@intel.com \
    --cc=irogers@google.com \
    --cc=jiebin.sun@intel.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --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=pan.deng@intel.com \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=thomas.falcon@intel.com \
    --cc=wangyang.guo@intel.com \
    --cc=zhiguo.zhou@intel.com \
    /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

all inboxes | Powered by JetHome®