From nobody Sun Feb 8 06:22:43 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 1521C1591F8; Tue, 9 Apr 2024 23:50:02 +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=1712706603; cv=none; b=B9RoCtpW79tplCJXtV1YKOjNpIziaPcvAgDCpFdUsWfPISSC4KzYzAL6SX3mnDSoUMtfAFsdXuHZk2U70PJPlZiGq0NSuH+7iuZ36M9IxzIEe8peeHkaaTDOsSPlAfO3yXTOohtdRxouhVjzMqpbDwqIIfjjDpM3lmtBwLTslP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712706603; c=relaxed/simple; bh=JniUIOtymtPSjR4nX8r1BDesYexwAvEo2n0TNtIdZes=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oYgND4sLw2RKbPuuEdNP2dik0UrCez+kkeURDJLlohcFO3K5hBHB+a1tZj9BcPPsxRiAbtICu2B1CWxlSOZu78ASBlV6PDr6J4Fa7Iv4N+vG9PR4eV790KOKp2xoggK58ZQeLV6fG8Ve1Rsu1TJEewV7wqk74Bf8yx/SeEUhwuA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=naEbYt79; 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="naEbYt79" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98072C433A6; Tue, 9 Apr 2024 23:50:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712706602; bh=JniUIOtymtPSjR4nX8r1BDesYexwAvEo2n0TNtIdZes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=naEbYt79Rt3g+TLI52IaGdEmcyGYXtoC3tux39xgok/DKT0JRk9AsU/EJiSfgsf8f dLDPzD3kT4Zu9NdsSl7sYptIJqE4qk6nXoSNgbG66fDxk89d6FOqJKdQ2lrQSvuHr2 bkRsB0Apd7JM56BwCcN6dy0cGQcecWRx03iKx3AfBEDMmGW5xriF+170uyIwqVpHQJ tZmxGsvToTbmNEg5QpLrWU1vJUEZuGyWNNL5xKT8pr2dgWNvoN56lnSQo5D5eTArGn +XaMwlnm9L805riHlSjQKwns5fg5WVzLxQOh478yW/FbeuFs0VWX/DORDaV0/juA8b edRe0U70D/BPw== 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/6] perf annotate: Show progress of sample processing Date: Tue, 9 Apr 2024 16:49:55 -0700 Message-ID: <20240409235000.1893969-2-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240409235000.1893969-1-namhyung@kernel.org> References: <20240409235000.1893969-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 the progress window to inform users how long it'll take. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- 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 Sun Feb 8 06:22:43 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 90894158DDE; Tue, 9 Apr 2024 23:50:02 +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=1712706602; cv=none; b=GTko/Z+Rj1AFxlJVwXpdoNGvWWzEx7JdVos34FFBTZxMsBtCH6dIZXrZvrVdKvbtd24Z9SgCXNL3iu/4MZbwgMix9M8mCLAsrEf87DUg/Q0o4Ds+quOC71+vSkEyfH2KQLYgN/lWYfMj3Rh2MU5m+DNzYtBPHakAohU1hsi2bP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712706602; c=relaxed/simple; bh=0pW5q6KpdAEgOCgzS+L1xZu25Btzvfo5clIFIMC4pqI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fncOZKetiW6Eb+zcAAU44H9b/H3GCyiJtSyrDGgHM7jymz84Fx/BoAVQQ+sXADvNNOgrkM7h8OXmQt2T9QmDwI3BXpjwVulc1mckOAC3ucPLPvvU5LRtXgjla/+pnFN5N2JTQFTQ/d75OwZMKP/nWPGobBtJsyeMSwgsFJqMtqA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Aj0F8qkP; 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="Aj0F8qkP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EBE5C433C7; Tue, 9 Apr 2024 23:50:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712706602; bh=0pW5q6KpdAEgOCgzS+L1xZu25Btzvfo5clIFIMC4pqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Aj0F8qkP2y8wgqW1A0sAym5sAakKe/AgnNE8eLapmiw/QkUFNiDHciLu8kvRp8Lzu ig5wEcX0Bim+FFMnMeKTxVBmiIlpT5aZQyYxDr7T9fDu0jv5UQuGzFxOJW4wOWG6qf j3pLwfD1lb4GYyHPRurRYcGuosxQhiFKTuSXYbqT5NaXbQQENr0rmLUccNo+3Avjf9 MsLsRBFUUVJdK4kYvj3/v/lFBhKiE9Cd5Sei4yjrreYYEiIE1Ai5mgqQGeAdCejEdT afrTRuMUz3sxy6oDpURIOd3tS3jkRBQBNfpJ0PeDASnzzxZ2081lcOQe/9s1bqL/F0 k/CFSyeZNjGGg== 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/6] perf annotate-data: Add hist_entry__annotate_data_tty() Date: Tue, 9 Apr 2024 16:49:56 -0700 Message-ID: <20240409235000.1893969-3-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240409235000.1893969-1-namhyung@kernel.org> References: <20240409235000.1893969-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. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/builtin-annotate.c | 106 +----------------------------- tools/perf/util/annotate-data.c | 110 ++++++++++++++++++++++++++++++++ tools/perf/util/annotate-data.h | 3 + 3 files changed, 114 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..99c5dcdfc9df 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,112 @@ 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"); +} + +void hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *ev= sel) +{ + print_annotated_data_header(he, evsel); + print_annotated_data_type(he->mem_type, &he->mem_type->self, evsel, 0); + printf("\n"); +} diff --git a/tools/perf/util/annotate-data.h b/tools/perf/util/annotate-dat= a.h index fe1e53d6e8c7..037e2622b7a3 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 @@ -140,6 +141,8 @@ struct annotated_data_stat { }; extern struct annotated_data_stat ann_data_stat; =20 +void hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *ev= sel); + #ifdef HAVE_DWARF_SUPPORT =20 /* Returns data type at the location (ip, reg, offset) */ --=20 2.44.0.478.gd926399ef9-goog From nobody Sun Feb 8 06:22:43 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 193811591F9; Tue, 9 Apr 2024 23:50:03 +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=1712706603; cv=none; b=IoBrWo64V4bUoa2Mtn3XFMZYFXTkey7UtJ89BbU44931JxY+KoBBd9pYQYXvJFrRgPAlTHTiI0I3zfUB9YiXv/mjy2U8YERa+GYYiuHMGb2ZvAff8/dijd68EZ8fVN35pW9y33PFSh0VqWDn8xCuy906q/9m6VSVErXDhJHKZlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712706603; c=relaxed/simple; bh=3TpVmLFJVURZBCiS1i9FyAIxWtUR0uuUCXuJi1xdk/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y2/+770mTHwCgoGf72ZkaPOkHKPN6DaSOCA9stAV5W548RxN+TGLrGI9kVrxWjMUA1/hfH47pGavdtAt9391+uUfK2WKJL9dYOAIFCM9YKi5T8bbj1+G0YlMyT7Tu+7O6rXkaVTxlSx/Ey627545KFX/qiwqludujQE3mlBCJZc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PjEEVxw9; 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="PjEEVxw9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95683C43601; Tue, 9 Apr 2024 23:50:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712706603; bh=3TpVmLFJVURZBCiS1i9FyAIxWtUR0uuUCXuJi1xdk/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PjEEVxw9MSsvDY/GE9cQsovBRKGFFAe6aYh6/pon3DWpdqf4QOY8ph5sWbp/gKFUc l+JKzhVNgPJtuOa+6keaeQ4OHuY4DvqDLN0bQ9v10K3+Kii/q9KMtgv5BwdlT1TRhf vEFL0ZahYesv2CDOXpP6GOSjYEDe15SeZbNFEtxL6zs/yD/inVl9hlIgn2SwJbR/fj eUgzhcDUhBwUbS4YdsOrRkaTyCuvu+zDhANdaIkCbhek3YlI+gUBA2bpjnuzeLQUHm jljH3TQcdf27/dpmxUMVjEue5qNmsZwE3tjwrXOGXYcryL6TuAjjF/pEaXCQxG4sHw JpBA7SbPW4yYw== 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/6] perf annotate-data: Add hist_entry__annotate_data_tui() Date: Tue, 9 Apr 2024 16:49:57 -0700 Message-ID: <20240409235000.1893969-4-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240409235000.1893969-1-namhyung@kernel.org> References: <20240409235000.1893969-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. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers 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 | 5 +- tools/perf/util/annotate-data.h | 5 +- 5 files changed, 317 insertions(+), 6 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 99c5dcdfc9df..1cd857400038 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -1814,9 +1814,12 @@ static void print_annotated_data_type(struct annotat= ed_data_type *mem_type, printf(";\n"); } =20 -void hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *ev= sel) +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"); + + /* move to the next entry */ + return '>'; } diff --git a/tools/perf/util/annotate-data.h b/tools/perf/util/annotate-dat= a.h index 037e2622b7a3..9a6d9b519724 100644 --- a/tools/perf/util/annotate-data.h +++ b/tools/perf/util/annotate-data.h @@ -11,6 +11,7 @@ struct annotated_op_loc; struct debuginfo; struct evsel; struct hist_entry; +struct hist_browser_timer; struct map_symbol; struct thread; =20 @@ -141,7 +142,9 @@ struct annotated_data_stat { }; extern struct annotated_data_stat ann_data_stat; =20 -void hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *ev= sel); +int hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *evs= el); +int hist_entry__annotate_data_tui(struct hist_entry *he, struct evsel *evs= el, + struct hist_browser_timer *hbt); =20 #ifdef HAVE_DWARF_SUPPORT =20 --=20 2.44.0.478.gd926399ef9-goog From nobody Sun Feb 8 06:22:43 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 EA0AD159560; Tue, 9 Apr 2024 23:50:03 +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=1712706604; cv=none; b=WEfbK2gqtVhDpSw9mJoJBLI2Z51hv8UHpAojFsaOUZB1rNjVMB0idSqSvwifKApFOXCH3QH3uodwmvBQ2bDqHBq6wd2oYAI1Wnsxl6Exx3sabUs9DaaYYKwqlx1RqAEwus1QFhNlwKC8ZcLrdJNxleMQCtV4xNLVyql3ONS5ZWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712706604; c=relaxed/simple; bh=AddK5ii9O630G6QxgsZ1OcL/iUmRt+ii1QXcHGqscqg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JhBlm3PSP4pic5e4tcPLDgloHF+WCsCtyFgagSCiYlDcWqVUqfwv2sA+6c1Yb75NkkeHNMh3EThtVEmVtNYPKjRvj0uBH/xFlFdigzDVotemkZf5Z44v/JnJkD7++13tZYF1UixZvmQbXlbE46XiTpe+fY2zQwQEWaKL8EQoAG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bo8+tsXU; 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="Bo8+tsXU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E1E3C43330; Tue, 9 Apr 2024 23:50:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712706603; bh=AddK5ii9O630G6QxgsZ1OcL/iUmRt+ii1QXcHGqscqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bo8+tsXU+e8TkJzx+YtKY8oFMS1I4U8lv7O6v83cfA52nC1GJrQVjSaW/TAL/Qp/K R8MX2t8UR7+HNu8gk9ef8rVigArEYorQh9fBIfGVIxbrGUode+zW2dLk/Z3p2wKcCZ 9tHMaNmkR6kdsY904QEuHXm4TKa/aRWzqZ76t3tuVLAJKdgH/fHa11BU2Kras2mNkJ oXguCgFx/UXDoVpdoFsVchnxglShkBcCWuM4HxKhUMwziSEHMs3bYR7LzwCNjxP0IP Z6bMEQ+yXnaEpIgiiTpP+6v/oV8uQyPvi+58WksCf4EhOZ7coKM87eH+uRAMg9TfdN 0gXPwxgpUzbPg== 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 4/6] perf annotate-data: Support event group display in TUI Date: Tue, 9 Apr 2024 16:49:58 -0700 Message-ID: <20240409235000.1893969-5-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240409235000.1893969-1-namhyung@kernel.org> References: <20240409235000.1893969-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. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers 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 Sun Feb 8 06:22:43 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 82FB6159579; Tue, 9 Apr 2024 23:50:04 +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=1712706604; cv=none; b=hQRthOxiyrKQf/jgD23V+Ff6OoP8SbcAASF1PqVxq3nORdRflgQuPCMNf/27AmF0iHWMpUloZR7uffJwqDcDcKvTVAwSha0vFcEPDnJ3VM7n846RAveD8r0NlHZ8sFyt05Z9cVRCu4DoqfcDL/beQmORoePKYk4PatnkcX6WZQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712706604; c=relaxed/simple; bh=nieDE0/teF2k6LWCPMxAt6MAUAfm9geljBFjmb2K5NY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l3LGyoj42drbabr29FtdCtqTuMeY9LHIlIoHkDf0V2hdZTaBGYv2WbYDPbpvGJKAyezzobcOMTmKXyPFM3jL73cy1zTrpzmUMOnFVnXE36GjIF2+jWKAgsOtDuUeVBduPkOQGA1gJo5Juk4ML14GitjdV83F1GjA3c6tVPeeaSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ev7SBIF+; 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="ev7SBIF+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92549C43142; Tue, 9 Apr 2024 23:50:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712706603; bh=nieDE0/teF2k6LWCPMxAt6MAUAfm9geljBFjmb2K5NY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ev7SBIF+29xcCVsiUduIJI+ak9pMOKAhVuW4chcL2NPgr97/MDmzRdLiob+0rYG2+ 8KbuhgdxgNHSrYbnMo4AReadDlCbx8b3T4DT7GRkCy0WLnYwZ678zDM9rUC8NdC012 NRKUKUPg0QxEcShsoQLmKh/HgrlEwqmMybkAecQCkojKq/5p1SPA6pyCo8ZmQLSUwM RcMzpmiEplbWWup9PPKx5ti7alXAr7mbtyQ45CE1VZ/8LL5ozvkctvwwp6/kmMSSMy qyVdrP0DgpehmRzasyZ7pRVY3xndLSeX3H4dX+RgTcRuaDBSACSCv1rQzxxtQqvL+U +6aF4x1LJ/UqA== 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 5/6] perf report: Add a menu item to annotate data type in TUI Date: Tue, 9 Apr 2024 16:49:59 -0700 Message-ID: <20240409235000.1893969-6-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240409235000.1893969-1-namhyung@kernel.org> References: <20240409235000.1893969-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`. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- 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 Sun Feb 8 06:22:43 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 87AF115957A; Tue, 9 Apr 2024 23:50:04 +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=1712706604; cv=none; b=Ie1G4Q/29X0/p16n68O1sOO/I9YI44WzZNnyJnoCiAVKsz0aSd94ad1uTFGsLYR0/XFw2Y5Jg5gYhKmx5/wD7Jk1lGw6GRBSGym8yB+MAFHGGM01GKU016dGUgeqPri1OQpV8hBnGxEdcnrZqtnzUhg73TeTrW6rwuSlDu14cuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712706604; c=relaxed/simple; bh=PHHmaY/dJfgbrb1xjAz7ZXHpkxQRYYdnC61SjjaGTOk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bVJ/lXhCmVe5wWFkge8i/723MpkpPfj3ZBC48+wysBlMW5cAEPumoetIYnv/+fZweJlGIaVR/gNh4Ff8GIC0EAe33YV928h0w4iNwzJjCCAHiObW4D+fK3Ev4RKaGefzeSja2kfyfW3XUIy8x4NS+vtYI78tqdcBuIqI3JMiWsQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XC5ZdLtD; 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="XC5ZdLtD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AC44C43390; Tue, 9 Apr 2024 23:50:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712706604; bh=PHHmaY/dJfgbrb1xjAz7ZXHpkxQRYYdnC61SjjaGTOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XC5ZdLtDw+8tQjRubaQDyZmQrtnywONrn24Tldeg7Mp/JM9IbN92e2Z4XpbdLElO8 nG4CXMkj5xiPsAUnFVrAW3wD14YhmuhvrtkwSJaBz77DHZksdXjHVD0p7oXoD2kjy9 PEEoWIwR6CqdL6vLCZQEhVRsSVXEZtblOPdmXfu9IpPHKJoGGeOzFAUuNJ59YSiYkc 3SORnlNxr20Ubt+mC59v3c6fc1S/AWPtHMucEbY4cxfMV7ioQqd84WANf0lE/zVfAO qekqa8+TJN9pYmbROL9t0fJn4JmHPDn1Y0AsmULEiURLKA0n4imSeP7Es4Hcxw35gi HFriir49I6P4w== 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/6] perf report: Do not collect sample histogram unnecessarily Date: Tue, 9 Apr 2024 16:50:00 -0700 Message-ID: <20240409235000.1893969-7-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240409235000.1893969-1-namhyung@kernel.org> References: <20240409235000.1893969-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 the data type profiling and make sure the annotation has the annotated_source before calling symbol__disassemble(). Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- 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 11da27801d88..7e034d2f2adb 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