From nobody Fri Feb 13 01:40:24 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 D68E713CF97; Mon, 3 Jun 2024 22:44:14 +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=1717454654; cv=none; b=cwypVuqoxaMerZ2ZtHZvPDTbvpSQ4QP6VvbOQjLgSHRcnzGW3EfXMkKpR0mohcYGudbCTc20HEQ++Kt1HzkJ3zI30hVpmTkEYv4rA+DdpVg3vPN0E5c1NLu6APrYNZI1UDHZnJIM8O+NNQUeYkO9SpG6SyWXBqhBr8KopGejfnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717454654; c=relaxed/simple; bh=TdJfb4b0EK7Er1ltY544EIHAZOToWommLg0CWKrIXRE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pcFJgSAYXTMviru9A/bDagK6glHervOWUt8aR6+TCzUC5VWLxNbuQ1tBrBPG3i4BLE7wulrieMZXvRIwmKhxTp1COPaVm6WkawtlKdmqIFbWouFbRFEkNZCLlbDCnhLMBLXUkudHplS7T6CHY3ogWJryGz9RpcM6Y48ivViLBDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UaUcSg8h; 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="UaUcSg8h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B475C32782; Mon, 3 Jun 2024 22:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717454654; bh=TdJfb4b0EK7Er1ltY544EIHAZOToWommLg0CWKrIXRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UaUcSg8htavfY3pUGIgBMBi7dgY+GqzZOKLr0qz7IQu3MB+ZU9At1vvdEcnvNVj4E tWJopEz+ZRc0xL/JyieuLGFGYCSS33XJCYVIksflKM7BJ77NOFjJGcYcWTdClXJR6X OpWO4sVwIt9YrizsR1ltW5mofhn62XTp1WigrdTXqAGXl5/Q/Pp56XOSnhxQY+G2uq sLt++gPesjV4QZN1QHELdPDyESWpL8Zf6eTwlQk7Q9vSYojYxvSBJ8WnUkgW13jutC hOmzDKYQ7I/tUrZ8a8yoeMfGdzRd/fmkval5+4AUPDE6Bp5KIAqkUTfxl1ufaxLHL0 e8L2dtnSj2YKA== 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/4] perf hist: Factor out __hpp__fmt_print() Date: Mon, 3 Jun 2024 15:44:09 -0700 Message-ID: <20240603224412.1910049-2-namhyung@kernel.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240603224412.1910049-1-namhyung@kernel.org> References: <20240603224412.1910049-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" Split the logic to print the histogram values according to the format string. This was used in 3 different places so it's better to move out the logic into a function. Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/ui/hist.c | 83 +++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 685ba2a54fd8..e30fcb1e87e7 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -23,35 +23,42 @@ __ret; \ }) =20 -static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, - hpp_field_fn get_field, const char *fmt, int len, - hpp_snprint_fn print_fn, enum perf_hpp_fmt_type fmtype) +static int __hpp__fmt_print(struct perf_hpp *hpp, struct hists *hists, u64= val, + int nr_samples, const char *fmt, int len, + hpp_snprint_fn print_fn, enum perf_hpp_fmt_type fmtype) { - int ret; - struct hists *hists =3D he->hists; - struct evsel *evsel =3D hists_to_evsel(hists); - char *buf =3D hpp->buf; - size_t size =3D hpp->size; - if (fmtype =3D=3D PERF_HPP_FMT_TYPE__PERCENT) { double percent =3D 0.0; u64 total =3D hists__total_period(hists); =20 if (total) - percent =3D 100.0 * get_field(he) / total; + percent =3D 100.0 * val / total; =20 - ret =3D hpp__call_print_fn(hpp, print_fn, fmt, len, percent); - } else if (fmtype =3D=3D PERF_HPP_FMT_TYPE__AVERAGE) { - double average =3D 0; + return hpp__call_print_fn(hpp, print_fn, fmt, len, percent); + } =20 - if (he->stat.nr_events) - average =3D 1.0 * get_field(he) / he->stat.nr_events; + if (fmtype =3D=3D PERF_HPP_FMT_TYPE__AVERAGE) { + double avg =3D nr_samples ? (1.0 * val / nr_samples) : 0; =20 - ret =3D hpp__call_print_fn(hpp, print_fn, fmt, len, average); - } else { - ret =3D hpp__call_print_fn(hpp, print_fn, fmt, len, get_field(he)); + return hpp__call_print_fn(hpp, print_fn, fmt, len, avg); } =20 + return hpp__call_print_fn(hpp, print_fn, fmt, len, val); +} + +static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, + hpp_field_fn get_field, const char *fmt, int len, + hpp_snprint_fn print_fn, enum perf_hpp_fmt_type fmtype) +{ + int ret; + struct hists *hists =3D he->hists; + struct evsel *evsel =3D hists_to_evsel(hists); + char *buf =3D hpp->buf; + size_t size =3D hpp->size; + + ret =3D __hpp__fmt_print(hpp, hists, get_field(he), he->stat.nr_events, + fmt, len, print_fn, fmtype); + if (evsel__is_group_event(evsel)) { int prev_idx, idx_delta; struct hist_entry *pair; @@ -72,30 +79,16 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist= _entry *he, =20 while (idx_delta--) { /* - * zero-fill group members in the middle which - * have no sample + * zero-fill group members in the middle which have + * no samples, pair->hists is not correct but it's + * fine since the value is 0. */ - if (fmtype !=3D PERF_HPP_FMT_TYPE__RAW) { - 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); - } + ret +=3D __hpp__fmt_print(hpp, pair->hists, 0, 0, + fmt, len, print_fn, fmtype); } =20 - if (fmtype =3D=3D PERF_HPP_FMT_TYPE__PERCENT) { - ret +=3D hpp__call_print_fn(hpp, print_fn, fmt, len, - 100.0 * period / total); - } else if (fmtype =3D=3D PERF_HPP_FMT_TYPE__AVERAGE) { - double avg =3D nr_samples ? (period / nr_samples) : 0; - - ret +=3D hpp__call_print_fn(hpp, print_fn, fmt, - len, avg); - } else { - ret +=3D hpp__call_print_fn(hpp, print_fn, fmt, - len, period); - } + ret +=3D __hpp__fmt_print(hpp, pair->hists, period, nr_samples, + fmt, len, print_fn, fmtype); =20 prev_idx =3D evsel__group_idx(evsel); } @@ -104,15 +97,11 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct his= t_entry *he, =20 while (idx_delta--) { /* - * zero-fill group members at last which have no sample + * zero-fill group members at last which have no sample. + * the hists is not correct but it's fine like above. */ - if (fmtype !=3D PERF_HPP_FMT_TYPE__RAW) { - 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); - } + ret +=3D __hpp__fmt_print(hpp, evsel__hists(evsel), 0, 0, + fmt, len, print_fn, fmtype); } } =20 --=20 2.45.1.288.g0e0cd299f1-goog From nobody Fri Feb 13 01:40:25 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 4424113CFAB; Mon, 3 Jun 2024 22:44:14 +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=1717454655; cv=none; b=CnQv+5a+fk1C1DQzje+jpnUjttNR8F2w+MdHHcTMfMFkiOZAnTn33Uu/cBgRxzyvmYFQt4WB7JejYM7bTRPQmh9nhPeW0mhP3m7S71yc6/AEcPeGkiO3T1BPkO4MMVaRhJXoN3qYl3VTiXSlRoPOI87ZzGaHPB5Y68xl9bc5N2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717454655; c=relaxed/simple; bh=Kg6743M4jK2pkp/b4Bbj59j6MAtu4SgkHWIqpEC7BU8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lmk5T06TWY0vHdjduXhek6fTUJyeeDfuyWZzKBJdumw1xedhBcboZfCkvo/AkPjnc6+mPm98r2RDpBAFayHSDL6y0KodVQF1oX3HU1KfEPGfoXcqq7GoXdo2hAEqbXqesHsZ1sTtOc3H1L2HitXHF+JWbKY2Kwf6wK7Y+wKoZ3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hKKMTpe5; 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="hKKMTpe5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82DE2C4AF0F; Mon, 3 Jun 2024 22:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717454654; bh=Kg6743M4jK2pkp/b4Bbj59j6MAtu4SgkHWIqpEC7BU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hKKMTpe5INUkTRoChzcNztB6VJHSviPAh3CiyC+KpSWvwVEynPJILJ/7YsJOAwdPB yyP1QnTXWAWdwQ+P4WplVNlXIo/iLalPWuc2pem7ZcZA4CUoZeLWzVmEprSEUoFo7l i/hIFfWyCTKaVXvebdKHx1qlLU6iDgR1ZHRrKF5/JF7IKJ2HUDRv3p2+I4ZRHyhScu qSMqkOo9tfi52LTL+BgRVAkHhpVaz6KHkA2Wo8zDDNEEFP/TV0hoYWf6HrTRR5fMsG Rbn4WZP/Gy0VJMBY9T+o1rY5xmby80D0aQI+zy3y9tGwsPrI9uIFH0ZfXfSg6Zc9N+ JYke+oYYunE0A== 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/4] perf hist: Simplify __hpp_fmt() using hpp_fmt_data Date: Mon, 3 Jun 2024 15:44:10 -0700 Message-ID: <20240603224412.1910049-3-namhyung@kernel.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240603224412.1910049-1-namhyung@kernel.org> References: <20240603224412.1910049-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 struct hpp_fmt_data is to keep the values for each group members so it doesn't need to check the event index in the group. Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/ui/hist.c | 75 +++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index e30fcb1e87e7..539978c95cfd 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -46,65 +46,62 @@ static int __hpp__fmt_print(struct perf_hpp *hpp, struc= t hists *hists, u64 val, return hpp__call_print_fn(hpp, print_fn, fmt, len, val); } =20 +struct hpp_fmt_data { + struct hists *hists; + u64 val; + int samples; +}; + static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, hpp_field_fn get_field, const char *fmt, int len, hpp_snprint_fn print_fn, enum perf_hpp_fmt_type fmtype) { - int ret; + int ret =3D 0; struct hists *hists =3D he->hists; struct evsel *evsel =3D hists_to_evsel(hists); + struct evsel *pos; char *buf =3D hpp->buf; size_t size =3D hpp->size; + int i, nr_members =3D 1; + struct hpp_fmt_data *data; + + if (evsel__is_group_event(evsel)) + nr_members =3D evsel->core.nr_members; + + data =3D calloc(nr_members, sizeof(*data)); + if (data =3D=3D NULL) + return 0; + + i =3D 0; + for_each_group_evsel(pos, evsel) + data[i++].hists =3D evsel__hists(pos); =20 - ret =3D __hpp__fmt_print(hpp, hists, get_field(he), he->stat.nr_events, - fmt, len, print_fn, fmtype); + data[0].val =3D get_field(he); + data[0].samples =3D he->stat.nr_events; =20 if (evsel__is_group_event(evsel)) { - int prev_idx, idx_delta; struct hist_entry *pair; - int nr_members =3D evsel->core.nr_members; - - prev_idx =3D evsel__group_idx(evsel); =20 list_for_each_entry(pair, &he->pairs.head, pairs.node) { - u64 period =3D get_field(pair); - u64 total =3D hists__total_period(pair->hists); - int nr_samples =3D pair->stat.nr_events; - - if (!total) - continue; + for (i =3D 0; i < nr_members; i++) { + if (data[i].hists !=3D pair->hists) + 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 samples, pair->hists is not correct but it's - * fine since the value is 0. - */ - ret +=3D __hpp__fmt_print(hpp, pair->hists, 0, 0, - fmt, len, print_fn, fmtype); + data[i].val =3D get_field(pair); + data[i].samples =3D pair->stat.nr_events; + break; } - - ret +=3D __hpp__fmt_print(hpp, pair->hists, period, nr_samples, - fmt, len, print_fn, fmtype); - - prev_idx =3D evsel__group_idx(evsel); } + } =20 - idx_delta =3D nr_members - prev_idx - 1; - - while (idx_delta--) { - /* - * zero-fill group members at last which have no sample. - * the hists is not correct but it's fine like above. - */ - ret +=3D __hpp__fmt_print(hpp, evsel__hists(evsel), 0, 0, - fmt, len, print_fn, fmtype); - } + for (i =3D 0; i < nr_members; i++) { + ret +=3D __hpp__fmt_print(hpp, data[i].hists, data[i].val, + data[i].samples, fmt, len, + print_fn, fmtype); } =20 + free(data); + /* * Restore original buf and size as it's where caller expects * the result will be saved. --=20 2.45.1.288.g0e0cd299f1-goog From nobody Fri Feb 13 01:40:25 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 8132313D244; Mon, 3 Jun 2024 22:44:15 +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=1717454655; cv=none; b=AU/uNDTA2AUsW6+b7dChua5FKs71FMip/ktJr4jeRi5ATUDrHFXmnoWZ6S/Zk8VmFKiK9pC7Wdf+ejdw6/jxPvwsK2TqeWKJ+xAhQXx5ixH7kaCkH4npSPlyUtdVJEhcKEm7Gtt5xV4gDzZ2gpG4nQIk3bINpPkrsmeb/9RfkbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717454655; c=relaxed/simple; bh=LRfIPWtEHi1TeH+Xj5dcWGvd3NaKK+FQJi7DsB6BcZc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DwXP5QEX7xTh5eeBgWJg3K/K7KfgK/xUmWrGDlb8q6Yg8GpurumjbSXAHBsx17cIuPD2Ry2R8adIeFI6SciLAEHkvfUAJh7IFHNGWfBW4+Zrd+EBqitDEf5v8vP5cgEXzZ9/mHMcERPoslZd6PY2G7IgYtIbxxloLyXX2NuW/ZU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TPiTUc77; 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="TPiTUc77" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06319C4AF07; Mon, 3 Jun 2024 22:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717454655; bh=LRfIPWtEHi1TeH+Xj5dcWGvd3NaKK+FQJi7DsB6BcZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TPiTUc77pd5WmM5jqZaaiChxDeEZ2Tf3CysgdDgVbCKebjN5+bXEYcQs1F0TemGGj Z+UBpM+rvIKRII5JvbYGcKoALZVgKGHQLXzhlVN0erDBIPQNTRSuIqfbjCb7xFQuPE UkpXgcspeTSHJWsfi06pu4pDRAPkqoJY3j89QQ7RXys/VEc0eYY9i/wFLKy1zyxahK OGp90yxjgltln8/ooVSsWoScHE4OEVqSmuIIN1PwhqxkEerLE9cxKTjWM+RCJwVV7U w3wHwa8FUVF8P5PGADRT0mgu3LyO0hdV+QFWAV8ME537VC8wpOH/azVgvMj/U2HEge SQKMZj5fqtEqw== 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/4] perf hist: Add symbol_conf.skip_empty Date: Mon, 3 Jun 2024 15:44:11 -0700 Message-ID: <20240603224412.1910049-4-namhyung@kernel.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240603224412.1910049-1-namhyung@kernel.org> References: <20240603224412.1910049-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" Add the skip_empty flag to symbol_conf and set the value from the report command to preserve the existing behavior. This makes the code simpler and will be needed other code which is hard to add a new argument. Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-annotate.c | 4 ++-- tools/perf/builtin-report.c | 12 ++++++------ tools/perf/ui/stdio/hist.c | 5 ++--- tools/perf/util/events_stats.h | 3 +-- tools/perf/util/hist.c | 6 +++--- tools/perf/util/hist.h | 3 +-- tools/perf/util/session.c | 5 ++--- tools/perf/util/session.h | 3 +-- tools/perf/util/symbol_conf.h | 3 ++- 9 files changed, 20 insertions(+), 24 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 50d2fb222d48..b10b7f005658 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -571,8 +571,8 @@ static int __cmd_annotate(struct perf_annotate *ann) goto out; =20 if (dump_trace) { - perf_session__fprintf_nr_events(session, stdout, false); - evlist__fprintf_nr_events(session->evlist, stdout, false); + perf_session__fprintf_nr_events(session, stdout); + evlist__fprintf_nr_events(session->evlist, stdout); goto out; } =20 diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 69618fb0110b..9718770facb5 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -810,8 +810,8 @@ static int stats_print(struct report *rep) { struct perf_session *session =3D rep->session; =20 - perf_session__fprintf_nr_events(session, stdout, rep->skip_empty); - evlist__fprintf_nr_events(session->evlist, stdout, rep->skip_empty); + perf_session__fprintf_nr_events(session, stdout); + evlist__fprintf_nr_events(session->evlist, stdout); return 0; } =20 @@ -1089,10 +1089,8 @@ static int __cmd_report(struct report *rep) perf_session__fprintf_dsos(session, stdout); =20 if (dump_trace) { - perf_session__fprintf_nr_events(session, stdout, - rep->skip_empty); - evlist__fprintf_nr_events(session->evlist, stdout, - rep->skip_empty); + perf_session__fprintf_nr_events(session, stdout); + evlist__fprintf_nr_events(session->evlist, stdout); return 0; } } @@ -1562,6 +1560,8 @@ int cmd_report(int argc, const char **argv) data.path =3D input_name; data.force =3D symbol_conf.force; =20 + symbol_conf.skip_empty =3D report.skip_empty; + repeat: session =3D perf_session__new(&data, &report.tool); if (IS_ERR(session)) { diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c index b849caace398..9372e8904d22 100644 --- a/tools/perf/ui/stdio/hist.c +++ b/tools/perf/ui/stdio/hist.c @@ -897,8 +897,7 @@ size_t hists__fprintf(struct hists *hists, bool show_he= ader, int max_rows, return ret; } =20 -size_t events_stats__fprintf(struct events_stats *stats, FILE *fp, - bool skip_empty) +size_t events_stats__fprintf(struct events_stats *stats, FILE *fp) { int i; size_t ret =3D 0; @@ -910,7 +909,7 @@ size_t events_stats__fprintf(struct events_stats *stats= , FILE *fp, name =3D perf_event__name(i); if (!strcmp(name, "UNKNOWN")) continue; - if (skip_empty && !stats->nr_events[i]) + if (symbol_conf.skip_empty && !stats->nr_events[i]) continue; =20 if (i && total) { diff --git a/tools/perf/util/events_stats.h b/tools/perf/util/events_stats.h index 8fecc9fbaecc..f43e5b1a366a 100644 --- a/tools/perf/util/events_stats.h +++ b/tools/perf/util/events_stats.h @@ -52,7 +52,6 @@ struct hists_stats { =20 void events_stats__inc(struct events_stats *stats, u32 type); =20 -size_t events_stats__fprintf(struct events_stats *stats, FILE *fp, - bool skip_empty); +size_t events_stats__fprintf(struct events_stats *stats, FILE *fp); =20 #endif /* __PERF_EVENTS_STATS_ */ diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 2e9e193179dd..f028f113c4fd 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -2706,8 +2706,7 @@ void hist__account_cycles(struct branch_stack *bs, st= ruct addr_location *al, } } =20 -size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp, - bool skip_empty) +size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp) { struct evsel *pos; size_t ret =3D 0; @@ -2715,7 +2714,8 @@ size_t evlist__fprintf_nr_events(struct evlist *evlis= t, FILE *fp, evlist__for_each_entry(evlist, pos) { struct hists *hists =3D evsel__hists(pos); =20 - if (skip_empty && !hists->stats.nr_samples && !hists->stats.nr_lost_samp= les) + if (symbol_conf.skip_empty && !hists->stats.nr_samples && + !hists->stats.nr_lost_samples) continue; =20 ret +=3D fprintf(fp, "%s stats:\n", evsel__name(pos)); diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 8fb3bdd29188..5273f5c37050 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -375,8 +375,7 @@ void hists__inc_nr_lost_samples(struct hists *hists, u3= 2 lost); size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, int max_cols, float min_pcnt, FILE *fp, bool ignore_callchains); -size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp, - bool skip_empty); +size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp); =20 void hists__filter_by_dso(struct hists *hists); void hists__filter_by_thread(struct hists *hists); diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index a10343b9dcd4..0ec92d47373c 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2696,8 +2696,7 @@ size_t perf_session__fprintf_dsos_buildid(struct perf= _session *session, FILE *fp return machines__fprintf_dsos_buildid(&session->machines, fp, skip, parm); } =20 -size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE = *fp, - bool skip_empty) +size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE = *fp) { size_t ret; const char *msg =3D ""; @@ -2707,7 +2706,7 @@ size_t perf_session__fprintf_nr_events(struct perf_se= ssion *session, FILE *fp, =20 ret =3D fprintf(fp, "\nAggregated stats:%s\n", msg); =20 - ret +=3D events_stats__fprintf(&session->evlist->stats, fp, skip_empty); + ret +=3D events_stats__fprintf(&session->evlist->stats, fp); return ret; } =20 diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 3b0256e977a6..4c29dc86956f 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -130,8 +130,7 @@ size_t perf_session__fprintf_dsos(struct perf_session *= session, FILE *fp); size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FI= LE *fp, bool (fn)(struct dso *dso, int parm), int parm); =20 -size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE = *fp, - bool skip_empty); +size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE = *fp); =20 void perf_session__dump_kmaps(struct perf_session *session); =20 diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h index c114bbceef40..657cfa5af43c 100644 --- a/tools/perf/util/symbol_conf.h +++ b/tools/perf/util/symbol_conf.h @@ -46,7 +46,8 @@ struct symbol_conf { lazy_load_kernel_maps, keep_exited_threads, annotate_data_member, - annotate_data_sample; + annotate_data_sample, + skip_empty; const char *vmlinux_name, *kallsyms_name, *source_prefix, --=20 2.45.1.288.g0e0cd299f1-goog From nobody Fri Feb 13 01:40:25 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 46D7B13D27F; Mon, 3 Jun 2024 22:44:15 +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=1717454656; cv=none; b=tjIpAX/6e7w5H3C7sD3j/C5QiOx5Yxh/i/fQI70GeYB+5k4LF5HbdpNHcmrQjSOnxveGHLQguxyBbO1GvpDfkEosS4oHdaYhhsXPaUqqC7QJ6o67D/x15SQWkjVGuuSThjt6ZhQzuuzhKCmjBLJb9FcggPonXeTw3na5YPoDHY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717454656; c=relaxed/simple; bh=jSrJ9iNN+XlHHSV30984S7Q4L1nAEpF0UPaMLYCqwls=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OtmeDSt/I+5hqzzhpwaGgoaDPzi9WhL8+zrtR9ZzEm94pvnsAxq3y05zqYlppEDPhoxnRqn7/8hiNcheoRrJF9H5fXjqrG8UTLxLJzaiNURNG1+xlX9L0WDVrBA9dz6pGdd80JKgMvutNuGW/QGRfqjGg8b3rbW1nb9//txksrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NdsIo1cG; 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="NdsIo1cG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E086C4AF0E; Mon, 3 Jun 2024 22:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717454655; bh=jSrJ9iNN+XlHHSV30984S7Q4L1nAEpF0UPaMLYCqwls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NdsIo1cGRDVOLo7Wc9L5DwpE676YaatVb0A00KZ+q3/e2HFYep7utc/faVMlW4I0p LWLBA9ZrIB1Z/OF1G5k8gnbQ+/zvo8it0anU29XD2gna1w7CuwjdrZ5QhY64MjwK0R A1Epr7I/b5apbN8S4xFhzrDkHGDharrm0xFWQY61WcmHL+/2PL4sNzrTK14lJ+DP1b RrpBcy409IyjYQ0pU/i0jPcXYoV4Zgc8TXXK601HkqSn0HLVQnmXYg7gC9tqRP3Jwx O2HhemQmEJ3iQ0l9KQZ8K8LAfzU7/24CtgyNBsA8yyCt4yDSNde/Y/tEya3ZEkweLm gWjoxLJKieszQ== 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/4] perf hist: Honor symbol_conf.skip_empty Date: Mon, 3 Jun 2024 15:44:12 -0700 Message-ID: <20240603224412.1910049-5-namhyung@kernel.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240603224412.1910049-1-namhyung@kernel.org> References: <20240603224412.1910049-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" So that it can skip events with no sample according to the config value. This can omit the dummy event in the output of perf report --group. Signed-off-by: Namhyung Kim Tested-by: Arnaldo Carvalho de Melo --- tools/perf/ui/hist.c | 18 ++++++++++++++++-- tools/perf/util/evsel.c | 13 ++++++++++--- tools/perf/util/python.c | 3 +++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 539978c95cfd..d76062979ab7 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -95,6 +95,10 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_= entry *he, } =20 for (i =3D 0; i < nr_members; i++) { + if (symbol_conf.skip_empty && + data[i].hists->stats.nr_samples =3D=3D 0) + continue; + ret +=3D __hpp__fmt_print(hpp, data[i].hists, data[i].val, data[i].samples, fmt, len, print_fn, fmtype); @@ -296,8 +300,18 @@ static int hpp__width_fn(struct perf_hpp_fmt *fmt, int len =3D fmt->user_len ?: fmt->len; struct evsel *evsel =3D hists_to_evsel(hists); =20 - if (symbol_conf.event_group) - len =3D max(len, evsel->core.nr_members * fmt->len); + if (symbol_conf.event_group) { + int nr =3D 0; + struct evsel *pos; + + for_each_group_evsel(pos, evsel) { + if (!symbol_conf.skip_empty || + evsel__hists(pos)->stats.nr_samples) + nr++; + } + + len =3D max(len, nr * fmt->len); + } =20 if (len < (int)strlen(fmt->name)) len =3D strlen(fmt->name); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 4f818ab6b662..befb80c272d2 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -53,6 +53,7 @@ #include "../perf-sys.h" #include "util/parse-branch-options.h" #include "util/bpf-filter.h" +#include "util/hist.h" #include #include #include @@ -830,16 +831,22 @@ const char *evsel__group_name(struct evsel *evsel) int evsel__group_desc(struct evsel *evsel, char *buf, size_t size) { int ret =3D 0; + bool first =3D true; struct evsel *pos; const char *group_name =3D evsel__group_name(evsel); =20 if (!evsel->forced_leader) ret =3D scnprintf(buf, size, "%s { ", group_name); =20 - ret +=3D scnprintf(buf + ret, size - ret, "%s", evsel__name(evsel)); + for_each_group_evsel(pos, evsel) { + if (symbol_conf.skip_empty && + evsel__hists(pos)->stats.nr_samples =3D=3D 0) + continue; =20 - for_each_group_member(pos, evsel) - ret +=3D scnprintf(buf + ret, size - ret, ", %s", evsel__name(pos)); + ret +=3D scnprintf(buf + ret, size - ret, "%s%s", + first ? "" : ", ", evsel__name(pos)); + first =3D false; + } =20 if (!evsel->forced_leader) ret +=3D scnprintf(buf + ret, size - ret, " }"); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 0aeb97c11c03..88f98f2772fb 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -23,6 +23,7 @@ #include "util/env.h" #include "util/pmu.h" #include "util/pmus.h" +#include "util/symbol_conf.h" #include #include "util.h" =20 @@ -50,6 +51,8 @@ #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) #endif =20 +struct symbol_conf symbol_conf; + /* * Avoid bringing in event parsing. */ --=20 2.45.1.288.g0e0cd299f1-goog