aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/python
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2015-10-06 16:46:46 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-10-07 18:41:50 -0400
commitae938802443732e77d01f8d5b52b900b9327ff30 (patch)
tree67ee10943f425619e70850628c5f164aa0e13dc2 /tools/perf/python
parent38349665388fb079fb2bc8c46db9446dd976802a (diff)
perf python: Support the PERF_RECORD_SWITCH event
To test it check tools/perf/python/twatch.py, after following the instructions there to enable context_switch, output looks like: [root@zoo linux]# tools/perf/python/twatch.py cpu: 1, pid: 31463, tid: 31463 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31463, switch_out: 0 } cpu: 2, pid: 31463, tid: 31496 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31496, switch_out: 0 } cpu: 2, pid: 31463, tid: 31496 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31496, switch_out: 1 } cpu: 3, pid: 31463, tid: 31527 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31527, switch_out: 0 } cpu: 1, pid: 31463, tid: 31463 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31463, switch_out: 1 } cpu: 3, pid: 31463, tid: 31527 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31527, switch_out: 1 } cpu: 1, pid: 31463, tid: 31463 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31463, switch_out: 0 } ^CTraceback (most recent call last): File "tools/perf/python/twatch.py", line 67, in <module> main(context_switch = 1, thread = 31463) File "tools/perf/python/twatch.py", line 40, in main evlist.poll(timeout = -1) KeyboardInterrupt [root@zoo linux]# Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Guy Streeter <streeter@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Stephane Eranian <eranian@google.com> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-1ukistmpamc5z717k80ctcp2@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/python')
-rwxr-xr-xtools/perf/python/twatch.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/tools/perf/python/twatch.py b/tools/perf/python/twatch.py
index b9d508336ae6..c235c22b107a 100755
--- a/tools/perf/python/twatch.py
+++ b/tools/perf/python/twatch.py
@@ -15,14 +15,14 @@
15 15
16import perf 16import perf
17 17
18def main(): 18def main(context_switch = 0, thread = -1):
19 cpus = perf.cpu_map() 19 cpus = perf.cpu_map()
20 threads = perf.thread_map() 20 threads = perf.thread_map(thread)
21 evsel = perf.evsel(type = perf.TYPE_SOFTWARE, 21 evsel = perf.evsel(type = perf.TYPE_SOFTWARE,
22 config = perf.COUNT_SW_DUMMY, 22 config = perf.COUNT_SW_DUMMY,
23 task = 1, comm = 1, mmap = 0, freq = 0, 23 task = 1, comm = 1, mmap = 0, freq = 0,
24 wakeup_events = 1, watermark = 1, 24 wakeup_events = 1, watermark = 1,
25 sample_id_all = 1, 25 sample_id_all = 1, context_switch = context_switch,
26 sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU) 26 sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)
27 27
28 """What we want are just the PERF_RECORD_ lifetime events for threads, 28 """What we want are just the PERF_RECORD_ lifetime events for threads,
@@ -48,4 +48,21 @@ def main():
48 print event 48 print event
49 49
50if __name__ == '__main__': 50if __name__ == '__main__':
51 """
52 To test the PERF_RECORD_SWITCH record, pick a pid and replace
53 in the following line.
54
55 Example output:
56
57cpu: 3, pid: 31463, tid: 31593 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31593, switch_out: 1 }
58cpu: 1, pid: 31463, tid: 31489 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31489, switch_out: 1 }
59cpu: 2, pid: 31463, tid: 31496 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31496, switch_out: 1 }
60cpu: 3, pid: 31463, tid: 31491 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31491, switch_out: 0 }
61
62 It is possible as well to use event.misc & perf.PERF_RECORD_MISC_SWITCH_OUT
63 to figure out if this is a context switch in or out of the monitored threads.
64
65 If bored, please add command line option parsing support for these options :-)
66 """
67 # main(context_switch = 1, thread = 31463)
51 main() 68 main()