* [PATCH] perf report: Fix sample number stats for branch entry mode
@ 2025-02-19 21:53 Thomas Falcon
2025-02-20 4:40 ` Falcon, Thomas
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Falcon @ 2025-02-19 21:53 UTC (permalink / raw)
To: linux-perf-users; +Cc: Thomas Falcon
Currently, stats->nr_samples is incremented per entry in the sample's
branch stack instead of per sample taken. As a result, statistics of
samples taken during perf record in --branch-filter mode do not seem
correct. Call hists__inc_nr_samples() only for each sample taken.
Before:
$ ./perf record -e cycles:u -b -c 10000000000 ./tchain_edit
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (2 samples) ]
$ perf report -D | tail -n 16
Aggregated stats:
TOTAL events: 16
COMM events: 2 (12.5%)
EXIT events: 1 ( 6.2%)
SAMPLE events: 2 (12.5%)
MMAP2 events: 2 (12.5%)
KSYMBOL events: 1 ( 6.2%)
FINISHED_ROUND events: 1 ( 6.2%)
ID_INDEX events: 1 ( 6.2%)
THREAD_MAP events: 1 ( 6.2%)
CPU_MAP events: 1 ( 6.2%)
EVENT_UPDATE events: 2 (12.5%)
TIME_CONV events: 1 ( 6.2%)
FINISHED_INIT events: 1 ( 6.2%)
cpu_core/cycles/u stats:
SAMPLE events: 64
After:
$ ./perf report -D | tail -n 16
Aggregated stats:
TOTAL events: 16
COMM events: 2 (12.5%)
EXIT events: 1 ( 6.2%)
SAMPLE events: 2 (12.5%)
MMAP2 events: 2 (12.5%)
KSYMBOL events: 1 ( 6.2%)
FINISHED_ROUND events: 1 ( 6.2%)
ID_INDEX events: 1 ( 6.2%)
THREAD_MAP events: 1 ( 6.2%)
CPU_MAP events: 1 ( 6.2%)
EVENT_UPDATE events: 2 (12.5%)
TIME_CONV events: 1 ( 6.2%)
FINISHED_INIT events: 1 ( 6.2%)
cpu_core/cycles/u stats:
SAMPLE events: 2
Signed-off-by: Thomas Falcon <thomas.falcon@intel.com>
---
tools/perf/util/hist.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 0f30f843c566..4ae56a2a4d34 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -975,8 +975,6 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a
if (he == NULL)
return -ENOMEM;
- hists__inc_nr_samples(hists, he->filtered);
-
out:
iter->he = he;
iter->curr++;
@@ -995,9 +993,14 @@ static int
iter_finish_branch_entry(struct hist_entry_iter *iter,
struct addr_location *al __maybe_unused)
{
+ struct evsel *evsel = iter->evsel;
+ struct hists *hists = evsel__hists(evsel);
+
for (int i = 0; i < iter->total; i++)
branch_info__exit(&iter->bi[i]);
+ hists__inc_nr_samples(hists, iter->he->filtered);
+
zfree(&iter->bi);
iter->he = NULL;
--
2.48.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] perf report: Fix sample number stats for branch entry mode
2025-02-19 21:53 [PATCH] perf report: Fix sample number stats for branch entry mode Thomas Falcon
@ 2025-02-20 4:40 ` Falcon, Thomas
0 siblings, 0 replies; 2+ messages in thread
From: Falcon, Thomas @ 2025-02-20 4:40 UTC (permalink / raw)
To: linux-perf-users@vger.kernel.org
On Wed, 2025-02-19 at 15:53 -0600, Thomas Falcon wrote:
> Currently, stats->nr_samples is incremented per entry in the sample's
> branch stack instead of per sample taken. As a result, statistics of
> samples taken during perf record in --branch-filter mode do not seem
> correct. Call hists__inc_nr_samples() only for each sample taken.
>
> Before:
>
> $ ./perf record -e cycles:u -b -c 10000000000 ./tchain_edit
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 0.005 MB perf.data (2 samples) ]
> $ perf report -D | tail -n 16
> Aggregated stats:
> TOTAL events: 16
> COMM events: 2 (12.5%)
> EXIT events: 1 ( 6.2%)
> SAMPLE events: 2 (12.5%)
> MMAP2 events: 2 (12.5%)
> KSYMBOL events: 1 ( 6.2%)
> FINISHED_ROUND events: 1 ( 6.2%)
> ID_INDEX events: 1 ( 6.2%)
> THREAD_MAP events: 1 ( 6.2%)
> CPU_MAP events: 1 ( 6.2%)
> EVENT_UPDATE events: 2 (12.5%)
> TIME_CONV events: 1 ( 6.2%)
> FINISHED_INIT events: 1 ( 6.2%)
> cpu_core/cycles/u stats:
> SAMPLE events: 64
>
> After:
>
> $ ./perf report -D | tail -n 16
> Aggregated stats:
> TOTAL events: 16
> COMM events: 2 (12.5%)
> EXIT events: 1 ( 6.2%)
> SAMPLE events: 2 (12.5%)
> MMAP2 events: 2 (12.5%)
> KSYMBOL events: 1 ( 6.2%)
> FINISHED_ROUND events: 1 ( 6.2%)
> ID_INDEX events: 1 ( 6.2%)
> THREAD_MAP events: 1 ( 6.2%)
> CPU_MAP events: 1 ( 6.2%)
> EVENT_UPDATE events: 2 (12.5%)
> TIME_CONV events: 1 ( 6.2%)
> FINISHED_INIT events: 1 ( 6.2%)
> cpu_core/cycles/u stats:
> SAMPLE events: 2
>
> Signed-off-by: Thomas Falcon <thomas.falcon@intel.com>
> ---
> tools/perf/util/hist.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
> index 0f30f843c566..4ae56a2a4d34 100644
> --- a/tools/perf/util/hist.c
> +++ b/tools/perf/util/hist.c
> @@ -975,8 +975,6 @@ iter_add_next_branch_entry(struct hist_entry_iter
> *iter, struct addr_location *a
> if (he == NULL)
> return -ENOMEM;
>
> - hists__inc_nr_samples(hists, he->filtered);
> -
> out:
> iter->he = he;
> iter->curr++;
> @@ -995,9 +993,14 @@ static int
> iter_finish_branch_entry(struct hist_entry_iter *iter,
> struct addr_location *al __maybe_unused)
> {
> + struct evsel *evsel = iter->evsel;
> + struct hists *hists = evsel__hists(evsel);
> +
> for (int i = 0; i < iter->total; i++)
> branch_info__exit(&iter->bi[i]);
>
> + hists__inc_nr_samples(hists, iter->he->filtered);
> +
Sorry, I missed a null check for iter->he here I think, will send a v2.
Tom
> zfree(&iter->bi);
> iter->he = NULL;
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-20 4:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-19 21:53 [PATCH] perf report: Fix sample number stats for branch entry mode Thomas Falcon
2025-02-20 4:40 ` Falcon, Thomas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).