Skip to content

Commit cb42259

Browse files
Chun-Tse Shaoacmel
authored andcommitted
perf test: Add stat uniquifying test
The `stat+uniquify.sh` test retrieves all uniquified `clockticks` events from `perf list -v clockticks` and check if `perf stat -e clockticks -A` contains all of them. Committer testing: root@x1:~# grep -m1 "model name" /proc/cpuinfo model name : 13th Gen Intel(R) Core(TM) i7-1365U root@x1:~# perf list clockticks List of pre-defined events (to be used in -e or -M): uncore_clock/clockticks/ [Kernel PMU event] uncore memory: unc_m_clockticks [Number of clocks. Unit: uncore_imc] root@x1:~# root@x1:~# perf test uniquifying 92: perf stat events uniquifying : Ok root@x1:~# perf test -vv uniquifying 92: perf stat events uniquifying: --- start --- test child forked, pid 1552628 stat event uniquifying test ---- end(0) ---- 92: perf stat events uniquifying : Ok root@x1:~# 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: Andi Kleen <ak@linux.intel.com> Cc: Dr. David Alan Gilbert <linux@treblig.org> Cc: Howard Chu <howardchu95@gmail.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Levi Yun <yeoreum.yun@arm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Weilin Wang <weilin.wang@intel.com> Link: https://lore.kernel.org/r/20250513215401.2315949-4-ctshao@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 137359b commit cb42259

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
# perf stat events uniquifying
3+
# SPDX-License-Identifier: GPL-2.0
4+
5+
set -e
6+
7+
stat_output=$(mktemp /tmp/__perf_test.stat_output.XXXXX)
8+
perf_tool=perf
9+
err=0
10+
11+
test_event_uniquifying() {
12+
# We use `clockticks` to verify the uniquify behavior.
13+
event="clockticks"
14+
15+
# If the `-A` option is added, the event should be uniquified.
16+
#
17+
# $perf list -v clockticks
18+
#
19+
# List of pre-defined events (to be used in -e or -M):
20+
#
21+
# uncore_imc_0/clockticks/ [Kernel PMU event]
22+
# uncore_imc_1/clockticks/ [Kernel PMU event]
23+
# uncore_imc_2/clockticks/ [Kernel PMU event]
24+
# uncore_imc_3/clockticks/ [Kernel PMU event]
25+
# uncore_imc_4/clockticks/ [Kernel PMU event]
26+
# uncore_imc_5/clockticks/ [Kernel PMU event]
27+
#
28+
# ...
29+
#
30+
# $perf stat -e clockticks -A -- true
31+
#
32+
# Performance counter stats for 'system wide':
33+
#
34+
# CPU0 3,773,018 uncore_imc_0/clockticks/
35+
# CPU0 3,609,025 uncore_imc_1/clockticks/
36+
# CPU0 0 uncore_imc_2/clockticks/
37+
# CPU0 3,230,009 uncore_imc_3/clockticks/
38+
# CPU0 3,049,897 uncore_imc_4/clockticks/
39+
# CPU0 0 uncore_imc_5/clockticks/
40+
#
41+
# 0.002029828 seconds time elapsed
42+
43+
echo "stat event uniquifying test"
44+
uniquified_event_array=()
45+
46+
# Check how many uniquified events.
47+
while IFS= read -r line; do
48+
uniquified_event=$(echo "$line" | awk '{print $1}')
49+
uniquified_event_array+=("${uniquified_event}")
50+
done < <(${perf_tool} list -v ${event} | grep "\[Kernel PMU event\]")
51+
52+
perf_command="${perf_tool} stat -e $event -A -o ${stat_output} -- true"
53+
$perf_command
54+
55+
# Check the output contains all uniquified events.
56+
for uniquified_event in "${uniquified_event_array[@]}"; do
57+
if ! cat "${stat_output}" | grep -q "${uniquified_event}"; then
58+
echo "Event is not uniquified [Failed]"
59+
echo "${perf_command}"
60+
cat "${stat_output}"
61+
err=1
62+
break
63+
fi
64+
done
65+
}
66+
67+
test_event_uniquifying
68+
rm -f "${stat_output}"
69+
exit $err

0 commit comments

Comments
 (0)