Message ID | 20240213075256.1983638-3-namhyung@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-63063-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp383854dyb; Mon, 12 Feb 2024 23:54:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJj+v/C+n4B/1uVR4jGN0nPhxbiHMFayH74YFoxFzJNAxlMtD1sYAYqm1pPy37ixawWPLc X-Received: by 2002:a05:6870:b291:b0:206:6db:dff9 with SMTP id c17-20020a056870b29100b0020606dbdff9mr8508156oao.58.1707810857887; Mon, 12 Feb 2024 23:54:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707810857; cv=pass; d=google.com; s=arc-20160816; b=wejm83KAZ+eJfpqh/cfywtp/6CVGzBHXhAgRKRBqc98o9bIOKlbCKNrrDcpskh2hHZ Lvzbww+kXcOXB1Qs+4Yid7Ao/2412GxEL1ORhX0LKQzuYr+jTmPXHRgFbHbB52wiK4vy dmTJ2LDgIrzJxmHuX/sOOB16ox2mJW8RUnAkx8lNFTC6mWiYkoSLZ7ulPe/s/gYTtLYj X3/tdgVGuzxAQEkAadi4nQBsiWyyXzOtzNS3xdJWaGUmGDwCGjlwDcWeB1GTIbamTJA8 1HjfsHCCjZB6qzGE8qrrXuFRMeqIVm373GU2vJUYXd1jTFPFt7IodbJbl1CMpI+wk6A+ T3dQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=icUOIUv5aPxp/XDHfMIYwPdOZUziOwrmgWjtBk/AqOQ=; fh=qSEQRoWkWLa4t/oftrEJCnSk62mjQ9owur564gFpig8=; b=i4s2CaKeoCFm3smN6wWNyUHKANvgFyk6yAfsFAPPEb0iJyaWrVnhLkdEOyRU7E8gbr KPv6MfkiKkHNtdpqYon9QmQAR8Kz4zZBR7cLS20vJdUzNSJD8I6ebklKXOoYfjQD6UHo 2rR/76WLkaKEEU/CfWIl7GCzEX/+dt96SQEnH2gif319732X/k2qSGoqWZhVyge4ZVGR kKpUVbb8pqkOaw79z2PVO6zLpWWUD/EXowlK6jGhtpuuvZhnZT2RhPRkW+7cvjC0xgC3 n+FnOP+uiOb3LimR1aesh9mzSrQ4VM9sV4jooP0O5yQRXPS4E0wIqgp9U/q/4boJd5Lv hHEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i5Ia39o+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-63063-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63063-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXLDzPfRhJnd6QftZiqSmD8YqTQ96aasw87BcPjn/ATruS5+ipZ4Y+w2juSt/OWP5Yk2UxU2DtI/YEMty9s/bIu7lZq1w== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s22-20020a639256000000b005bd27be66e1si1594880pgn.719.2024.02.12.23.54.17 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 23:54:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63063-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i5Ia39o+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-63063-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63063-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A059C284076 for <ouuuleilei@gmail.com>; Tue, 13 Feb 2024 07:54:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78F9122313; Tue, 13 Feb 2024 07:53:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i5Ia39o+" 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 BC511182CC; Tue, 13 Feb 2024 07:52: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=1707810778; cv=none; b=Qmj0JJAM0rGR+b6masr7DUMgKBLPTjbPW2lafdTVbBq1QezV6XDY70r52jcb0/Npa8iBeDtYZAPf4tyYBf99zVlkWjGcf95rcyiL0kHdGtzO1F7IeVH74WX5u2Rss1/eEeXumGhVw49S8mqv8A3TBZwZa5U5kJ0V55YBRsY7HGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707810778; c=relaxed/simple; bh=jcUZpV1neXzu3Kp6ToaOsDKLDERo3W3oIzclMpmzJ1I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j6kkniChvGZSdi5VVxgfzE51psLK6mzs3T8EoX7hn0F0Je+nxV8EPnn5mUXWCEPXpHM7Q6NC+B9hfT1On7qg7/sNkEqnBSwcc0gBw4jL6q3VE8TLeV2mAKZkRyAzOUf70k3jQY1azSmkIjVyjvXazvxioQq2BZK8qH0P9flyff0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i5Ia39o+; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECA87C43394; Tue, 13 Feb 2024 07:52:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707810778; bh=jcUZpV1neXzu3Kp6ToaOsDKLDERo3W3oIzclMpmzJ1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i5Ia39o+UXgoq87UnC132bdO3AXQ/WuaXkeWlK28XRnlkd37wk+R3d77ML+/2HZXO xhyxDBLbmlMFOQ/mAig9LIK643sPl2voIr9p5JWunqnslc6uj4iWmIkvEQPsmPkh/Q RbwNcFT3chwNv8hn17yABArqTYfI8QXSUkBVh6b9vOAG5d+4UTyJRIlw71ub9f5rq2 8qhrb5z9kAV/TRiZUQQI68JIk+DH4I3KR8cFIORO7a/dh60UcJ9XJNvciWZaa4J7e5 XuM20i5nEhyC9K7JgrZ7OkMZ9kiXS1I2qR9WzgLrM20VvfMfKbp9y5UWk7ycm7Nyrk lF9UQIbCnv3cg== 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 Message-ID: <20240213075256.1983638-3-namhyung@kernel.org> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240213075256.1983638-1-namhyung@kernel.org> References: <20240213075256.1983638-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790769477984190177 X-GMAIL-MSGID: 1790769477984190177 |
Series |
perf report: Omit dummy events in the output (v1)
|
|
Commit Message
Namhyung Kim
Feb. 13, 2024, 7:52 a.m. UTC
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(-)
Comments
On Mon, Feb 12, 2024 at 11:53 PM Namhyung Kim <namhyung@kernel.org> wrote: > > 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; Looks good, but should this return value be negative to indicate an error? Snprintf gives a negative result on error, its result is sometimes returned from hpp__fmt_acc, as is this result. Thanks, Ian > > + /* 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 >
On Wed, Feb 14, 2024 at 3:57 PM Ian Rogers <irogers@google.com> wrote: > > On Mon, Feb 12, 2024 at 11:53 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > 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; > > Looks good, but should this return value be negative to indicate an > error? Snprintf gives a negative result on error, its result is > sometimes returned from hpp__fmt_acc, as is this result. Sounds good, will change. Thanks, Namhyung > > > > > + /* 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 > >
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); } /*