-
Notifications
You must be signed in to change notification settings - Fork 7
/
generate_runqlen_bpftrace.py
77 lines (62 loc) · 1.37 KB
/
generate_runqlen_bpftrace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import sys
start = [
"BEGIN\n",
"{\n",
"\t$i = 0;\n",
"\tprintf(\"[%12s],\", \"Timestamp\");\n",
]
mid1 = [
"\t\tprintf(\"CPU%3d,\", $i);\n",
"\t\t$i = $i + 1;\n",
"\t}\n",
"\tprintf(\"\\n\");\n",
"}\n",
"\n",
"kprobe:scheduler_tick\n",
"{\n",
"\t@runqlen[curtask->wake_cpu] = curtask->se.cfs_rq->rq->nr_running;\n",
"}\n",
"\n",
"tracepoint:power:cpu_idle\n",
"{\n",
"\t@runqlen[curtask->wake_cpu] = 0;\n",
"}\n",
"\n",
]
mid2 = [
"{\n",
"\t$i = 0;\n"
"\tprintf(\"[%12lld],\", elapsed);\n",
]
end = [
"\t\tprintf(\"%3d,\", @runqlen[$i]);\n",
"\t\t$i = $i + 1;\n",
"\t}\n",
"\tprintf(\"\\n\");\n",
"}\n",
"\n",
"END\n",
"{\n",
"\tclear(@runqlen);\n",
"}\n"
]
if __name__ == "__main__":
scriptdir = sys.argv[1]
nr_cpus = int(sys.argv[2])
profile_time = int(sys.argv[3])
profile_hz = 1000//profile_time
fout = open(scriptdir+"/runqlen.bt", "w")
condition = "\t%s%d%s" % ("while ($i < ",nr_cpus,") \n\t{\n")
interval_probe = "%s%d\n" %("interval:hz:", profile_hz)
for s in start:
fout.write(s)
fout.write(condition)
for s in mid1:
fout.write(s)
fout.write(interval_probe)
for s in mid2:
fout.write(s)
fout.write(condition)
for s in end:
fout.write(s)
fout.close()