1 #!/bin/bash 2 # test perf probe of function from different CU 3 # SPDX-License-Identifier: GPL-2.0 4 5 set -e 6 7 # Skip if there's no probe command. 8 if ! perf | grep probe 9 then 10 echo "Skip: probe command isn't present" 11 exit 2 12 fi 13 14 # skip if there's no gcc 15 if ! [ -x "$(command -v gcc)" ]; then 16 echo "failed: no gcc compiler" 17 exit 2 18 fi 19 20 temp_dir=$(mktemp -d /tmp/perf-uprobe-different-cu-sh.XXXXXXXXXX) 21 22 cleanup() 23 { 24 trap - EXIT TERM INT 25 if [[ "${temp_dir}" =~ ^/tmp/perf-uprobe-different-cu-sh.*$ ]]; then 26 echo "--- Cleaning up ---" 27 perf probe -x ${temp_dir}/testfile -d foo || true 28 rm -f "${temp_dir}/"* 29 rmdir "${temp_dir}" 30 fi 31 } 32 33 trap_cleanup() 34 { 35 cleanup 36 exit 1 37 } 38 39 trap trap_cleanup EXIT TERM INT 40 41 cat > ${temp_dir}/testfile-foo.h << EOF 42 struct t 43 { 44 int *p; 45 int c; 46 }; 47 48 extern int foo (int i, struct t *t); 49 EOF 50 51 cat > ${temp_dir}/testfile-foo.c << EOF 52 #include "testfile-foo.h" 53 54 int 55 foo (int i, struct t *t) 56 { 57 int j, res = 0; 58 for (j = 0; j < i && j < t->c; j++) 59 res += t->p[j]; 60 61 return res; 62 } 63 EOF 64 65 cat > ${temp_dir}/testfile-main.c << EOF 66 #include "testfile-foo.h" 67 68 static struct t g; 69 70 int 71 main (int argc, char **argv) 72 { 73 int i; 74 int j[argc]; 75 g.c = argc; 76 g.p = j; 77 for (i = 0; i < argc; i++) 78 j[i] = (int) argv[i][0]; 79 return foo (3, &g); 80 } 81 EOF 82 83 gcc -g -Og -flto -c ${temp_dir}/testfile-foo.c -o ${temp_dir}/testfile-foo.o 84 gcc -g -Og -c ${temp_dir}/testfile-main.c -o ${temp_dir}/testfile-main.o 85 gcc -g -Og -o ${temp_dir}/testfile ${temp_dir}/testfile-foo.o ${temp_dir}/testfile-main.o 86 87 perf probe -x ${temp_dir}/testfile --funcs foo | grep "foo" 88 perf probe -x ${temp_dir}/testfile foo 89 90 cleanup
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.