From nobody Sun Feb 8 07:02:02 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 5FD7418036; Tue, 13 Feb 2024 07:52:57 +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=DhHZhx+UVj2EAZ8xun6RN3/9ThdYbA8ai8zpr7fnfdPEZR3/9/PKCxVN5NFMXrWp6T6t2wrpjXpv0uebeUKwEq4eVHUAGQulhraa9IaE32jrOpBLwZ3qwnJyqWu9JFCqrVoL/aXw/w/Gc+9G4X3NkgFI5xC1fyaYdZWkhEAoE5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707810778; c=relaxed/simple; bh=sOy6KlficwKF5vE8HVBwVLDj0OcsjYyU8khFYs9JUiQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VqquY+QP88Dy9pqzJKwtNYyF7GGfI8hvQ0N/djndXBbxVvFDmmXdSTkHbM8FeaUd7vbgDDPR7xVJ2GAu132C1XNy8NXaCtiSfnJhejIPzGNIjEk4dNjeZ/mrfWLDNR39gVl1Th4oJRbPCS8hBjFe6ob25bkH3H+qMx3ERhoT4F4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g3dpFVKv; 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="g3dpFVKv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F3CDC43390; 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=1707810777; bh=sOy6KlficwKF5vE8HVBwVLDj0OcsjYyU8khFYs9JUiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g3dpFVKvINO5IweleyEFN/hEmQOIAzXGvkh7OnKH2x8GDDheWS9D/+vK4Tz0PXgt+ fAFAxgwkzfqpIf2tuIcZLaSD2ahUrfcv8rIBEcwASBzkD2Q6Rrx/BUT9iYtyJ4HMw1 9L/J2j4PzZ3x+w5K7oaKu8seXAVWfd9v64bwWuPOFB5h1nWiaMC5AJ80kqDUypo1Mi AS7YUtMaNMgvVxo7jjWMftJIsAKr+XntKtiddO+Bhk2ON66cpePHJ+GXAxTBPaRCno KZoz3IuA8qs5Xfk8SAhVQznCVRmoDlUg5TJ8BoSMLHQBmzLOLoWOrruiL36CABrxnQ +XgJBIW8OIFLw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 1/4] libperf evlist: Update group info in perf_evlist__remove() Date: Mon, 12 Feb 2024 23:52:53 -0800 Message-ID: <20240213075256.1983638-2-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When an event in a group is removed, it should update the group status including the pointer to leader and number of member events. Signed-off-by: Namhyung Kim --- tools/lib/perf/evlist.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 058e3ff10f9b..befdb062fa1d 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -102,8 +102,29 @@ void perf_evlist__add(struct perf_evlist *evlist, void perf_evlist__remove(struct perf_evlist *evlist, struct perf_evsel *evsel) { + struct perf_evsel *leader =3D evsel->leader; + list_del_init(&evsel->node); evlist->nr_entries -=3D 1; + + /* return stand-alone event */ + if (leader =3D=3D evsel && leader->nr_members < 2) + return; + + if (leader =3D=3D evsel) { + struct perf_evsel *member; + + /* select the next event as a new leader */ + leader =3D member =3D perf_evlist__next(evlist, evsel); + + /* update members to see the new leader */ + while (member && member->leader =3D=3D evsel) { + member->leader =3D leader; + member =3D perf_evlist__next(evlist, member); + } + } + + leader->nr_members =3D evsel->leader->nr_members - 1; } =20 struct perf_evlist *perf_evlist__new(void) --=20 2.43.0.687.g38aa6559b0-goog From nobody Sun Feb 8 07:02:02 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 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i5Ia39o+" 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 To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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_e= ntry *he, char *buf =3D hpp->buf; size_t size =3D hpp->size; =20 + /* print stand-alone or group leader events separately */ if (fmt_percent) { double percent =3D 0.0; u64 total =3D hists__total_period(hists); @@ -45,12 +46,19 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist= _entry *he, ret =3D hpp__call_print_fn(hpp, print_fn, fmt, len, get_field(he)); =20 if (evsel__is_group_event(evsel)) { - int prev_idx, idx_delta; + int idx; struct hist_entry *pair; int nr_members =3D evsel->core.nr_members; + union { + u64 period; + double percent; + } *val; =20 - prev_idx =3D evsel__group_idx(evsel); + val =3D calloc(nr_members, sizeof(*val)); + if (val =3D=3D NULL) + return 0; =20 + /* collect values in the group members */ list_for_each_entry(pair, &he->pairs.head, pairs.node) { u64 period =3D get_field(pair); u64 total =3D hists__total_period(pair->hists); @@ -59,47 +67,26 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist= _entry *he, continue; =20 evsel =3D hists_to_evsel(pair->hists); - idx_delta =3D 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 +=3D hpp__call_print_fn(hpp, print_fn, - fmt, len, 0.0); - } else { - ret +=3D hpp__call_print_fn(hpp, print_fn, - fmt, len, 0ULL); - } - } - - if (fmt_percent) { - ret +=3D hpp__call_print_fn(hpp, print_fn, fmt, len, - 100.0 * period / total); - } else { - ret +=3D hpp__call_print_fn(hpp, print_fn, fmt, - len, period); - } + idx =3D evsel__group_idx(evsel); =20 - prev_idx =3D evsel__group_idx(evsel); + if (fmt_percent) + val[idx].percent =3D 100.0 * period / total; + else + val[idx].period =3D period; } =20 - idx_delta =3D 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 =3D 1; idx < nr_members; idx++) { if (fmt_percent) { ret +=3D hpp__call_print_fn(hpp, print_fn, - fmt, len, 0.0); + fmt, len, val[idx].percent); } else { ret +=3D hpp__call_print_fn(hpp, print_fn, - fmt, len, 0ULL); + fmt, len, val[idx].period); } } + + free(val); } =20 /* --=20 2.43.0.687.g38aa6559b0-goog From nobody Sun Feb 8 07:02:02 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 4427618C1A; 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=1707810779; cv=none; b=KD5FNiac0OF0mScWSFCXr8pU8yLyGmsoD1vDJaOwUz/4LaDv0EGviS+O5vJpMbnngvQOULG7d9kha9YfzL6/oVjDnt48nlDbz/+UKuQbXK8SHetnK9sBRVl6sWaWUly3uT+Ymc3nYaxumvqAPW2lgt0pdDzanx4dqlKzkhifaVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707810779; c=relaxed/simple; bh=/cAFvtSoMi2WFvvFOaWCdmF3lcgANJyG3cErhVuBZ3Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G8ul/i2vhAcX4hpxsQuAnRBTsa8VipPNyHguDrC3noTZB5ppejSJ+0Sm/jVOvtCUL4ZY4Xyx9aRwg55vhGU1P+R0LjHtlZonhz+3LBNZOkZz+1lJRuwSYg9xFhubBahXL+RbYfP2m0cfxTGIOjnj4MM+CjbuIh5qtyMU0QCgO8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nnufl34i; 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="nnufl34i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67A32C433C7; Tue, 13 Feb 2024 07:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707810778; bh=/cAFvtSoMi2WFvvFOaWCdmF3lcgANJyG3cErhVuBZ3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nnufl34iNC3PJN5Ds6rRUdfaW5U9p2ah3WGrMWoIOVvx6meTPJyvRYbKJ2VaWyEpW JwENBqr0ykiQo0dWSIrefm/0Q3hCBelXViKWu6WnXs1/D+eQxTjCDrspxoXrf5EhhM hkT0uEhvSSnwieywqmxuphXVUYOrios9WcUb1q/hxbZx5KmVcJf1FVVuBL7NihNQp6 fYsmE51MaZ5UWNh3X63jbf74uJzpBmpXClyoZPS6grNXRnBwGCjhjqkr5zPfys4DoT ns/e68RUr2CY0OTxJ/F0Ospavzi4qyYapfM7i+OnslVuD/yU1rBP9yPRbnI3Oreubc snyzjTj+UcECQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 3/4] perf hist: Do not use event index in hpp__fmt() Date: Mon, 12 Feb 2024 23:52:55 -0800 Message-ID: <20240213075256.1983638-4-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The __hpp__fmt() is to print period values in a hist entry. It handles event groups using linked pair entries. Until now, it used event index to print values of group members. But we want to make it more robust and support groups even if some members in the group were removed. Let's use an index table from evsel to value array so that we can skip dummy events in the output later. Signed-off-by: Namhyung Kim --- tools/perf/ui/hist.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 5f4c110d840f..9c4c738edde1 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -48,15 +48,30 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist= _entry *he, if (evsel__is_group_event(evsel)) { int idx; struct hist_entry *pair; - int nr_members =3D evsel->core.nr_members; + int nr_members =3D evsel->core.nr_members - 1; union { u64 period; double percent; } *val; + struct evsel *member; + struct evsel **idx_table; =20 val =3D calloc(nr_members, sizeof(*val)); if (val =3D=3D NULL) - return 0; + goto out; + + idx_table =3D calloc(nr_members, sizeof(*idx_table)); + if (idx_table =3D=3D NULL) + goto out; + + /* + * Build an index table for each evsel to the val array. + * It cannot use evsel->core.idx because removed events might + * create a hole so the index is not consecutive anymore. + */ + idx =3D 0; + for_each_group_member(member, evsel) + idx_table[idx++] =3D member; =20 /* collect values in the group members */ list_for_each_entry(pair, &he->pairs.head, pairs.node) { @@ -66,8 +81,15 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_= entry *he, if (!total) continue; =20 - evsel =3D hists_to_evsel(pair->hists); - idx =3D evsel__group_idx(evsel); + member =3D hists_to_evsel(pair->hists); + for (idx =3D 0; idx < nr_members; idx++) { + if (idx_table[idx] =3D=3D member) + break; + } + + /* this should not happen */ + if (idx =3D=3D nr_members) + continue; =20 if (fmt_percent) val[idx].percent =3D 100.0 * period / total; @@ -75,8 +97,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_e= ntry *he, val[idx].period =3D period; } =20 - /* idx starts from 1 to skip the leader event */ - for (idx =3D 1; idx < nr_members; idx++) { + for (idx =3D 0; idx < nr_members; idx++) { if (fmt_percent) { ret +=3D hpp__call_print_fn(hpp, print_fn, fmt, len, val[idx].percent); @@ -89,6 +110,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_= entry *he, free(val); } =20 +out: /* * Restore original buf and size as it's where caller expects * the result will be saved. --=20 2.43.0.687.g38aa6559b0-goog From nobody Sun Feb 8 07:02:02 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 50D6518E37; Tue, 13 Feb 2024 07:52: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=1707810779; cv=none; b=I2S4KfD89XVSxFw+fRhb1Pdvk7j77qNDQW93hnBqmgOAU7Vb1kYIuXMX/33RK2A1RRf1Rq3LagodtddqO+VJP1UW0xXRMb8qP7vntf5YI3vORJyzcmwWq1PkZBaNf7Wh9u17+bNyh1prrMana1Gsxv/72WYJhCKMf+pVCVev06Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707810779; c=relaxed/simple; bh=iBUiWDW8Ai4qSjFVJLHHIZ87HU0SArsopllQZXXyTrI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UIGdF0XCjwCMLbNdm648pA7qfvCohzEyD1IjeUfexrZcwBeoHaUx9/DDRbrOekXFmk3B3SdPGhhBaQ8+owpERmQegmYCca1amtXHmkq8lAaPN8GKIxedOu87vsT8uwsbxy/V2xDHbx7NI2dRqRFzuOy+XqHI3ci/V+uPA/A0PfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oaBzEzXX; 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="oaBzEzXX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCD86C43330; Tue, 13 Feb 2024 07:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707810779; bh=iBUiWDW8Ai4qSjFVJLHHIZ87HU0SArsopllQZXXyTrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oaBzEzXXW7jZhGtjT0gxCZeIIIhE6Lwb6H4dPRwJ6q1eZjb9RexYg508HRr2GfPDq KvulJxx3AsqX6RyjTuELeZtDIGeO0MK2DGQ9pmgPMMu7shYprG6px+fV9Hnhw6JY3c FDBuLrkBNjvZVXNU7FMgOUVp/TLq9H3GU1mwbhNREJIioP+cdWDGmkHbfctd7vF1J/ aLVp3mLYszLHvdmvQipSnmDNzsLy+EFAfayIYeLnKZhNchsVJ06EjPjoycPU4ICmEi Us9s4LccIjtvHGzehkoBi+gApsL1Vj8BV+9z0kP3TaDpUoFfESwrpBwv417w7kjbgJ L3zlI4I7AVDlw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 4/4] perf report: Do not show dummy events with --skip-empty Date: Mon, 12 Feb 2024 23:52:56 -0800 Message-ID: <20240213075256.1983638-5-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In system-wide mode, a dummy event was added during the perf record to save various side-band events like FORK, MMAP and so on. But this dummy event doesn't have samples for itself so it just wastes the output with all zero values. When --skip-empty option is on (by default), it can skip those (dummy) events without any samples by removing them from the evlist. Users can disable it using --no-skip-empty command line option or setting the report.skip-empty config option to false. Signed-off-by: Namhyung Kim --- tools/perf/Documentation/perf-report.txt | 3 ++- tools/perf/builtin-report.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Document= ation/perf-report.txt index d8b863e01fe0..546af27d209c 100644 --- a/tools/perf/Documentation/perf-report.txt +++ b/tools/perf/Documentation/perf-report.txt @@ -609,7 +609,8 @@ include::itrace.txt[] 'Avg Cycles' - block average sampled cycles =20 --skip-empty:: - Do not print 0 results in the --stat output. + Do not print 0 results in the output. This means skipping dummy events + in the event list and the --stat output. =20 include::callchain-overhead-calculation.txt[] =20 diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 8e16fa261e6f..60e30f13c8f8 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -752,10 +752,22 @@ static int hists__resort_cb(struct hist_entry *he, vo= id *arg) static void report__output_resort(struct report *rep) { struct ui_progress prog; - struct evsel *pos; + struct evsel *pos, *tmp; =20 ui_progress__init(&prog, rep->nr_entries, "Sorting events for output..."); =20 + if (rep->skip_empty) { + evlist__for_each_entry_safe(rep->session->evlist, tmp, pos) { + struct hists *hists =3D evsel__hists(pos); + + if (hists->nr_entries !=3D 0) + continue; + + evlist__remove(rep->session->evlist, pos); + evsel__delete(pos); + } + } + evlist__for_each_entry(rep->session->evlist, pos) { evsel__output_resort_cb(pos, &prog, hists__resort_cb, rep); } --=20 2.43.0.687.g38aa6559b0-goog