perf script: Add missed "+" if br_cntr reaches upper limit
PATCH 1/2 perf script: Add missed "+" if br_cntr reaches upper limit
From: Dapeng Mi <[email protected]>
Add missed "+" if br_cntr reaches upper limit.
--- tools/perf/builtin-script.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +6 -2
@@ -1287,8 +1287,12 @@ static int ip__fprintf_jump(uint64_t ip, struct branch_entry *en,if (!verbose) {for (j =0 ; j < num; j++) printed +=fprintf (fp,"%s" , pos->abbr_name); - }else - printed +=fprintf (fp,"%s %d " , pos->name, num); +if (num == mask) + printed +=fprintf (fp,"+" ); + }else { + printed +=fprintf (fp,"%s %d%s" , pos->name, + num, num == mask ?"+ " :" " ); + } }if (numprinted ==0 && !verbose) printed +=fprintf (fp,"-" );
Signature · 1 line
2.43.0
PATCH 2/2 perf/annotate: Fix missing branch counter column in TUI mode
perf annotate checks that evlist->nr_br_cntr has been incremented to determine whether to show branch counter information. However, this data is not populated until after the check when events are processed. Therefore, this counter will always be less than zero and the Branch Count column is never shown. Do this check after events have been processed and branch counter data is updated.
--- tools/perf/builtin-annotate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/builtin-annotate.c +3 -2
@@ -563,6 +563,9 @@ static int __cmd_annotate(struct perf_annotate *ann)if (ret) goto out; +if (session->evlist->nr_br_cntr >0 ) + annotate_opts.show_br_cntr = true; +if (dump_trace) {perf_session__fprintf_nr_events (session, stdout);evlist__fprintf_nr_events (session->evlist, stdout);
@@ -928,8 +931,6 @@ int cmd_annotate(int argc, const char **argv)*/ if ((use_browser ==1 || annotate.use_stdio2) && annotate.has_br_stack) { sort__mode =SORT_MODE__BRANCH ; -if (annotate.session->evlist->nr_br_cntr >0 ) - annotate_opts.show_br_cntr = true; }if (setup_sorting (/*evlist=*/ NULL ,perf_session__env (annotate.session)) <0 )
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 2/2] perf/annotate: Fix missing branch counter column in TUI mode
Sashiko AI review found 1 potential issue(s): - [Medium] The branch counter column is now enabled in standard stdio mode where it cannot be populated, resulting in a useless empty column in the…
Sashiko AI review found 1 potential issue(s):
- [Medium] The branch counter column is now enabled in standard stdio mode where it cannot be populated, resulting in a useless empty column in the output. --
commit afd424a34255fcd5587246caa606560bc9b916c8
Author: Thomas Falcon <[email protected]>
perf/annotate: Fix missing branch counter column in TUI mode
This commit moves the check for enabling the branch counter column into __cmd_annotate() so it occurs after events have been processed and the counter is updated.
tools/perf/builtin-annotate.c static int __cmd_annotate(struct perf_annotate *ann) · line 568
Quoted 11 lines
tools/perf/builtin-annotate.c +3
-0@@ -563,6 +563,9 @@ static int __cmd_annotate(struct perf_annotate *ann)if (ret) goto out; +if (session->evlist->nr_br_cntr >0 ) + annotate_opts.show_br_cntr = true; +
Will this cause an empty branch counter column to be displayed in standard stdio mode?
The original code restricted this check to TUI and stdio2 modes where use_browser == 1 or annotate.use_stdio2 is true. By moving the assignment here, it becomes unconditional.
In standard stdio mode, process_branch_callback() is skipped when adding samples, so branch stack data is not aggregated into the annotation notes. This leaves the counter data at 0 for all instructions. Could this result in the output rendering the column title but printing only empty spaces for all the rows?
[ ... ]
Quoted 9 lines
tools/perf/builtin-annotate.c +0
-2@@ -928,8 +931,6 @@ int cmd_annotate(int argc, const char **argv)*/ if ((use_browser ==1 || annotate.use_stdio2) && annotate.has_br_stack) { sort__mode =SORT_MODE__BRANCH ; -if (annotate.session->evlist->nr_br_cntr >0 ) - annotate_opts.show_br_cntr = true; }if (setup_sorting (/*evlist=*/ NULL ,perf_session__env (annotate.session)) <0 )
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/2] perf/annotate: Fix missing branch counter column in TUI mode
Quoted 26 lines · On Fri, 2026-04-10 at 20:01 +0000, [email protected] wrote:
Sashiko AI review found 1 potential issue(s):
- [Medium] The branch counter column is now enabled in standard stdio mode where it cannot be populated, resulting in a useless empty column in the output.
--commit
afd424a34255fcd5587246caa606560bc9b916c8
Author: Thomas Falcon <[email protected]>perf/annotate: Fix missing branch counter column in TUI mode
This commit moves the check for enabling the branch counter column into
__cmd_annotate()so it occurs after events have been processed and the
counter is updated.Quoted 9 lines
tools/perf/builtin- renamed from tools/perf/builtin-annotate.c +0
-0
annotate.c
index5e57b78548f42..7fe23b05306f8100644tools/perf/builtin-annotate.c +0
-0@@ -563,6 +563,9 @@ static int __cmd_annotate(struct perf_annotate *ann) if (ret) goto out;
Quoted 8 lines
tools/perf/builtin-annotate.c static int __cmd_annotate(struct perf_annotate *ann) · line 568
Quoted 4 lines
tools/perf/builtin-annotate.c +3
-0+if (session->evlist->nr_br_cntr >0 ) + annotate_opts.show_br_cntr = true; +Will this cause an empty branch counter column to be displayed in standard
stdio mode?
Oops, this was an older version, I'll resend with an updated one.
Thanks,
Tom
Quoted 30 lines
The original code restricted this check to TUI and stdio2 modes where
use_browser== 1 or annotate.use_stdio2 is true. By moving the assignment
here, it becomes unconditional.In standard stdio mode,
process_branch_callback()is skipped when adding
samples, so branch stack data is not aggregated into the annotation notes.
This leaves the counter data at 0 for all instructions. Could this result
in the output rendering the column title but printing only empty spaces for
all the rows?[ ... ]
Quoted 11 lines
tools/perf/builtin-annotate.c +0
-0@@ -928,8 +931,6 @@ int cmd_annotate(int argc, const char **argv)*/ if ((
use_browser== 1 || annotate.use_stdio2) && annotate.has_br_stack) {
sort__mode=SORT_MODE__BRANCH;tools/perf/builtin-annotate.c +0
-2-if (annotate.session->evlist->nr_br_cntr >0 ) - annotate_opts.show_br_cntr = true;}
if (setup_sorting(/*evlist=*/NULL,perf_session__env(annotate.session)) < 0)
PATCH v2 2/2 perf/annotate: Fix missing branch counter column in TUI mode
In reply to Thomas Falconperf annotate checks that evlist->nr_br_cntr has been incremented to determine whether to show branch counter information. However, this data is not populated until after the check when events are processed. Therefore, this counter will always be less than zero and the Branch Count column is never shown. Do this check after events have been processed and branch counter data is updated.
---
v2: Sent an older version by mistake, updated to the latest version.
--- tools/perf/builtin-annotate.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
tools/perf/builtin-annotate.c +5 -4
@@ -563,6 +563,10 @@ static int __cmd_annotate(struct perf_annotate *ann)if (ret) goto out; +if ((use_browser ==1 || ann->use_stdio2) && ann->has_br_stack) +if (session->evlist->nr_br_cntr >0 ) + annotate_opts.show_br_cntr = true; +if (dump_trace) {perf_session__fprintf_nr_events (session, stdout);evlist__fprintf_nr_events (session->evlist, stdout);
@@ -926,11 +930,8 @@ int cmd_annotate(int argc, const char **argv)* branch counters, if the corresponding branch info is available * in the perf data in the TUI mode. */ -if ((use_browser ==1 || annotate.use_stdio2) && annotate.has_br_stack) { +if ((use_browser ==1 || annotate.use_stdio2) && annotate.has_br_stack) sort__mode =SORT_MODE__BRANCH ; -if (annotate.session->evlist->nr_br_cntr >0 ) - annotate_opts.show_br_cntr = true; - }if (setup_sorting (/*evlist=*/ NULL ,perf_session__env (annotate.session)) <0 )usage_with_options (annotate_usage, options);
Signature · 1 line
2.43.0
Re: [PATCH 2/2] perf/annotate: Fix missing branch counter column in TUI mode
In reply to Thomas FalconQuoted 17 lines · Thomas Falcon
perf annotate checks that
evlist->nr_br_cntrhas been incremented to determine whether to show branch counter information. However, this data is not populated until after the check when events are processed. Therefore, this counter will always be less than zero and the Branch Count column is never shown. Do this check after events have been processed and branch counter data is updated.Signed-off-by Thomas Falcon <[email protected]>--- tools/perf/builtin-annotate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)tools/perf/builtin-annotate.c +0
-0
tools/perf/builtin-annotate.c static int __cmd_annotate(struct perf_annotate *ann) · line 566
Quoted 4 lines
tools/perf/builtin-annotate.c +1
-0@@ -563,6 +563,9 @@ static int __cmd_annotate(struct perf_annotate *ann)if (ret) goto out; +if (session->evlist->nr_br_cntr >0 )
Do we need to check if annotate.has_br_stack is true before setting show_br_cntr to true? Thanks.
Quoted 14 lines
tools/perf/builtin-annotate.c +2
-2+ annotate_opts.show_br_cntr = true; +if (dump_trace) {perf_session__fprintf_nr_events (session, stdout);evlist__fprintf_nr_events (session->evlist, stdout);@@ -928,8 +931,6 @@ int cmd_annotate(int argc, const char **argv)*/ if ((use_browser ==1 || annotate.use_stdio2) && annotate.has_br_stack) { sort__mode =SORT_MODE__BRANCH ; -if (annotate.session->evlist->nr_br_cntr >0 ) - annotate_opts.show_br_cntr = true; }if (setup_sorting (/*evlist=*/ NULL ,perf_session__env (annotate.session)) <0 )