Skip to content

Commit 831d06c

Browse files
namhyungacmel
authored andcommitted
perf test: Add a basic offcpu profiling test
$ sudo ./perf test -v offcpu 88: perf record offcpu profiling tests : --- start --- test child forked, pid 685966 Basic off-cpu test Basic off-cpu test [Success] test child finished with 0 ---- end ---- perf record offcpu profiling tests: Ok Signed-off-by: Namhyung Kim <namhyung@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Acked-by: Ian Rogers <irogers@google.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Blake Jones <blakejones@google.com> Cc: Hao Luo <haoluo@google.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Milian Wolff <milian.wolff@kdab.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <songliubraving@fb.com> Cc: bpf@vger.kernel.org Link: https://lore.kernel.org/r/20220518224725.742882-7-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 685439a commit 831d06c

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
# perf record offcpu profiling tests
3+
# SPDX-License-Identifier: GPL-2.0
4+
5+
set -e
6+
7+
err=0
8+
perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
9+
10+
cleanup() {
11+
rm -f ${perfdata}
12+
rm -f ${perfdata}.old
13+
trap - exit term int
14+
}
15+
16+
trap_cleanup() {
17+
cleanup
18+
exit 1
19+
}
20+
trap trap_cleanup exit term int
21+
22+
test_offcpu() {
23+
echo "Basic off-cpu test"
24+
if [ `id -u` != 0 ]
25+
then
26+
echo "Basic off-cpu test [Skipped permission]"
27+
err=2
28+
return
29+
fi
30+
if perf record --off-cpu -o ${perfdata} --quiet true 2>&1 | grep BUILD_BPF_SKEL
31+
then
32+
echo "Basic off-cpu test [Skipped missing BPF support]"
33+
err=2
34+
return
35+
fi
36+
if ! perf record --off-cpu -e dummy -o ${perfdata} sleep 1 2> /dev/null
37+
then
38+
echo "Basic off-cpu test [Failed record]"
39+
err=1
40+
return
41+
fi
42+
if ! perf evlist -i ${perfdata} | grep -q "offcpu-time"
43+
then
44+
echo "Basic off-cpu test [Failed record]"
45+
err=1
46+
return
47+
fi
48+
if ! perf report -i ${perfdata} -q --percent-limit=90 | egrep -q sleep
49+
then
50+
echo "Basic off-cpu test [Failed missing output]"
51+
err=1
52+
return
53+
fi
54+
echo "Basic off-cpu test [Success]"
55+
}
56+
57+
test_offcpu
58+
59+
cleanup
60+
exit $err

0 commit comments

Comments
 (0)