From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org
Subject: [PATCH 2/4] perf hist: Simplify hist printing logic for group events
Date: Mon, 12 Feb 2024 23:52:54 -0800 [thread overview]
Message-ID: <20240213075256.1983638-3-namhyung@kernel.org> (raw)
In-Reply-To: <20240213075256.1983638-1-namhyung@kernel.org>
It can uses an array to save the period (or percent) values for member
events and print them together in a loop. This simplify the logic to
handle missing samples in members with zero values.
No functional change intended.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/ui/hist.c | 55 +++++++++++++++++---------------------------
1 file changed, 21 insertions(+), 34 deletions(-)
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 2bf959d08354..5f4c110d840f 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -33,6 +33,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
char *buf = hpp->buf;
size_t size = hpp->size;
+ /* print stand-alone or group leader events separately */
if (fmt_percent) {
double percent = 0.0;
u64 total = hists__total_period(hists);
@@ -45,12 +46,19 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
ret = hpp__call_print_fn(hpp, print_fn, fmt, len, get_field(he));
if (evsel__is_group_event(evsel)) {
- int prev_idx, idx_delta;
+ int idx;
struct hist_entry *pair;
int nr_members = evsel->core.nr_members;
+ union {
+ u64 period;
+ double percent;
+ } *val;
- prev_idx = evsel__group_idx(evsel);
+ val = calloc(nr_members, sizeof(*val));
+ if (val == NULL)
+ return 0;
+ /* collect values in the group members */
list_for_each_entry(pair, &he->pairs.head, pairs.node) {
u64 period = get_field(pair);
u64 total = hists__total_period(pair->hists);
@@ -59,47 +67,26 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
continue;
evsel = hists_to_evsel(pair->hists);
- idx_delta = evsel__group_idx(evsel) - prev_idx - 1;
-
- while (idx_delta--) {
- /*
- * zero-fill group members in the middle which
- * have no sample
- */
- if (fmt_percent) {
- ret += hpp__call_print_fn(hpp, print_fn,
- fmt, len, 0.0);
- } else {
- ret += hpp__call_print_fn(hpp, print_fn,
- fmt, len, 0ULL);
- }
- }
-
- if (fmt_percent) {
- ret += hpp__call_print_fn(hpp, print_fn, fmt, len,
- 100.0 * period / total);
- } else {
- ret += hpp__call_print_fn(hpp, print_fn, fmt,
- len, period);
- }
+ idx = evsel__group_idx(evsel);
- prev_idx = evsel__group_idx(evsel);
+ if (fmt_percent)
+ val[idx].percent = 100.0 * period / total;
+ else
+ val[idx].period = period;
}
- idx_delta = nr_members - prev_idx - 1;
-
- while (idx_delta--) {
- /*
- * zero-fill group members at last which have no sample
- */
+ /* idx starts from 1 to skip the leader event */
+ for (idx = 1; idx < nr_members; idx++) {
if (fmt_percent) {
ret += hpp__call_print_fn(hpp, print_fn,
- fmt, len, 0.0);
+ fmt, len, val[idx].percent);
} else {
ret += hpp__call_print_fn(hpp, print_fn,
- fmt, len, 0ULL);
+ fmt, len, val[idx].period);
}
}
+
+ free(val);
}
/*
--
2.43.0.687.g38aa6559b0-goog
next prev parent reply other threads:[~2024-02-13 7:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-13 7:52 [PATCHSET 0/4] perf report: Omit dummy events in the output (v1) Namhyung Kim
2024-02-13 7:52 ` [PATCH 1/4] libperf evlist: Update group info in perf_evlist__remove() Namhyung Kim
2024-02-14 23:50 ` Ian Rogers
2024-02-15 5:16 ` Namhyung Kim
2024-02-13 7:52 ` Namhyung Kim [this message]
2024-02-14 23:57 ` [PATCH 2/4] perf hist: Simplify hist printing logic for group events Ian Rogers
2024-02-15 5:18 ` Namhyung Kim
2024-02-13 7:52 ` [PATCH 3/4] perf hist: Do not use event index in hpp__fmt() Namhyung Kim
2024-02-15 0:08 ` Ian Rogers
2024-02-15 5:26 ` Namhyung Kim
2024-02-15 7:54 ` Ian Rogers
2024-02-16 20:08 ` Namhyung Kim
2024-02-13 7:52 ` [PATCH 4/4] perf report: Do not show dummy events with --skip-empty Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240213075256.1983638-3-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®