Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # perf pipe recording and injection test
0003 # SPDX-License-Identifier: GPL-2.0
0004 
0005 # skip if there's no compiler
0006 if ! [ -x "$(command -v cc)" ]; then
0007         echo "failed: no compiler, install gcc"
0008         exit 2
0009 fi
0010 
0011 file=$(mktemp /tmp/test.file.XXXXXX)
0012 data=$(mktemp /tmp/perf.data.XXXXXX)
0013 
0014 cat <<EOF | cc -o ${file} -x c -
0015 #include <signal.h>
0016 #include <stdlib.h>
0017 #include <unistd.h>
0018 
0019 volatile int done;
0020 
0021 void sigalrm(int sig) {
0022         done = 1;
0023 }
0024 
0025 __attribute__((noinline)) void noploop(void) {
0026         while (!done)
0027                 continue;
0028 }
0029 
0030 int main(int argc, char *argv[]) {
0031         int sec = 1;
0032 
0033         if (argc > 1)
0034                 sec = atoi(argv[1]);
0035 
0036         signal(SIGALRM, sigalrm);
0037         alarm(sec);
0038 
0039         noploop();
0040         return 0;
0041 }
0042 EOF
0043 
0044 
0045 if ! perf record -e task-clock:u -o - ${file} | perf report -i - --task | grep test.file; then
0046         echo "cannot find the test file in the perf report"
0047         exit 1
0048 fi
0049 
0050 if ! perf record -e task-clock:u -o - ${file} | perf inject -b | perf report -i - | grep noploop; then
0051         echo "cannot find noploop function in pipe #1"
0052         exit 1
0053 fi
0054 
0055 perf record -e task-clock:u -o - ${file} | perf inject -b -o ${data}
0056 if ! perf report -i ${data} | grep noploop; then
0057         echo "cannot find noploop function in pipe #2"
0058         exit 1
0059 fi
0060 
0061 perf record -e task-clock:u -o ${data} ${file}
0062 if ! perf inject -b -i ${data} | perf report -i - | grep noploop; then
0063         echo "cannot find noploop function in pipe #3"
0064         exit 1
0065 fi
0066 
0067 
0068 rm -f ${file} ${data} ${data}.old
0069 exit 0