1#!/bin/sh 2# perf record offcpu profiling tests 3# SPDX-License-Identifier: GPL-2.0 4 5set -e 6 7err=0 8perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) 9 10cleanup() { 11 rm -f ${perfdata} 12 rm -f ${perfdata}.old 13 trap - exit term int 14} 15 16trap_cleanup() { 17 cleanup 18 exit 1 19} 20trap trap_cleanup exit term int 21 22test_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 57test_offcpu 58 59cleanup 60exit $err 61