~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/sh
  2 # perf stat --bpf-counters --for-each-cgroup test
  3 # SPDX-License-Identifier: GPL-2.0
  4 
  5 set -e
  6 
  7 test_cgroups=
  8 if [ "$1" = "-v" ]; then
  9         verbose="1"
 10 fi
 11 
 12 # skip if --bpf-counters --for-each-cgroup is not supported
 13 check_bpf_counter()
 14 {
 15         if ! perf stat -a --bpf-counters --for-each-cgroup / true > /dev/null 2>&1; then
 16                 if [ "${verbose}" = "1" ]; then
 17                         echo "Skipping: --bpf-counters --for-each-cgroup not supported"
 18                         perf --no-pager stat -a --bpf-counters --for-each-cgroup / true || true
 19                 fi
 20                 exit 2
 21         fi
 22 }
 23 
 24 # find two cgroups to measure
 25 find_cgroups()
 26 {
 27         # try usual systemd slices first
 28         if [ -d /sys/fs/cgroup/system.slice ] && [ -d /sys/fs/cgroup/user.slice ]; then
 29                 test_cgroups="system.slice,user.slice"
 30                 return
 31         fi
 32 
 33         # try root and self cgroups
 34         find_cgroups_self_cgrp=$(grep perf_event /proc/self/cgroup | cut -d: -f3)
 35         if [ -z ${find_cgroups_self_cgrp} ]; then
 36                 # cgroup v2 doesn't specify perf_event
 37                 find_cgroups_self_cgrp=$(grep ^0: /proc/self/cgroup | cut -d: -f3)
 38         fi
 39 
 40         if [ -z ${find_cgroups_self_cgrp} ]; then
 41                 test_cgroups="/"
 42         else
 43                 test_cgroups="/,${find_cgroups_self_cgrp}"
 44         fi
 45 }
 46 
 47 # As cgroup events are cpu-wide, we cannot simply compare the result.
 48 # Just check if it runs without failure and has non-zero results.
 49 check_system_wide_counted()
 50 {
 51         check_system_wide_counted_output=$(perf stat -a --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, sleep 1  2>&1)
 52         if echo ${check_system_wide_counted_output} | grep -q -F "<not "; then
 53                 echo "Some system-wide events are not counted"
 54                 if [ "${verbose}" = "1" ]; then
 55                         echo ${check_system_wide_counted_output}
 56                 fi
 57                 exit 1
 58         fi
 59 }
 60 
 61 check_cpu_list_counted()
 62 {
 63         check_cpu_list_counted_output=$(perf stat -C 0,1 --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, taskset -c 1 sleep 1  2>&1)
 64         if echo ${check_cpu_list_counted_output} | grep -q -F "<not "; then
 65                 echo "Some CPU events are not counted"
 66                 if [ "${verbose}" = "1" ]; then
 67                         echo ${check_cpu_list_counted_output}
 68                 fi
 69                 exit 1
 70         fi
 71 }
 72 
 73 check_bpf_counter
 74 find_cgroups
 75 
 76 check_system_wide_counted
 77 check_cpu_list_counted
 78 
 79 exit 0

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php