Re: [PATCH 2/2] perf/annotate: Fix missing branch counter column in TUI mode
From: Mi, Dapeng
Date: Tue Apr 14 2026 - 22:32:03 EST
On 4/11/2026 3:40 AM, Thomas Falcon wrote:
> 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.
>
> Signed-off-by: Thomas Falcon <thomas.falcon@xxxxxxxxx>
> ---
> tools/perf/builtin-annotate.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
> index 5e57b78548f4..7fe23b05306f 100644
> --- a/tools/perf/builtin-annotate.c
> +++ b/tools/perf/builtin-annotate.c
> @@ -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.
> + 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)