1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <stdio.h>
4 #include <string.h>
5 #include <sdt.h>
6 
7 #define __PASTE(a, b) a##b
8 #define PASTE(a, b) __PASTE(a, b)
9 
10 #define NAME(name, idx) PASTE(name, idx)
11 
12 #define DEF(name, idx)  int NAME(name, idx)(void) { return 0; }
13 #define CALL(name, idx) NAME(name, idx)();
14 
15 #define F(body, name, idx) body(name, idx)
16 
17 #define F10(body, name, idx) \
18 	F(body, PASTE(name, idx), 0) F(body, PASTE(name, idx), 1) F(body, PASTE(name, idx), 2) \
19 	F(body, PASTE(name, idx), 3) F(body, PASTE(name, idx), 4) F(body, PASTE(name, idx), 5) \
20 	F(body, PASTE(name, idx), 6) F(body, PASTE(name, idx), 7) F(body, PASTE(name, idx), 8) \
21 	F(body, PASTE(name, idx), 9)
22 
23 #define F100(body, name, idx) \
24 	F10(body, PASTE(name, idx), 0) F10(body, PASTE(name, idx), 1) F10(body, PASTE(name, idx), 2) \
25 	F10(body, PASTE(name, idx), 3) F10(body, PASTE(name, idx), 4) F10(body, PASTE(name, idx), 5) \
26 	F10(body, PASTE(name, idx), 6) F10(body, PASTE(name, idx), 7) F10(body, PASTE(name, idx), 8) \
27 	F10(body, PASTE(name, idx), 9)
28 
29 #define F1000(body, name, idx) \
30 	F100(body, PASTE(name, idx), 0) F100(body, PASTE(name, idx), 1) F100(body, PASTE(name, idx), 2) \
31 	F100(body, PASTE(name, idx), 3) F100(body, PASTE(name, idx), 4) F100(body, PASTE(name, idx), 5) \
32 	F100(body, PASTE(name, idx), 6) F100(body, PASTE(name, idx), 7) F100(body, PASTE(name, idx), 8) \
33 	F100(body, PASTE(name, idx), 9)
34 
35 #define F10000(body, name, idx) \
36 	F1000(body, PASTE(name, idx), 0) F1000(body, PASTE(name, idx), 1) F1000(body, PASTE(name, idx), 2) \
37 	F1000(body, PASTE(name, idx), 3) F1000(body, PASTE(name, idx), 4) F1000(body, PASTE(name, idx), 5) \
38 	F1000(body, PASTE(name, idx), 6) F1000(body, PASTE(name, idx), 7) F1000(body, PASTE(name, idx), 8) \
39 	F1000(body, PASTE(name, idx), 9)
40 
41 F10000(DEF, uprobe_multi_func_, 0)
42 F10000(DEF, uprobe_multi_func_, 1)
43 F10000(DEF, uprobe_multi_func_, 2)
44 F10000(DEF, uprobe_multi_func_, 3)
45 F10000(DEF, uprobe_multi_func_, 4)
46 
bench(void)47 static int bench(void)
48 {
49 	F10000(CALL, uprobe_multi_func_, 0)
50 	F10000(CALL, uprobe_multi_func_, 1)
51 	F10000(CALL, uprobe_multi_func_, 2)
52 	F10000(CALL, uprobe_multi_func_, 3)
53 	F10000(CALL, uprobe_multi_func_, 4)
54 	return 0;
55 }
56 
57 #define PROBE STAP_PROBE(test, usdt);
58 
59 #define PROBE10    PROBE PROBE PROBE PROBE PROBE \
60 		   PROBE PROBE PROBE PROBE PROBE
61 #define PROBE100   PROBE10 PROBE10 PROBE10 PROBE10 PROBE10 \
62 		   PROBE10 PROBE10 PROBE10 PROBE10 PROBE10
63 #define PROBE1000  PROBE100 PROBE100 PROBE100 PROBE100 PROBE100 \
64 		   PROBE100 PROBE100 PROBE100 PROBE100 PROBE100
65 #define PROBE10000 PROBE1000 PROBE1000 PROBE1000 PROBE1000 PROBE1000 \
66 		   PROBE1000 PROBE1000 PROBE1000 PROBE1000 PROBE1000
67 
usdt(void)68 static int usdt(void)
69 {
70 	PROBE10000
71 	PROBE10000
72 	PROBE10000
73 	PROBE10000
74 	PROBE10000
75 	return 0;
76 }
77 
main(int argc,char ** argv)78 int main(int argc, char **argv)
79 {
80 	if (argc != 2)
81 		goto error;
82 
83 	if (!strcmp("bench", argv[1]))
84 		return bench();
85 	if (!strcmp("usdt", argv[1]))
86 		return usdt();
87 
88 error:
89 	fprintf(stderr, "usage: %s <bench|usdt>\n", argv[0]);
90 	return -1;
91 }
92