linux/tools/perf/tests/shell/stat+event_uniquifying.sh
Chun-Tse Shao 070b315333 perf test: Restrict uniquifying test to machines with 'uncore_imc'
The test would fail if target machine does not have 'uncore_imc'
devices.

Since event uniquifying behavior is similar among different
architectures, we are restricting the test to only run on machines with
`uncore_imc` devices.

Suggested-by: Ian Rogers <irogers@google.com>
Signed-off-by: Chun-Tse Shao <ctshao@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250521224513.1104129-1-ctshao@google.com
[ Skip the test, i.e. return 2, instead of returning 0 as if the test had succeed ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2025-06-16 14:05:10 -03:00

77 lines
2.4 KiB
Bash
Executable file

#!/bin/bash
# perf stat events uniquifying
# SPDX-License-Identifier: GPL-2.0
set -e
stat_output=$(mktemp /tmp/__perf_test.stat_output.XXXXX)
perf_tool=perf
err=0
test_event_uniquifying() {
# We use `clockticks` in `uncore_imc` to verify the uniquify behavior.
pmu="uncore_imc"
event="clockticks"
# If the `-A` option is added, the event should be uniquified.
#
# $perf list -v clockticks
#
# List of pre-defined events (to be used in -e or -M):
#
# uncore_imc_0/clockticks/ [Kernel PMU event]
# uncore_imc_1/clockticks/ [Kernel PMU event]
# uncore_imc_2/clockticks/ [Kernel PMU event]
# uncore_imc_3/clockticks/ [Kernel PMU event]
# uncore_imc_4/clockticks/ [Kernel PMU event]
# uncore_imc_5/clockticks/ [Kernel PMU event]
#
# ...
#
# $perf stat -e clockticks -A -- true
#
# Performance counter stats for 'system wide':
#
# CPU0 3,773,018 uncore_imc_0/clockticks/
# CPU0 3,609,025 uncore_imc_1/clockticks/
# CPU0 0 uncore_imc_2/clockticks/
# CPU0 3,230,009 uncore_imc_3/clockticks/
# CPU0 3,049,897 uncore_imc_4/clockticks/
# CPU0 0 uncore_imc_5/clockticks/
#
# 0.002029828 seconds time elapsed
echo "stat event uniquifying test"
uniquified_event_array=()
# Skip if the machine does not have `uncore_imc` device.
if ! ${perf_tool} list pmu | grep -q ${pmu}; then
echo "Target does not support PMU ${pmu} [Skipped]"
err=2
return
fi
# Check how many uniquified events.
while IFS= read -r line; do
uniquified_event=$(echo "$line" | awk '{print $1}')
uniquified_event_array+=("${uniquified_event}")
done < <(${perf_tool} list -v ${event} | grep ${pmu})
perf_command="${perf_tool} stat -e $event -A -o ${stat_output} -- true"
$perf_command
# Check the output contains all uniquified events.
for uniquified_event in "${uniquified_event_array[@]}"; do
if ! cat "${stat_output}" | grep -q "${uniquified_event}"; then
echo "Event is not uniquified [Failed]"
echo "${perf_command}"
cat "${stat_output}"
err=1
break
fi
done
}
test_event_uniquifying
rm -f "${stat_output}"
exit $err