Skip to content

perf bpf-filter: Add cgroup filter term (v1)

Namhyung Kim linux-perf-users lkml 1 version Applied

Status from this message: Thanks, applied the series to perf-tools-next,

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 1 replyApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/4perf report: Fix segfault when 'sym' sort key is not usedtools/perf/util/hist.c+1 -11 reply
2/4perf bpf-filter: Add build dependency to header filestools/perf/util/Build+2 -20 replies
3/4perf bpf-filter: Support filtering on cgroupstools/perf/util/bpf-filter.c tools/perf/util/bpf-filter.l tools/perf/util/bpf-filter.y +3 more+55 -90 replies
4/4perf test: Add perf record cgroup filtering testtools/perf/tests/shell/record_bpf_filter.sh+36 -30 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] perf bpf-filter: Add cgroup filter term (v1)

Hello,

I'm adding a new 'cgroup' filter term in the filter expression so that it can be used in the BPF.

The cgroup filter takes a pathname and allows either '==' or '!=' operators only. The requires '--all-cgroups' option so it can see the cgroup_id in the sample data. Actually BPF programs can get the cgroup of the current task without looking sample data, but I added it for consistency with other fields.

  $ sudo perf record --synth=cgroup -e cycles --filter 'cgroup > /' -a true
  perf_bpf_filter: cgroup accepts '==' or '!=' only

Usage: perf record [<options>] [<command>]
or: perf record [<options>] -- <command> [<options>]

--filter <filter>
event filter

  $ sudo perf record -e cycles --filter 'cgroup == /' \
      -a --synth=cgroup -o- sleep 1 | perf report -i- -s cgroup
  Error: cycles event does not have PERF_SAMPLE_CGROUP
   Hint: please add --all-cgroups option to perf record
  Failed to process filter entries
  failed to set filter "BPF" on event cycles with 2 (No such file or directory)
  incompatible file format (rerun with -v to learn more)

On the filter syntax, it used to reject arbitrary strings. But it needs to handle strings because of the cgroup paths. For now, the bpf filter parser will reject strings if it's not used for cgroups.

For now, it only supports the exact matching of target cgroups. So specifying the root cgroup ("/") will match tasks in the root cgroup directly (not in the descendants).

  $ sudo perf record --all-cgroups -e cycles --filter 'cgroup == /' \
      -a --synth=cgroup -o- sleep 1 | perf report -i- -s cgroup
  ...
  #
  # Total Lost Samples: 0
  #
  # Samples: 621  of event 'cycles'
  # Event count (approx.): 108101281
  #
  # Overhead  Cgroup
  # ........  ......
  #
     100.00%  /

Thanks,
Namhyung

Namhyung Kim (4):
perf report: Fix segfault when 'sym' sort key is not used perf bpf-filter: Add build dependency to header files perf bpf-filter: Support filtering on cgroups perf test: Add perf record cgroup filtering test

 tools/perf/tests/shell/record_bpf_filter.sh  | 39 ++++++++++++++++++--
 tools/perf/util/Build                        |  4 +-
 tools/perf/util/bpf-filter.c                 |  1 +
 tools/perf/util/bpf-filter.l                 | 28 +++++++++++---
 tools/perf/util/bpf-filter.y                 | 28 +++++++++++++-
 tools/perf/util/bpf_skel/sample-filter.h     |  2 +-
 tools/perf/util/bpf_skel/sample_filter.bpf.c |  4 +-
 tools/perf/util/bpf_skel/vmlinux/vmlinux.h   |  1 +
 tools/perf/util/hist.c                       |  2 +-
 9 files changed, 94 insertions(+), 15 deletions(-)
Signature · 1 line
2.46.0.295.g3b9ea8a38a-goog