From nobody Sat Feb 7 22:21:05 2026 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 95B1B13BADD; Thu, 11 Apr 2024 03:32:58 +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=1712806378; cv=none; b=kz3FAmbE94M4Bb5rNwGC6Z+yn6IenCe8iVWl89oaLasvi76hbKlbAcJ29isuvpJJiK9ALuQawSqnr/d6nIcdvJggg7g0uNIFEKyq+ic3M/D/6/CmJPuAAgdhoiTjBWjubRlx1vUTn4/+2rHfLCYcAMy/eTgc+mQ0X+s9hks1ui4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712806378; c=relaxed/simple; bh=iOCpCDUmajHA6Opq8WcJ6PcQv4ZZHQHjuT0DJJ405iw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ngQZZ1Ex0tp/+NFYtQCc91Kb5PnsxMPlHva3IbXUdfI4jirExbcVG9PBcZdj0XjjzBiRZFQVwuTnAbvHpLi2WNnMFJczcyx2rhajsTAIPDdGiUPUJ9zoVHpCZGslj29Ei3m+Yy5tcMEaJSUant8gQHhtabR/km8z2s+hSE7veyA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IARPqoAe; 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="IARPqoAe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA353C43390; Thu, 11 Apr 2024 03:32:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712806378; bh=iOCpCDUmajHA6Opq8WcJ6PcQv4ZZHQHjuT0DJJ405iw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IARPqoAeSRKcC1Y/goOtmb1IXci4uqF1C+BFBtBbFMGbU+WJmJ32+/7bWZL/1l3Wl s3UYT55fYjsEDDskCZ4uGI4QJS2U0te/kzJVLdKZGJYmBHormQgU7PW2KMtVDj6yoP ZHeqxprPyDPYZNIUpr1fZfAF+J2J8C1tNKIUAy8E7fmWpqzzaRFLxGwQJ34uzfYtIB 1sSo7X9cmxyjup4cRTaw57t5oI46vEZ/n4iCpBVvJeA6PWayIRF4xsMz2AeH/8ErGc Dug1bwnKPRjMPk+8S/lk6pCnpq/3WAGsQGpOX2YOx9BhxQqYdZow3cRnjpi2IzIAoh 6JqfpOsOMBCzA== 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 1/7] perf annotate-data: Skip sample histogram for stack canary Date: Wed, 10 Apr 2024 20:32:50 -0700 Message-ID: <20240411033256.2099646-2-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240411033256.2099646-1-namhyung@kernel.org> References: <20240411033256.2099646-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 a pseudo data type and has no field. Fixes: b3c95109c131 ("perf annotate-data: Add stack canary type") Signed-off-by: Namhyung Kim --- tools/perf/util/annotate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 11da27801d88..ec79c120a7d2 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2399,8 +2399,9 @@ struct annotated_data_type *hist_entry__get_data_type= (struct hist_entry *he) mem_type =3D find_data_type(&dloc); =20 if (mem_type =3D=3D NULL && is_stack_canary(arch, op_loc)) { - mem_type =3D &canary_type; - dloc.type_offset =3D 0; + istat->good++; + he->mem_type_off =3D 0; + return &canary_type; } =20 if (mem_type) --=20 2.44.0.478.gd926399ef9-goog From nobody Sat Feb 7 22:21:05 2026 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 C6D7313BAE5; Thu, 11 Apr 2024 03:32:58 +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=1712806378; cv=none; b=cTpEoCtCwk43FGuRNT4vYlLWQNYfTKnuvB1aP48EbNXGTRuG78mWUfZWBGEpcFMlCS2gXVIa3gUG5ATzqZuYshkMmfRbH1VOylx0diFHQNejr2FS8ErSgd0b3G+ZoXM2qeuiMs/1nd8lJ11fVpaxJTbQJbcBnoobw3Y/MzwULXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712806378; c=relaxed/simple; bh=E7MUbHglg5iWys9JXYDObrTkAuoigHes409w9J6EGEc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bjo0uOOpsakFSVn6nTbzuLX+h1xKQ2bbQ5oC2vN2HJvVNdnMG+ktMJCeaeHozdqGE+HX+it/1f9/cKOPypJneyZtxHsyQ1FSRe9dwPyCIZAs6o1RgIl0NR8T1hZpMaJ6I3AuPM49zM8dobl2Hu8vnhIgvG4CQpunZqbRbGGWjCw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ngVvk5vq; 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="ngVvk5vq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F85CC43399; Thu, 11 Apr 2024 03:32:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712806378; bh=E7MUbHglg5iWys9JXYDObrTkAuoigHes409w9J6EGEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ngVvk5vq9Y6CbMgZjWWsYxjtjK4/EdUjH75o2kERRsv0x6/5KAAJDjK8ZLxY2z/rW EyvE/G1p9gwBqVTqgGfS6Bq9iRVSlVP0ei6SxFEG85UwgnVGhYB3jOcW+ssj2CNjmQ QiIyTgFB/u0peIdYJXlJO9/gLfLjN3MYlDaEDtiHgVTt6dAWb1sCNszrY+amBYJ7xh 98h2w71Y2oB+cW7ZRiZYeHWuhznhi9CT7ACS5/XxOuyb00O+ddpNNln+kocglkpdpY /BvMYFQ5OUelsOV7wZk8YcXZPIx0oDh10viB9okTmGoNqt6z9M10AL44wy3MbENgQU 2BppXXCHiILig== 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 2/7] perf annotate: Show progress of sample processing Date: Wed, 10 Apr 2024 20:32:51 -0700 Message-ID: <20240411033256.2099646-3-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240411033256.2099646-1-namhyung@kernel.org> References: <20240411033256.2099646-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 'perf report', it can take a while to process samples. Show a progress window to inform users how that it is not stuck. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-annotate.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 16e1581207c9..332e1ddcacbd 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -37,6 +37,7 @@ #include "util/map_symbol.h" #include "util/branch.h" #include "util/util.h" +#include "ui/progress.h" =20 #include #include @@ -665,13 +666,23 @@ static int __cmd_annotate(struct perf_annotate *ann) evlist__for_each_entry(session->evlist, pos) { struct hists *hists =3D evsel__hists(pos); u32 nr_samples =3D hists->stats.nr_samples; + struct ui_progress prog; =20 if (nr_samples > 0) { total_nr_samples +=3D nr_samples; - hists__collapse_resort(hists, NULL); + + ui_progress__init(&prog, nr_samples, + "Merging related events..."); + hists__collapse_resort(hists, &prog); + ui_progress__finish(); + /* Don't sort callchain */ evsel__reset_sample_bit(pos, CALLCHAIN); - evsel__output_resort(pos, NULL); + + ui_progress__init(&prog, nr_samples, + "Sorting events for output..."); + evsel__output_resort(pos, &prog); + ui_progress__finish(); =20 /* * An event group needs to display other events too. --=20 2.44.0.478.gd926399ef9-goog From nobody Sat Feb 7 22:21:05 2026 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 99BB913BC1A; Thu, 11 Apr 2024 03:32:59 +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=1712806379; cv=none; b=soEhlo8rzKMnn26d8EJwHNI1kson9Ez1mGr2Jr/stUC2LQEXvMMLVT6PZCrOHbgwguoICeZtHyu9nB3W0l0uqFpkMNypdH5OEO9fGX2jfNm0Ooqn9+ozAyL4zOyp/6xuvRgArYo2yGAZPCXdDs7UZ3qSK3pma6zHKHCc1v6HI8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712806379; c=relaxed/simple; bh=QUqZPqNpv1B2WpvqTPpemc1xyxDVxJ3oUcE4o5/x8QI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L+MhVp702Zi05jO95GrW9N+Zm6yeO2BEqZKzs0LmHl6rwH8irtSrTeuhzMzkRi0MtLW+IPw3Q92Rd+zPIRs6y23F4syidPM8W7lznYtF1WmZHSDQIwvwpfJfBO2CYODR76QHywYqzBjZ/pvjv6Bbj63VWh3X9pjJ6ZKTrgrmB/c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sW8knkiQ; 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="sW8knkiQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD32BC433F1; Thu, 11 Apr 2024 03:32:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712806379; bh=QUqZPqNpv1B2WpvqTPpemc1xyxDVxJ3oUcE4o5/x8QI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sW8knkiQVOf6Ikdt4pI86QIYNEmQ2eLFIagIfi7KabXI4RnjmIsS2RaiGg0tm8Oxg eLSqEJ1ZDJ6+TJ2MF7HT84xlsu55QnbYmaIbKPlYrAclEnFHLg3bUTFmNjZke1dIY+ iDn+tFY1bVARfCic//GJu8k+waBJ7u0+G8LaJKSpJ9lfi6TtwcRHjjr2C36qedylxQ ZK9+i0w/o2DsNiukj5gdDqw6dlIQ32jOPyIWPLjEbCvCIBKBIlN0o9kcj180ExQCsH XCgxBh3Uh1L7GBe4fOXGZxB++Ij6guL6/yjqIrkEl11B5xx/Tg+bnvop1T0AYUPYB9 brscjNPurX3ug== 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 3/7] perf annotate-data: Add hist_entry__annotate_data_tty() Date: Wed, 10 Apr 2024 20:32:52 -0700 Message-ID: <20240411033256.2099646-4-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240411033256.2099646-1-namhyung@kernel.org> References: <20240411033256.2099646-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" And move the related code into util/annotate-data.c file. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-annotate.c | 106 +----------------------------- tools/perf/util/annotate-data.c | 112 ++++++++++++++++++++++++++++++++ tools/perf/util/annotate-data.h | 9 +++ 3 files changed, 122 insertions(+), 105 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 332e1ddcacbd..0812664faa54 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -329,108 +329,6 @@ static int hist_entry__tty_annotate(struct hist_entry= *he, return symbol__tty_annotate2(&he->ms, evsel); } =20 -static void print_annotated_data_header(struct hist_entry *he, struct evse= l *evsel) -{ - struct dso *dso =3D map__dso(he->ms.map); - int nr_members =3D 1; - int nr_samples =3D he->stat.nr_events; - int width =3D 7; - const char *val_hdr =3D "Percent"; - - if (evsel__is_group_event(evsel)) { - struct hist_entry *pair; - - list_for_each_entry(pair, &he->pairs.head, pairs.node) - nr_samples +=3D pair->stat.nr_events; - } - - printf("Annotate type: '%s' in %s (%d samples):\n", - he->mem_type->self.type_name, dso->name, nr_samples); - - if (evsel__is_group_event(evsel)) { - struct evsel *pos; - int i =3D 0; - - for_each_group_evsel(pos, evsel) - printf(" event[%d] =3D %s\n", i++, pos->name); - - nr_members =3D evsel->core.nr_members; - } - - if (symbol_conf.show_total_period) { - width =3D 11; - val_hdr =3D "Period"; - } else if (symbol_conf.show_nr_samples) { - width =3D 7; - val_hdr =3D "Samples"; - } - - printf("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D\n"); - printf("%*s %10s %10s %s\n", (width + 1) * nr_members, val_hdr, - "offset", "size", "field"); -} - -static void print_annotated_data_value(struct type_hist *h, u64 period, in= t nr_samples) -{ - double percent =3D h->period ? (100.0 * period / h->period) : 0; - const char *color =3D get_percent_color(percent); - - if (symbol_conf.show_total_period) - color_fprintf(stdout, color, " %11" PRIu64, period); - else if (symbol_conf.show_nr_samples) - color_fprintf(stdout, color, " %7d", nr_samples); - else - color_fprintf(stdout, color, " %7.2f", percent); -} - -static void print_annotated_data_type(struct annotated_data_type *mem_type, - struct annotated_member *member, - struct evsel *evsel, int indent) -{ - struct annotated_member *child; - struct type_hist *h =3D mem_type->histograms[evsel->core.idx]; - int i, nr_events =3D 1, samples =3D 0; - u64 period =3D 0; - int width =3D symbol_conf.show_total_period ? 11 : 7; - - for (i =3D 0; i < member->size; i++) { - samples +=3D h->addr[member->offset + i].nr_samples; - period +=3D h->addr[member->offset + i].period; - } - print_annotated_data_value(h, period, samples); - - if (evsel__is_group_event(evsel)) { - struct evsel *pos; - - for_each_group_member(pos, evsel) { - h =3D mem_type->histograms[pos->core.idx]; - - samples =3D 0; - period =3D 0; - for (i =3D 0; i < member->size; i++) { - samples +=3D h->addr[member->offset + i].nr_samples; - period +=3D h->addr[member->offset + i].period; - } - print_annotated_data_value(h, period, samples); - } - nr_events =3D evsel->core.nr_members; - } - - printf(" %10d %10d %*s%s\t%s", - member->offset, member->size, indent, "", member->type_name, - member->var_name ?: ""); - - if (!list_empty(&member->children)) - printf(" {\n"); - - list_for_each_entry(child, &member->children, node) - print_annotated_data_type(mem_type, child, evsel, indent + 4); - - if (!list_empty(&member->children)) - printf("%*s}", (width + 1) * nr_events + 24 + indent, ""); - printf(";\n"); -} - static void print_annotate_data_stat(struct annotated_data_stat *s) { #define PRINT_STAT(fld) if (s->fld) printf("%10d : %s\n", s->fld, #fld) @@ -571,9 +469,7 @@ static void hists__find_annotations(struct hists *hists, goto find_next; } =20 - print_annotated_data_header(he, evsel); - print_annotated_data_type(he->mem_type, &he->mem_type->self, evsel, 0); - printf("\n"); + hist_entry__annotate_data_tty(he, evsel); goto find_next; } =20 diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index b69a1cd1577a..b150137a92dc 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -19,6 +19,7 @@ #include "evlist.h" #include "map.h" #include "map_symbol.h" +#include "sort.h" #include "strbuf.h" #include "symbol.h" #include "symbol_conf.h" @@ -1710,3 +1711,114 @@ int annotated_data_type__update_samples(struct anno= tated_data_type *adt, h->addr[offset].period +=3D period; return 0; } + +static void print_annotated_data_header(struct hist_entry *he, struct evse= l *evsel) +{ + struct dso *dso =3D map__dso(he->ms.map); + int nr_members =3D 1; + int nr_samples =3D he->stat.nr_events; + int width =3D 7; + const char *val_hdr =3D "Percent"; + + if (evsel__is_group_event(evsel)) { + struct hist_entry *pair; + + list_for_each_entry(pair, &he->pairs.head, pairs.node) + nr_samples +=3D pair->stat.nr_events; + } + + printf("Annotate type: '%s' in %s (%d samples):\n", + he->mem_type->self.type_name, dso->name, nr_samples); + + if (evsel__is_group_event(evsel)) { + struct evsel *pos; + int i =3D 0; + + for_each_group_evsel(pos, evsel) + printf(" event[%d] =3D %s\n", i++, pos->name); + + nr_members =3D evsel->core.nr_members; + } + + if (symbol_conf.show_total_period) { + width =3D 11; + val_hdr =3D "Period"; + } else if (symbol_conf.show_nr_samples) { + width =3D 7; + val_hdr =3D "Samples"; + } + + printf("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D\n"); + printf("%*s %10s %10s %s\n", (width + 1) * nr_members, val_hdr, + "offset", "size", "field"); +} + +static void print_annotated_data_value(struct type_hist *h, u64 period, in= t nr_samples) +{ + double percent =3D h->period ? (100.0 * period / h->period) : 0; + const char *color =3D get_percent_color(percent); + + if (symbol_conf.show_total_period) + color_fprintf(stdout, color, " %11" PRIu64, period); + else if (symbol_conf.show_nr_samples) + color_fprintf(stdout, color, " %7d", nr_samples); + else + color_fprintf(stdout, color, " %7.2f", percent); +} + +static void print_annotated_data_type(struct annotated_data_type *mem_type, + struct annotated_member *member, + struct evsel *evsel, int indent) +{ + struct annotated_member *child; + struct type_hist *h =3D mem_type->histograms[evsel->core.idx]; + int i, nr_events =3D 1, samples =3D 0; + u64 period =3D 0; + int width =3D symbol_conf.show_total_period ? 11 : 7; + + for (i =3D 0; i < member->size; i++) { + samples +=3D h->addr[member->offset + i].nr_samples; + period +=3D h->addr[member->offset + i].period; + } + print_annotated_data_value(h, period, samples); + + if (evsel__is_group_event(evsel)) { + struct evsel *pos; + + for_each_group_member(pos, evsel) { + h =3D mem_type->histograms[pos->core.idx]; + + samples =3D 0; + period =3D 0; + for (i =3D 0; i < member->size; i++) { + samples +=3D h->addr[member->offset + i].nr_samples; + period +=3D h->addr[member->offset + i].period; + } + print_annotated_data_value(h, period, samples); + } + nr_events =3D evsel->core.nr_members; + } + + printf(" %10d %10d %*s%s\t%s", + member->offset, member->size, indent, "", member->type_name, + member->var_name ?: ""); + + if (!list_empty(&member->children)) + printf(" {\n"); + + list_for_each_entry(child, &member->children, node) + print_annotated_data_type(mem_type, child, evsel, indent + 4); + + if (!list_empty(&member->children)) + printf("%*s}", (width + 1) * nr_events + 24 + indent, ""); + printf(";\n"); +} + +int hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *evs= el) +{ + print_annotated_data_header(he, evsel); + print_annotated_data_type(he->mem_type, &he->mem_type->self, evsel, 0); + printf("\n"); + + return 0; +} diff --git a/tools/perf/util/annotate-data.h b/tools/perf/util/annotate-dat= a.h index fe1e53d6e8c7..01489db267d4 100644 --- a/tools/perf/util/annotate-data.h +++ b/tools/perf/util/annotate-data.h @@ -10,6 +10,7 @@ struct annotated_op_loc; struct debuginfo; struct evsel; +struct hist_entry; struct map_symbol; struct thread; =20 @@ -156,6 +157,8 @@ void annotated_data_type__tree_delete(struct rb_root *r= oot); /* Release all global variable information in the tree */ void global_var_type__tree_delete(struct rb_root *root); =20 +int hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *evs= el); + #else /* HAVE_DWARF_SUPPORT */ =20 static inline struct annotated_data_type * @@ -182,6 +185,12 @@ static inline void global_var_type__tree_delete(struct= rb_root *root __maybe_unu { } =20 +static inline int hist_entry__annotate_data_tty(struct hist_entry *he __ma= ybe_unused, + struct evsel *evsel __maybe_unused) +{ + return -1; +} + #endif /* HAVE_DWARF_SUPPORT */ =20 #endif /* _PERF_ANNOTATE_DATA_H */ --=20 2.44.0.478.gd926399ef9-goog From nobody Sat Feb 7 22:21:05 2026 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 2E07813BC33; Thu, 11 Apr 2024 03:32:59 +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=1712806380; cv=none; b=DxsstNmB28IrbbAan3+hviqff6e2mu8g2WWVVr+XXk+M2Qbw6z/Aup0bVBpD+QcQLzJRVnmbi3PROtFgxjDpiPB++C7Sfvk2sraMZRNPJdbtu3FBzC3J29xc6M8NAjNwTYeWsqAo4a4fSII0VYat/rpo09gK4B/qYson420bFq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712806380; c=relaxed/simple; bh=pVSYmnJQSf5CJbwDyiFLWmg1TbKOV3feN7stKZJIyLY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hf1SPywt11eCl6qBmnOiKFN+7Oo31tXBxy+0LSWAyGr+qyLCwP2PBQI3FdMQDUnklTXemKu+oG4XGuXxEnQfIugBQrw58lv/nrPWgtPcrnibcHJl+OiO5FDvkRJbpPirqKAnXNYuGFj39EBkOUgrnuGGjfTKIgbzJchAUogZt3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f8vgQq5P; 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="f8vgQq5P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B7D4C43330; Thu, 11 Apr 2024 03:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712806379; bh=pVSYmnJQSf5CJbwDyiFLWmg1TbKOV3feN7stKZJIyLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f8vgQq5Pw8SNDgIUAKPOg1vIgrha5gTsIPvehrkFVz7yoB1xg2oe1izG8hbzUVgDc despZ4BWZwtzuFAVi8JeUbLg5OVnu/HiQNV3OYxICszHdF1hWCXHNrZNFXYmUmzcHr ddsDCeU5TJ0RtjDzXZhnVy8/K1U/SODNORCQqFNZbgmsr7NbflCo/auLD5uzNWDDNl DT8ym7VI38sHa5gyLqSyva7hNn9BwigzexGpyT4OF6s/vFLhsNDzeZ/3g3mCOu2xev G5QnJ92m8CHD5BT5UryxAewAW5UjMojHOrXRHBwx2sgxaBGTWHpZX2oH+4KNuJoNZv ILBfK3qp9ALJg== 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, Arnaldo Carvalho de Melo Subject: [PATCH 4/7] perf annotate-data: Add hist_entry__annotate_data_tui() Date: Wed, 10 Apr 2024 20:32:53 -0700 Message-ID: <20240411033256.2099646-5-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240411033256.2099646-1-namhyung@kernel.org> References: <20240411033256.2099646-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 profiling output on TUI. Testing from Arnaldo: First make sure that the debug information for your workload binaries in embedded in them by building it with '-g' or install the debuginfo packages, since our workload is 'find': root@number:~# type find find is hashed (/usr/bin/find) root@number:~# rpm -qf /usr/bin/find findutils-4.9.0-5.fc39.x86_64 root@number:~# dnf debuginfo-install findutils root@number:~# Then collect some data: root@number:~# echo 1 > /proc/sys/vm/drop_caches root@number:~# perf mem record find / > /dev/null [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.331 MB perf.data (3982 samples) ] root@number:~# Finally do data-type annotation with the following command, that will default, as 'perf report' to the --tui mode, with lines colored to highlight the hotspots, etc. root@number:~# perf annotate --data-type Annotate type: 'struct predicate' (58 samples) Percent Offset Size Field 100.00 0 312 struct predicate { 0.00 0 8 PRED_FUNC pred_func; 0.00 8 8 char* p_name; 0.00 16 4 enum predicate_type p_type; 0.00 20 4 enum predicate_precedence p= _prec; 0.00 24 1 _Bool side_effects; 0.00 25 1 _Bool no_default_print; 0.00 26 1 _Bool need_stat; 0.00 27 1 _Bool need_type; 0.00 28 1 _Bool need_inum; 0.00 32 4 enum EvaluationCost p_cost; 0.00 36 4 float est_success_rate; 0.00 40 1 _Bool literal_control_chars; 0.00 41 1 _Bool artificial; 0.00 48 8 char* arg_text; Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-annotate.c | 30 ++- tools/perf/ui/browsers/Build | 1 + tools/perf/ui/browsers/annotate-data.c | 282 +++++++++++++++++++++++++ tools/perf/util/annotate-data.c | 3 +- tools/perf/util/annotate-data.h | 13 ++ 5 files changed, 324 insertions(+), 5 deletions(-) create mode 100644 tools/perf/ui/browsers/annotate-data.c diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 0812664faa54..6f7104f06c42 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -469,8 +469,32 @@ static void hists__find_annotations(struct hists *hist= s, goto find_next; } =20 - hist_entry__annotate_data_tty(he, evsel); - goto find_next; + if (use_browser =3D=3D 1) + key =3D hist_entry__annotate_data_tui(he, evsel, NULL); + else + key =3D hist_entry__annotate_data_tty(he, evsel); + + switch (key) { + case -1: + if (!ann->skip_missing) + return; + /* fall through */ + case K_RIGHT: + case '>': + next =3D rb_next(nd); + break; + case K_LEFT: + case '<': + next =3D rb_prev(nd); + break; + default: + return; + } + + if (next !=3D NULL) + nd =3D next; + + continue; } =20 if (use_browser =3D=3D 2) { @@ -873,9 +897,7 @@ int cmd_annotate(int argc, const char **argv) use_browser =3D 2; #endif =20 - /* FIXME: only support stdio for now */ if (annotate.data_type) { - use_browser =3D 0; annotate_opts.annotate_src =3D false; symbol_conf.annotate_data_member =3D true; symbol_conf.annotate_data_sample =3D true; diff --git a/tools/perf/ui/browsers/Build b/tools/perf/ui/browsers/Build index 7a1d5ddaf688..2608b5da3167 100644 --- a/tools/perf/ui/browsers/Build +++ b/tools/perf/ui/browsers/Build @@ -1,4 +1,5 @@ perf-y +=3D annotate.o +perf-y +=3D annotate-data.o perf-y +=3D hists.o perf-y +=3D map.o perf-y +=3D scripts.o diff --git a/tools/perf/ui/browsers/annotate-data.c b/tools/perf/ui/browser= s/annotate-data.c new file mode 100644 index 000000000000..fefacaaf16db --- /dev/null +++ b/tools/perf/ui/browsers/annotate-data.c @@ -0,0 +1,282 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include + +#include "ui/browser.h" +#include "ui/helpline.h" +#include "ui/keysyms.h" +#include "ui/ui.h" +#include "util/annotate.h" +#include "util/annotate-data.h" +#include "util/evsel.h" +#include "util/sort.h" + +struct annotated_data_browser { + struct ui_browser b; + struct list_head entries; +}; + +struct browser_entry { + struct list_head node; + struct annotated_member *data; + struct type_hist_entry hists; + int indent; +}; + +static void update_hist_entry(struct type_hist_entry *dst, + struct type_hist_entry *src) +{ + dst->nr_samples +=3D src->nr_samples; + dst->period +=3D src->period; +} + +static int get_member_overhead(struct annotated_data_type *adt, + struct browser_entry *entry, + struct evsel *evsel) +{ + struct annotated_member *member =3D entry->data; + int i; + + for (i =3D 0; i < member->size; i++) { + struct type_hist *h; + int offset =3D member->offset + i; + + h =3D adt->histograms[evsel->core.idx]; + update_hist_entry(&entry->hists, &h->addr[offset]); + } + return 0; +} + +static int add_child_entries(struct annotated_data_browser *browser, + struct annotated_data_type *adt, + struct annotated_member *member, + struct evsel *evsel, int indent) +{ + struct annotated_member *pos; + struct browser_entry *entry; + int nr_entries =3D 0; + + entry =3D zalloc(sizeof(*entry)); + if (entry =3D=3D NULL) + return -1; + + entry->data =3D member; + entry->indent =3D indent; + if (get_member_overhead(adt, entry, evsel) < 0) { + free(entry); + return -1; + } + + list_add_tail(&entry->node, &browser->entries); + nr_entries++; + + list_for_each_entry(pos, &member->children, node) { + int nr =3D add_child_entries(browser, adt, pos, evsel, indent + 1); + + if (nr < 0) + return nr; + + nr_entries +=3D nr; + } + + /* add an entry for the closing bracket ("}") */ + if (!list_empty(&member->children)) { + entry =3D zalloc(sizeof(*entry)); + if (entry =3D=3D NULL) + return -1; + + entry->indent =3D indent; + list_add_tail(&entry->node, &browser->entries); + nr_entries++; + } + + return nr_entries; +} + +static int annotated_data_browser__collect_entries(struct annotated_data_b= rowser *browser) +{ + struct hist_entry *he =3D browser->b.priv; + struct annotated_data_type *adt =3D he->mem_type; + struct evsel *evsel =3D hists_to_evsel(he->hists); + + INIT_LIST_HEAD(&browser->entries); + browser->b.entries =3D &browser->entries; + browser->b.nr_entries =3D add_child_entries(browser, adt, &adt->self, + evsel, /*indent=3D*/0); + return 0; +} + +static void annotated_data_browser__delete_entries(struct annotated_data_b= rowser *browser) +{ + struct browser_entry *pos, *tmp; + + list_for_each_entry_safe(pos, tmp, &browser->entries, node) { + list_del_init(&pos->node); + free(pos); + } +} + +static unsigned int browser__refresh(struct ui_browser *uib) +{ + return ui_browser__list_head_refresh(uib); +} + +static int browser__show(struct ui_browser *uib) +{ + struct hist_entry *he =3D uib->priv; + struct annotated_data_type *adt =3D he->mem_type; + const char *help =3D "Press 'h' for help on key bindings"; + char title[256]; + + snprintf(title, sizeof(title), "Annotate type: '%s' (%d samples)", + adt->self.type_name, he->stat.nr_events); + + if (ui_browser__show(uib, title, help) < 0) + return -1; + + /* second line header */ + ui_browser__gotorc_title(uib, 0, 0); + ui_browser__set_color(uib, HE_COLORSET_ROOT); + + if (symbol_conf.show_total_period) + strcpy(title, "Period"); + else if (symbol_conf.show_nr_samples) + strcpy(title, "Samples"); + else + strcpy(title, "Percent"); + + ui_browser__printf(uib, " %10s %10s %10s %s", + title, "Offset", "Size", "Field"); + ui_browser__write_nstring(uib, "", uib->width); + return 0; +} + +static void browser__write_overhead(struct ui_browser *uib, + struct type_hist *total, + struct type_hist_entry *hist, int row) +{ + u64 period =3D hist->period; + double percent =3D total->period ? (100.0 * period / total->period) : 0; + bool current =3D ui_browser__is_current_entry(uib, row); + int nr_samples =3D 0; + + ui_browser__set_percent_color(uib, percent, current); + + if (symbol_conf.show_total_period) + ui_browser__printf(uib, " %10" PRIu64, period); + else if (symbol_conf.show_nr_samples) + ui_browser__printf(uib, " %10d", nr_samples); + else + ui_browser__printf(uib, " %10.2f", percent); + + ui_browser__set_percent_color(uib, 0, current); +} + +static void browser__write(struct ui_browser *uib, void *entry, int row) +{ + struct browser_entry *be =3D entry; + struct annotated_member *member =3D be->data; + struct hist_entry *he =3D uib->priv; + struct annotated_data_type *adt =3D he->mem_type; + struct evsel *evsel =3D hists_to_evsel(he->hists); + + if (member =3D=3D NULL) { + bool current =3D ui_browser__is_current_entry(uib, row); + + /* print the closing bracket */ + ui_browser__set_percent_color(uib, 0, current); + ui_browser__write_nstring(uib, "", 11); + ui_browser__printf(uib, " %10s %10s %*s};", + "", "", be->indent * 4, ""); + ui_browser__write_nstring(uib, "", uib->width); + return; + } + + /* print the number */ + browser__write_overhead(uib, adt->histograms[evsel->core.idx], + &be->hists, row); + + /* print type info */ + if (be->indent =3D=3D 0 && !member->var_name) { + ui_browser__printf(uib, " %10d %10d %s%s", + member->offset, member->size, + member->type_name, + list_empty(&member->children) ? ";" : " {"); + } else { + ui_browser__printf(uib, " %10d %10d %*s%s\t%s%s", + member->offset, member->size, + be->indent * 4, "", member->type_name, + member->var_name ?: "", + list_empty(&member->children) ? ";" : " {"); + } + /* fill the rest */ + ui_browser__write_nstring(uib, "", uib->width); +} + +static int annotated_data_browser__run(struct annotated_data_browser *brow= ser, + struct evsel *evsel __maybe_unused, + struct hist_browser_timer *hbt) +{ + int delay_secs =3D hbt ? hbt->refresh : 0; + int key; + + if (browser__show(&browser->b) < 0) + return -1; + + while (1) { + key =3D ui_browser__run(&browser->b, delay_secs); + + switch (key) { + case K_TIMER: + if (hbt) + hbt->timer(hbt->arg); + continue; + case K_F1: + case 'h': + ui_browser__help_window(&browser->b, + "UP/DOWN/PGUP\n" + "PGDN/SPACE Navigate\n" + " Move to prev/next symbol\n" + "q/ESC/CTRL+C Exit\n\n"); + continue; + case K_LEFT: + case '<': + case '>': + case K_ESC: + case 'q': + case CTRL('c'): + goto out; + default: + continue; + } + } +out: + ui_browser__hide(&browser->b); + return key; +} + +int hist_entry__annotate_data_tui(struct hist_entry *he, struct evsel *evs= el, + struct hist_browser_timer *hbt) +{ + struct annotated_data_browser browser =3D { + .b =3D { + .refresh =3D browser__refresh, + .seek =3D ui_browser__list_head_seek, + .write =3D browser__write, + .priv =3D he, + .extra_title_lines =3D 1, + }, + }; + int ret; + + ui_helpline__push("Press ESC to exit"); + + ret =3D annotated_data_browser__collect_entries(&browser); + if (ret =3D=3D 0) + ret =3D annotated_data_browser__run(&browser, evsel, hbt); + + annotated_data_browser__delete_entries(&browser); + + return ret; +} diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index b150137a92dc..1cd857400038 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -1820,5 +1820,6 @@ int hist_entry__annotate_data_tty(struct hist_entry *= he, struct evsel *evsel) print_annotated_data_type(he->mem_type, &he->mem_type->self, evsel, 0); printf("\n"); =20 - return 0; + /* move to the next entry */ + return '>'; } diff --git a/tools/perf/util/annotate-data.h b/tools/perf/util/annotate-dat= a.h index 01489db267d4..0a57d9f5ee78 100644 --- a/tools/perf/util/annotate-data.h +++ b/tools/perf/util/annotate-data.h @@ -10,6 +10,7 @@ struct annotated_op_loc; struct debuginfo; struct evsel; +struct hist_browser_timer; struct hist_entry; struct map_symbol; struct thread; @@ -193,4 +194,16 @@ static inline int hist_entry__annotate_data_tty(struct= hist_entry *he __maybe_un =20 #endif /* HAVE_DWARF_SUPPORT */ =20 +#ifdef HAVE_SLANG_SUPPORT +int hist_entry__annotate_data_tui(struct hist_entry *he, struct evsel *evs= el, + struct hist_browser_timer *hbt); +#else +static inline int hist_entry__annotate_data_tui(struct hist_entry *he __ma= ybe_unused, + struct evsel *evsel __maybe_unused, + struct hist_browser_timer *hbt __maybe_unused) +{ + return -1; +} +#endif /* HAVE_SLANG_SUPPORT */ + #endif /* _PERF_ANNOTATE_DATA_H */ --=20 2.44.0.478.gd926399ef9-goog From nobody Sat Feb 7 22:21:05 2026 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 A4F9613C68C; Thu, 11 Apr 2024 03:33:00 +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=1712806380; cv=none; b=TvxG1ouqzYFrIpoTSEkyjIxj8IjsuuNoOOu5+n+gwi40cLmCQ8JAsIqdiLj6bulO+BXgHdZ4pxpp7TsyRHs8An9alU41CAsDaVTbr0fbP2sPV3Kd66NPPmmxikUaENEkjIm/pbSyrf4Y/8faMAvXVHtKA+/gUzKafgfYTkuCYto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712806380; c=relaxed/simple; bh=RsRsNfw4aoHVLYuPLAJZgwVsTZcCjELiYSQfWvHMjgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m717kWvR665zHIfGxxZNYAqTGA1TGa99K/aO9nB6wzqJSwAohdVaW5PMhTXsxrhHn+jf2kgMHWhG2vZGT2R/smMK3hvYZ174byRVBzfIySfUjjTOLOzn4E9TiG7zVmdmbLtPXcLhlb3cbDTiXculkFx07Ld5tiYtHngu1I2gaGk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZGNWH53l; 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="ZGNWH53l" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB749C43390; Thu, 11 Apr 2024 03:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712806380; bh=RsRsNfw4aoHVLYuPLAJZgwVsTZcCjELiYSQfWvHMjgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZGNWH53lCJcrYRMGy/j84N9YR9qiiEWWQkGqxLhUDuTk8EEao/rYf7kfaPR+F+jX1 Ood/sSk/GJNLXqJWV+A3LyG7ivJT3scOLkQ6kCanjJ+WR/Qqoy4XuLAt1s1aYrzMqU 7fRyTh7hV43hQJ+hADlC2Tkbl/PkCbBcyyb8QRzkIipXrx5BAKFbJ/5pEFYKb6VhQY C8jq8PQ9MTI42mB3jnaUbYxy+Fy8TF88oEPwKUhDOqs4EcvLo3gQ4lXiig695wnWZk OQvHabroe/G2Mg3hIobcabeA7w1ydBXbwrSxyhiQwYAqSt249KIei3Vpzp5vWST2zL uLDTFd6Mw7Rdg== 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, Arnaldo Carvalho de Melo Subject: [PATCH 5/7] perf annotate-data: Support event group display in TUI Date: Wed, 10 Apr 2024 20:32:54 -0700 Message-ID: <20240411033256.2099646-6-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240411033256.2099646-1-namhyung@kernel.org> References: <20240411033256.2099646-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 in stdio, it should print all events in a group together. Committer notes: Collect it: root@number:~# perf record -a -e '{cpu_core/mem-loads,ldlat=3D30/P,cpu_co= re/mem-stores/P}' ^C[ perf record: Woken up 8 times to write data ] [ perf record: Captured and wrote 4.980 MB perf.data (55825 samples) ] root@number:~# Then do it in stdio: root@number:~# perf annotate --stdio --data-type Annotate type: 'union ' in /usr/lib64/libc.so.6 (1131 samples): event[0] =3D cpu_core/mem-loads,ldlat=3D30/P event[1] =3D cpu_core/mem-stores/P =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Percent offset size field 100.00 100.00 0 40 union { 100.00 100.00 0 40 struct __pthread_mutex_s _= _data { 48.61 23.46 0 4 int __lock; 0.00 0.48 4 4 unsigned int __count; 6.38 41.32 8 4 int __owner; 8.74 34.02 12 4 unsigned int __nusers; 35.66 0.26 16 4 int __kind; 0.61 0.45 20 2 short int __spins; 0.00 0.00 22 2 short int __elision; 0.00 0.00 24 16 __pthread_list_t _= _list { 0.00 0.00 24 8 struct __pthread_inte= rnal_list* __prev; 0.00 0.00 32 8 struct __pthread_inte= rnal_list* __next; }; }; 0.00 0.00 0 0 char* __size; 48.61 23.94 0 8 long int __align; }; Now with TUI before this patch: root@number:~# perf annotate --tui --data-type Annotate type: 'union ' (790 samples) Percent Offset Size Field 100.00 0 40 union { 100.00 0 40 struct __pthread_mutex_s __data { 48.61 0 4 int __lock; 0.00 4 4 unsigned int __count; 6.38 8 4 int __owner; 8.74 12 4 unsigned int __nusers; 35.66 16 4 int __kind; 0.61 20 2 short int __spins; 0.00 22 2 short int __elision; 0.00 24 16 __pthread_list_t __list { 0.00 24 8 struct __pthread_internal_= list* __prev; 0.00 32 8 struct __pthread_internal_= list* __next; 0.00 0 0 char* __size; 48.61 0 8 long int __align; }; And now after this patch: Annotate type: 'union ' (790 samples) Percent Offset Size Field 100.00 100.00 0 40 union { 100.00 100.00 0 40 struct __pthread_mutex_s = __data { 48.61 23.46 0 4 int __lock; 0.00 0.48 4 4 unsigned int __c= ount; 6.38 41.32 8 4 int __owner; 8.74 34.02 12 4 unsigned int __n= users; 35.66 0.26 16 4 int __kind; 0.61 0.45 20 2 short int __spins; 0.00 0.00 22 2 short int __elision; 0.00 0.00 24 16 __pthread_list_t __l= ist { 0.00 0.00 24 8 struct __pthread_= internal_list* __prev; 0.00 0.00 32 8 struct __pthread_= internal_list* __next; }; }; 0.00 0.00 0 0 char* __size; 48.61 23.94 0 8 long int __align; }; On a followup patch the --tui output should have this that is present in --stdio: And the --stdio has all the missing info in TUI: Annotate type: 'union ' in /usr/lib64/libc.so.6 (1131 samples): event[0] =3D cpu_core/mem-loads,ldlat=3D30/P event[1] =3D cpu_core/mem-stores/P Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/annotate-data.c | 50 ++++++++++++++++++++------ 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/tools/perf/ui/browsers/annotate-data.c b/tools/perf/ui/browser= s/annotate-data.c index fefacaaf16db..a4a0f042f201 100644 --- a/tools/perf/ui/browsers/annotate-data.c +++ b/tools/perf/ui/browsers/annotate-data.c @@ -10,20 +10,27 @@ #include "util/annotate.h" #include "util/annotate-data.h" #include "util/evsel.h" +#include "util/evlist.h" #include "util/sort.h" =20 struct annotated_data_browser { struct ui_browser b; struct list_head entries; + int nr_events; }; =20 struct browser_entry { struct list_head node; struct annotated_member *data; - struct type_hist_entry hists; + struct type_hist_entry *hists; int indent; }; =20 +static struct annotated_data_browser *get_browser(struct ui_browser *uib) +{ + return container_of(uib, struct annotated_data_browser, b); +} + static void update_hist_entry(struct type_hist_entry *dst, struct type_hist_entry *src) { @@ -33,17 +40,21 @@ static void update_hist_entry(struct type_hist_entry *d= st, =20 static int get_member_overhead(struct annotated_data_type *adt, struct browser_entry *entry, - struct evsel *evsel) + struct evsel *leader) { struct annotated_member *member =3D entry->data; - int i; + int i, k; =20 for (i =3D 0; i < member->size; i++) { struct type_hist *h; + struct evsel *evsel; int offset =3D member->offset + i; =20 - h =3D adt->histograms[evsel->core.idx]; - update_hist_entry(&entry->hists, &h->addr[offset]); + for_each_group_evsel(evsel, leader) { + h =3D adt->histograms[evsel->core.idx]; + k =3D evsel__group_idx(evsel); + update_hist_entry(&entry->hists[k], &h->addr[offset]); + } } return 0; } @@ -61,6 +72,12 @@ static int add_child_entries(struct annotated_data_brows= er *browser, if (entry =3D=3D NULL) return -1; =20 + entry->hists =3D calloc(browser->nr_events, sizeof(*entry->hists)); + if (entry->hists =3D=3D NULL) { + free(entry); + return -1; + } + entry->data =3D member; entry->indent =3D indent; if (get_member_overhead(adt, entry, evsel) < 0) { @@ -113,6 +130,7 @@ static void annotated_data_browser__delete_entries(stru= ct annotated_data_browser =20 list_for_each_entry_safe(pos, tmp, &browser->entries, node) { list_del_init(&pos->node); + free(pos->hists); free(pos); } } @@ -126,6 +144,7 @@ static int browser__show(struct ui_browser *uib) { struct hist_entry *he =3D uib->priv; struct annotated_data_type *adt =3D he->mem_type; + struct annotated_data_browser *browser =3D get_browser(uib); const char *help =3D "Press 'h' for help on key bindings"; char title[256]; =20 @@ -146,7 +165,8 @@ static int browser__show(struct ui_browser *uib) else strcpy(title, "Percent"); =20 - ui_browser__printf(uib, " %10s %10s %10s %s", + ui_browser__printf(uib, "%*s %10s %10s %10s %s", + 11 * (browser->nr_events - 1), "", title, "Offset", "Size", "Field"); ui_browser__write_nstring(uib, "", uib->width); return 0; @@ -175,18 +195,20 @@ static void browser__write_overhead(struct ui_browser= *uib, =20 static void browser__write(struct ui_browser *uib, void *entry, int row) { + struct annotated_data_browser *browser =3D get_browser(uib); struct browser_entry *be =3D entry; struct annotated_member *member =3D be->data; struct hist_entry *he =3D uib->priv; struct annotated_data_type *adt =3D he->mem_type; - struct evsel *evsel =3D hists_to_evsel(he->hists); + struct evsel *leader =3D hists_to_evsel(he->hists); + struct evsel *evsel; =20 if (member =3D=3D NULL) { bool current =3D ui_browser__is_current_entry(uib, row); =20 /* print the closing bracket */ ui_browser__set_percent_color(uib, 0, current); - ui_browser__write_nstring(uib, "", 11); + ui_browser__write_nstring(uib, "", 11 * browser->nr_events); ui_browser__printf(uib, " %10s %10s %*s};", "", "", be->indent * 4, ""); ui_browser__write_nstring(uib, "", uib->width); @@ -194,8 +216,12 @@ static void browser__write(struct ui_browser *uib, voi= d *entry, int row) } =20 /* print the number */ - browser__write_overhead(uib, adt->histograms[evsel->core.idx], - &be->hists, row); + for_each_group_evsel(evsel, leader) { + struct type_hist *h =3D adt->histograms[evsel->core.idx]; + int idx =3D evsel__group_idx(evsel); + + browser__write_overhead(uib, h, &be->hists[idx], row); + } =20 /* print type info */ if (be->indent =3D=3D 0 && !member->var_name) { @@ -267,11 +293,15 @@ int hist_entry__annotate_data_tui(struct hist_entry *= he, struct evsel *evsel, .priv =3D he, .extra_title_lines =3D 1, }, + .nr_events =3D 1, }; int ret; =20 ui_helpline__push("Press ESC to exit"); =20 + if (evsel__is_group_event(evsel)) + browser.nr_events =3D evsel->core.nr_members; + ret =3D annotated_data_browser__collect_entries(&browser); if (ret =3D=3D 0) ret =3D annotated_data_browser__run(&browser, evsel, hbt); --=20 2.44.0.478.gd926399ef9-goog From nobody Sat Feb 7 22:21:05 2026 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 E2BB813C692; Thu, 11 Apr 2024 03:33:00 +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=1712806381; cv=none; b=MuGM7JcnV0qBXg+y/Dq2OO2TIVxbCz8bju7op4Cgkx+/V18wsz8xfe+l+QAYuBtXpb/2Hf2NWFNo+20wG5RE7fBOJ6n59F9quh2B3z/TD5fybu9yZ/YW9PvHSknJ6VltTs+XtexjjpbnE/WtlZUk8bqo0MYC0CLdpkgJbnlkdy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712806381; c=relaxed/simple; bh=X8Vye17HjHIRPgRNBcNLpbPpftNemU1wC0X5p4n1gMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tAjT6h/E5VoeSCklOk5CRgThMLR7rWpM1zcYuSL/pFfr04nFpOkMOGSaZkdl/M7cRpC2P5NuA6kKkYlGXrgNEUEwuk2YI/TWjy7MEZsqKb3kGtYh4Ej4KCuVoTakK/tUHX0VvJLAZg7WSLf1wD36QZMI7kOFGVdUXfx8knciN+Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=glgSGqwO; 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="glgSGqwO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D1D0C43142; Thu, 11 Apr 2024 03:33:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712806380; bh=X8Vye17HjHIRPgRNBcNLpbPpftNemU1wC0X5p4n1gMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=glgSGqwOM+PaCygU3nDa340Py0E8vFzoYST8n1zGW8cvyNeMJ9ZwWW5xuQSR0Ranl Y5exrZITgC4800TosD/jMTMK2QqqDlpmG6zveIdVTdVpeJKT26BsPHaDDYxXQIulKY 19AKjW2htg2lnpasuUHq/3RQ58bQj4vZFmxBHlwWpZSPICifKau4Ts2Lo02esJfFDy epyqjWOpPK+PeoBqDi0i7diWDURFbs7wtcR6kVbnCxYQhkpxfL8ccRGn3X6Iij5AJK bFWVNMwO4N0OH6S8RwfmYBiHeMIU6pL+GIG0xmfvlvZLb2MhRDkuDs554Ans3DUHcf y9AGNV/EHtTPg== 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 6/7] perf report: Add a menu item to annotate data type in TUI Date: Wed, 10 Apr 2024 20:32:55 -0700 Message-ID: <20240411033256.2099646-7-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240411033256.2099646-1-namhyung@kernel.org> References: <20240411033256.2099646-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 the hist entry has the type info, it should be able to display the annotation browser for the type like in `perf annotate --data-type`. Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-report.c | 5 +++++ tools/perf/ui/browsers/hists.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index dcd93ee5fc24..aaa6427a1224 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -1694,6 +1694,11 @@ int cmd_report(int argc, const char **argv) else use_browser =3D 0; =20 + if (report.data_type && use_browser =3D=3D 1) { + symbol_conf.annotate_data_member =3D true; + symbol_conf.annotate_data_sample =3D true; + } + if (sort_order && strstr(sort_order, "ipc")) { parse_options_usage(report_usage, options, "s", 1); goto error; diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 0c02b3a8e121..71b32591d61a 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -38,6 +38,7 @@ #include "../ui.h" #include "map.h" #include "annotate.h" +#include "annotate-data.h" #include "srcline.h" #include "string2.h" #include "units.h" @@ -2505,6 +2506,32 @@ add_annotate_opt(struct hist_browser *browser __mayb= e_unused, return 1; } =20 +static int +do_annotate_type(struct hist_browser *browser, struct popup_action *act) +{ + struct hist_entry *he =3D browser->he_selection; + + hist_entry__annotate_data_tui(he, act->evsel, browser->hbt); + ui_browser__handle_resize(&browser->b); + return 0; +} + +static int +add_annotate_type_opt(struct hist_browser *browser, + struct popup_action *act, char **optstr, + struct hist_entry *he) +{ + if (he =3D=3D NULL || he->mem_type =3D=3D NULL || he->mem_type->histogram= s =3D=3D NULL) + return 0; + + if (asprintf(optstr, "Annotate type %s", he->mem_type->self.type_name) < = 0) + return 0; + + act->evsel =3D hists_to_evsel(browser->hists); + act->fn =3D do_annotate_type; + return 1; +} + static int do_zoom_thread(struct hist_browser *browser, struct popup_action *act) { @@ -3307,6 +3334,10 @@ static int evsel__hists_browse(struct evsel *evsel, = int nr_events, const char *h browser->he_selection->ip); } skip_annotation: + nr_options +=3D add_annotate_type_opt(browser, + &actions[nr_options], + &options[nr_options], + browser->he_selection); nr_options +=3D add_thread_opt(browser, &actions[nr_options], &options[nr_options], thread); nr_options +=3D add_dso_opt(browser, &actions[nr_options], --=20 2.44.0.478.gd926399ef9-goog From nobody Sat Feb 7 22:21:05 2026 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 D31E113C3D0; Thu, 11 Apr 2024 03:33:01 +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=1712806381; cv=none; b=oK6Tg+Mlb+GruNZWGp2mbSrgWeq8MAqyXDSNh2/rRWUUPpXQ8dumSq1foofzlnzMH+VUBdD1YJY4HsNrBcCR5JrVzTsU7TEMufuQB5CqCrtiaVbHsszievb87b+Edvf6s5m0zBxdX1PlgPbTD0cDEbxGuJG4BOZAZ73wvBcpJxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712806381; c=relaxed/simple; bh=oLLdTTKJKvZGCT3VxJu2I0H1lKPF7WqOrG568ajKlas=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rgc33aAoDt1FaruYugLHwal2OKEtY6LHP1I36x2zsIZFf3BJOULhOS73gJVQLS/wfQ9b+yqk+PBw9XONWi1Uvj+fjJp2RWS9q1d5HfYY8+MlcNA/EMsPVbqGXEKLzEdm1Eyn+8ZBhGYEI/CGcGFrvQr9bEQYz+CZ0DdFCp5WvGQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PSJ6lXHS; 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="PSJ6lXHS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB6F7C433B2; Thu, 11 Apr 2024 03:33:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712806381; bh=oLLdTTKJKvZGCT3VxJu2I0H1lKPF7WqOrG568ajKlas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PSJ6lXHSqpVia7i39B7tkei/wFKc3ImfQLi1p/LKSrZxHBonbM8fkzVOBmGUFL2JM DbRYt6bxJNdcRBcmkH0yz4Uo+RsO0+2t1BQgBQxdb4tysPzkVGw6bEXSxw0e6SFFYt QvasCY4bIaJkXqm806C8T9bitwJ/qBLvqPR1+CsNZyPAGOf/5gdkAaqkCv5+0+K2I3 qSkny1VjXI2pGTpeawAnOC5+V6g1tsMjeUoKbZ8g0fJK8Zo5bsETkpV1+6P64rO2hs t0mD5emTuepJ6EtKFzes6k+f56f8r5uX4IQwF9e/qXY15hwfuOcHH/UXyZ2eYmvmRJ KmlcVe1nrI4VA== 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 7/7] perf report: Do not collect sample histogram unnecessarily Date: Wed, 10 Apr 2024 20:32:56 -0700 Message-ID: <20240411033256.2099646-8-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240411033256.2099646-1-namhyung@kernel.org> References: <20240411033256.2099646-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 data type profiling alone doesn't need the sample histogram for functions. It only needs the histogram for the types. Let's remove the condition in the report_callback to check if data type profiling is selected and make sure the annotation has the 'struct annotated_source' instantiated before calling symbol__disassemble(). Reviewed-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-report.c | 2 +- tools/perf/util/annotate.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index aaa6427a1224..dafba6e030ef 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -172,7 +172,7 @@ static int hist_iter__report_callback(struct hist_entry= _iter *iter, struct mem_info *mi; struct branch_info *bi; =20 - if (!ui__has_annotation() && !rep->symbol_ipc && !rep->data_type) + if (!ui__has_annotation() && !rep->symbol_ipc) return 0; =20 if (sort__mode =3D=3D SORT_MODE__BRANCH) { diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index ec79c120a7d2..7595c8fbc2c5 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -908,6 +908,13 @@ int symbol__annotate(struct map_symbol *ms, struct evs= el *evsel, =20 args.arch =3D arch; args.ms =3D *ms; + + if (notes->src =3D=3D NULL) { + notes->src =3D annotated_source__new(); + if (notes->src =3D=3D NULL) + return -1; + } + if (annotate_opts.full_addr) notes->src->start =3D map__objdump_2mem(ms->map, ms->sym->start); else --=20 2.44.0.478.gd926399ef9-goog