File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change
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
+ temp_dir=$( mktemp -d /tmp/perf-uprobe-different-cu-sh.XXXXXXXXXX)
8
+
9
+ cleanup ()
10
+ {
11
+ trap - EXIT TERM INT
12
+ if [[ " ${temp_dir} " =~ ^/tmp/perf-uprobe-different-cu-sh.* $ ]]; then
13
+ echo " --- Cleaning up ---"
14
+ perf probe -x ${temp_dir} /testfile -d foo
15
+ rm -f " ${temp_dir} /" *
16
+ rmdir " ${temp_dir} "
17
+ fi
18
+ }
19
+
20
+ trap_cleanup ()
21
+ {
22
+ cleanup
23
+ exit 1
24
+ }
25
+
26
+ trap trap_cleanup EXIT TERM INT
27
+
28
+ cat > ${temp_dir} /testfile-foo.h << EOF
29
+ struct t
30
+ {
31
+ int *p;
32
+ int c;
33
+ };
34
+
35
+ extern int foo (int i, struct t *t);
36
+ EOF
37
+
38
+ cat > ${temp_dir} /testfile-foo.c << EOF
39
+ #include "testfile-foo.h"
40
+
41
+ int
42
+ foo (int i, struct t *t)
43
+ {
44
+ int j, res = 0;
45
+ for (j = 0; j < i && j < t->c; j++)
46
+ res += t->p[j];
47
+
48
+ return res;
49
+ }
50
+ EOF
51
+
52
+ cat > ${temp_dir} /testfile-main.c << EOF
53
+ #include "testfile-foo.h"
54
+
55
+ static struct t g;
56
+
57
+ int
58
+ main (int argc, char **argv)
59
+ {
60
+ int i;
61
+ int j[argc];
62
+ g.c = argc;
63
+ g.p = j;
64
+ for (i = 0; i < argc; i++)
65
+ j[i] = (int) argv[i][0];
66
+ return foo (3, &g);
67
+ }
68
+ EOF
69
+
70
+ gcc -g -Og -flto -c ${temp_dir} /testfile-foo.c -o ${temp_dir} /testfile-foo.o
71
+ gcc -g -Og -c ${temp_dir} /testfile-main.c -o ${temp_dir} /testfile-main.o
72
+ gcc -g -Og -o ${temp_dir} /testfile ${temp_dir} /testfile-foo.o ${temp_dir} /testfile-main.o
73
+
74
+ perf probe -x ${temp_dir} /testfile --funcs foo
75
+ perf probe -x ${temp_dir} /testfile foo
76
+
77
+ cleanup
You can’t perform that action at this time.
0 commit comments