[PATCH 4/9] perf dlfilter: Add non-empty branch stack filter
James Clark
james.clark at linaro.org
Thu Aug 13 01:31:24 PDT 2026
On 03/08/2026 10:06, Amir Ayupov wrote:
> --itrace=L adds decoded branch history to existing samples, but a sample
> that was recorded while the decoder had no trace for that thread keeps an
> empty branch stack. Consumers of the resulting perf script output, such
> as profile generators for context-sensitive PGO, have no use for those
> samples.
>
> Add an opt-in dlfilter that drops samples whose parsed branch stack is
> empty, so users can exclude them without changing default sample
> semantics. Build and install it alongside perf's existing dlfilters.
>
> Signed-off-by: Amir Ayupov <aaupov at fb.com>
> ---
> tools/perf/Makefile.perf | 1 +
> .../dlfilters/dlfilter-nonempty-brstack.c | 26 +++++++++++++++++++
> 2 files changed, 27 insertions(+)
> create mode 100644 tools/perf/dlfilters/dlfilter-nonempty-brstack.c
>
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 0031112c036e8..aeb8085b0756d 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -427,6 +427,7 @@ PROGRAMS += $(OUTPUT)$(LIBJVMTI)
> endif
>
> DLFILTERS := dlfilter-test-api-v0.so dlfilter-test-api-v2.so dlfilter-show-cycles.so
> +DLFILTERS += dlfilter-nonempty-brstack.so
> DLFILTERS := $(patsubst %,$(OUTPUT)dlfilters/%,$(DLFILTERS))
>
> # what 'all' will build and 'install' will install, in perfexecdir
> diff --git a/tools/perf/dlfilters/dlfilter-nonempty-brstack.c b/tools/perf/dlfilters/dlfilter-nonempty-brstack.c
> new file mode 100644
> index 0000000000000..9e66205b841d5
> --- /dev/null
> +++ b/tools/perf/dlfilters/dlfilter-nonempty-brstack.c
> @@ -0,0 +1,26 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * dlfilter-nonempty-brstack.c: Filter out samples with no branch stack
> + * Copyright (c) 2026, Meta Platforms, Inc.
> + */
> +#include <stddef.h>
> +
> +#include <perf/perf_dlfilter.h>
> +
> +int filter_event(void *data, const struct perf_dlfilter_sample *sample, void *ctx)
> +{
> + /* Return 1 to filter out the sample, 0 to keep it */
> + return !sample->brstack_nr;
> +}
> +
> +const char *filter_description(const char **long_description)
> +{
> + static char *long_desc =
> + "Instruction trace decoders can add branch history to existing "
> + "samples, but samples that were recorded while no trace was "
> + "being collected get an empty branch stack. Filter those out so "
> + "that only samples carrying branch history remain.";
> +
> + *long_description = long_desc;
> + return "Keep only samples with a non-empty branch stack";
> +}
Reviewed-by: James Clark <james.clark at linaro.org>
More information about the linux-arm-kernel
mailing list