Skip to content

Commit

Permalink
perf test: Add 'perf record cgroup' filtering test
Browse files Browse the repository at this point in the history
  $ sudo ./perf test filtering -vv
   96: perf record sample filtering (by BPF) tests:
  --- start ---
  test child forked, pid 2966908
  Checking BPF-filter privilege
  Basic bpf-filter test
  Basic bpf-filter test [Success]
  Failing bpf-filter test
  Failing bpf-filter test [Success]
  Group bpf-filter test
  Group bpf-filter test [Success]
  Multiple bpf-filter test
  Multiple bpf-filter test [Success]
  Cgroup bpf-filter test
  Cgroup bpf-filter test [Success]
  ---- end(0) ----
   96: perf record sample filtering (by BPF) tests                     : Ok

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240826221045.1202305-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
namhyung authored and acmel committed Aug 28, 2024
1 parent 91e8843 commit d56a4d5
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions tools/perf/tests/shell/record_bpf_filter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test_bpf_filter_fail() {

# 'cpu' requires PERF_SAMPLE_CPU flag
if ! perf record -e task-clock --filter 'cpu > 0' \
-o /dev/null true 2>&1 | grep PERF_SAMPLE_CPU
-o /dev/null true 2>&1 | grep -q PERF_SAMPLE_CPU
then
echo "Failing bpf-filter test [Failed forbidden CPU]"
err=1
Expand Down Expand Up @@ -98,15 +98,15 @@ test_bpf_filter_group() {
fi

if ! perf record -e task-clock --filter 'cpu > 0 || ip > 0' \
-o /dev/null true 2>&1 | grep PERF_SAMPLE_CPU
-o /dev/null true 2>&1 | grep -q PERF_SAMPLE_CPU
then
echo "Group bpf-filter test [Failed forbidden CPU]"
err=1
return
fi

if ! perf record -e task-clock --filter 'period > 0 || code_pgsz > 4096' \
-o /dev/null true 2>&1 | grep PERF_SAMPLE_CODE_PAGE_SIZE
-o /dev/null true 2>&1 | grep -q PERF_SAMPLE_CODE_PAGE_SIZE
then
echo "Group bpf-filter test [Failed forbidden CODE_PAGE_SIZE]"
err=1
Expand Down Expand Up @@ -147,6 +147,35 @@ test_bpf_filter_multi() {
echo "Multiple bpf-filter test [Success]"
}

test_bpf_filter_cgroup() {
echo "Cgroup bpf-filter test"

if ! perf record -e task-clock --filter 'cgroup == /' \
-a --all-cgroups --synth=cgroup -o "${perfdata}" true 2> /dev/null
then
echo "Cgroup bpf-filter test [Skipped cgroup not supported]"
return
fi

# 'cgroup' requires PERF_SAMPLE_CGROUP flag
if ! perf record -e task-clock --filter 'cgroup == /' \
-o /dev/null true 2>&1 | grep -q PERF_SAMPLE_CGROUP
then
echo "Cgroup bpf-filter test [Failed CGROUP requires --all-cgroups]"
err=1
return
fi

if ! perf report -i "${perfdata}" -s cgroup -q | grep -q -F '100.00%'
then
echo "Cgroup bpf-filter test [Failed root cgroup does not have 100%]"
err=1
return
fi

echo "Cgroup bpf-filter test [Success]"
}

test_bpf_filter_priv

if [ $err = 0 ]; then
Expand All @@ -165,5 +194,9 @@ if [ $err = 0 ]; then
test_bpf_filter_multi
fi

if [ $err = 0 ]; then
test_bpf_filter_cgroup
fi

cleanup
exit $err

0 comments on commit d56a4d5

Please sign in to comment.