Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # perf record offcpu profiling tests
0003 # SPDX-License-Identifier: GPL-2.0
0004 
0005 set -e
0006 
0007 err=0
0008 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
0009 
0010 cleanup() {
0011   rm -f ${perfdata}
0012   rm -f ${perfdata}.old
0013   trap - exit term int
0014 }
0015 
0016 trap_cleanup() {
0017   cleanup
0018   exit 1
0019 }
0020 trap trap_cleanup exit term int
0021 
0022 test_offcpu_priv() {
0023   echo "Checking off-cpu privilege"
0024 
0025   if [ `id -u` != 0 ]
0026   then
0027     echo "off-cpu test [Skipped permission]"
0028     err=2
0029     return
0030   fi
0031   if perf record --off-cpu -o /dev/null --quiet true 2>&1 | grep BUILD_BPF_SKEL
0032   then
0033     echo "off-cpu test [Skipped missing BPF support]"
0034     err=2
0035     return
0036   fi
0037 }
0038 
0039 test_offcpu_basic() {
0040   echo "Basic off-cpu test"
0041 
0042   if ! perf record --off-cpu -e dummy -o ${perfdata} sleep 1 2> /dev/null
0043   then
0044     echo "Basic off-cpu test [Failed record]"
0045     err=1
0046     return
0047   fi
0048   if ! perf evlist -i ${perfdata} | grep -q "offcpu-time"
0049   then
0050     echo "Basic off-cpu test [Failed no event]"
0051     err=1
0052     return
0053   fi
0054   if ! perf report -i ${perfdata} -q --percent-limit=90 | egrep -q sleep
0055   then
0056     echo "Basic off-cpu test [Failed missing output]"
0057     err=1
0058     return
0059   fi
0060   echo "Basic off-cpu test [Success]"
0061 }
0062 
0063 test_offcpu_child() {
0064   echo "Child task off-cpu test"
0065 
0066   # perf bench sched messaging creates 400 processes
0067   if ! perf record --off-cpu -e dummy -o ${perfdata} -- \
0068     perf bench sched messaging -g 10 > /dev/null 2&>1
0069   then
0070     echo "Child task off-cpu test [Failed record]"
0071     err=1
0072     return
0073   fi
0074   if ! perf evlist -i ${perfdata} | grep -q "offcpu-time"
0075   then
0076     echo "Child task off-cpu test [Failed no event]"
0077     err=1
0078     return
0079   fi
0080   # each process waits for read and write, so it should be more than 800 events
0081   if ! perf report -i ${perfdata} -s comm -q -n -t ';' --percent-limit=90 | \
0082     awk -F ";" '{ if (NF > 3 && int($3) < 800) exit 1; }'
0083   then
0084     echo "Child task off-cpu test [Failed invalid output]"
0085     err=1
0086     return
0087   fi
0088   echo "Child task off-cpu test [Success]"
0089 }
0090 
0091 
0092 test_offcpu_priv
0093 
0094 if [ $err = 0 ]; then
0095   test_offcpu_basic
0096 fi
0097 
0098 if [ $err = 0 ]; then
0099   test_offcpu_child
0100 fi
0101 
0102 cleanup
0103 exit $err