-
Notifications
You must be signed in to change notification settings - Fork 1
/
sched_latency.py
executable file
·51 lines (44 loc) · 1.21 KB
/
sched_latency.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
#!/usr/bin/env python
from bcc import BPF
from optparse import OptionParser
code='''
struct data_t {
u64 delta;
};
BPF_HASH(time);
BPF_PERF_OUTPUT(events);
TRACEPOINT_PROBE(irq_vectors, reschedule_entry) {
u64 key = bpf_get_smp_processor_id();
u64 t = bpf_ktime_get_ns();
time.update(&key, &t);
return 0;
}
TRACEPOINT_PROBE(irq_vectors, reschedule_exit) {
u64 key = bpf_get_smp_processor_id();
u64* kp;
kp = time.lookup(&key);
if (kp != NULL) {
struct data_t result;
result.delta = bpf_ktime_get_ns() - *kp;
events.perf_submit(args, &result, sizeof(result));
}
return 0;
}
'''
parser = OptionParser()
parser.add_option("-c", "--core", dest="core", help="Core to Trace", default=3, type=int)
(option, args) = parser.parse_args()
b = BPF(text = code)
def print_data(cpu, data, size):
e = b["events"].event(data)
if cpu == option.core:
print "%-8d %-16s" % (cpu, e.delta)
b["events"].open_perf_buffer(print_data)
print 'Running CPU %d Rescheduling Latency... Press Ctrl C-to Quit' % option.core
print '%-8s %-16s' % ("CPU", "LATENCY")
while True:
try:
b.perf_buffer_poll()
except KeyboardInterrupt:
print 'Exiting'
exit()