diff options
Diffstat (limited to 'tools/perf/python/tracepoint.py')
-rwxr-xr-x | tools/perf/python/tracepoint.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/perf/python/tracepoint.py b/tools/perf/python/tracepoint.py new file mode 100755 index 000000000000..eb4dbed57de7 --- /dev/null +++ b/tools/perf/python/tracepoint.py | |||
@@ -0,0 +1,47 @@ | |||
1 | #! /usr/bin/python | ||
2 | # -*- python -*- | ||
3 | # -*- coding: utf-8 -*- | ||
4 | |||
5 | import perf | ||
6 | |||
7 | class tracepoint(perf.evsel): | ||
8 | def __init__(self, sys, name): | ||
9 | config = perf.tracepoint(sys, name) | ||
10 | perf.evsel.__init__(self, | ||
11 | type = perf.TYPE_TRACEPOINT, | ||
12 | config = config, | ||
13 | freq = 0, sample_period = 1, wakeup_events = 1, | ||
14 | sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU | perf.SAMPLE_RAW | perf.SAMPLE_TIME) | ||
15 | |||
16 | def main(): | ||
17 | tp = tracepoint("sched", "sched_switch") | ||
18 | cpus = perf.cpu_map() | ||
19 | threads = perf.thread_map(-1) | ||
20 | |||
21 | evlist = perf.evlist(cpus, threads) | ||
22 | evlist.add(tp) | ||
23 | evlist.open() | ||
24 | evlist.mmap() | ||
25 | |||
26 | while True: | ||
27 | evlist.poll(timeout = -1) | ||
28 | for cpu in cpus: | ||
29 | event = evlist.read_on_cpu(cpu) | ||
30 | if not event: | ||
31 | continue | ||
32 | |||
33 | if not isinstance(event, perf.sample_event): | ||
34 | continue | ||
35 | |||
36 | print "time %u prev_comm=%s prev_pid=%d prev_prio=%d prev_state=0x%x ==> next_comm=%s next_pid=%d next_prio=%d" % ( | ||
37 | event.sample_time, | ||
38 | event.prev_comm, | ||
39 | event.prev_pid, | ||
40 | event.prev_prio, | ||
41 | event.prev_state, | ||
42 | event.next_comm, | ||
43 | event.next_pid, | ||
44 | event.next_prio) | ||
45 | |||
46 | if __name__ == '__main__': | ||
47 | main() | ||