diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-01-29 12:44:29 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-01-30 08:37:38 -0500 |
commit | 877108e42b1b9ba64857c4030cf356ecc120fd18 (patch) | |
tree | ca41fa741081faa0f936b7296d721c84d1b89176 /tools/perf/python | |
parent | 8115d60c323dd9931b95221c0a392aeddc1d6ef3 (diff) |
perf tools: Initial python binding
First clarifying that this kind of binding is not a replacement or an
equivalent to the 'perf script' way of using python with perf.
The 'perf script' way is to process events and look at a given script
for some python function that matches the events to pass each event for
processing.
This is a python module, i.e. everything is driven from the python
script, that merely uses "import perf" or "from perf import".
perf script is focused on tracepoints, this binding is focused on profiling as
an initial target. More work is needed to make available tracepoint specific
variables as event variables accessible via this binding.
There is one example of such usage model, in
tools/perf/python/twatch.py, a tool to watch "cycles" events together
with task (fork, exit) and comm perf events.
For now, due to me not being able to grok how python distutils cope with
building C extensions outside the sources dir the install target just
builds it, I'm using it as:
[root@emilia linux]# export PYTHONPATH=~acme/git/build/perf/lib.linux-x86_64-2.6/
[root@emilia linux]# tools/perf/python/twatch.py
cpu: 4, pid: 30126, tid: 30126 { type: mmap, pid: 30126, tid: 30126, start: 0x4, length: 0x82e9ca03, offset: 0, filename: }
cpu: 6, pid: 47, tid: 47 { type: mmap, pid: 47, tid: 47, start: 0x6, length: 0xbef87c36, offset: 0, filename: }
cpu: 1, pid: 0, tid: 0 { type: mmap, pid: 0, tid: 0, start: 0x1, length: 0x775d1904, offset: 0, filename: }
cpu: 7, pid: 0, tid: 0 { type: mmap, pid: 0, tid: 0, start: 0x7, length: 0xc750aeb6, offset: 0, filename: }
cpu: 5, pid: 2255, tid: 2255 { type: mmap, pid: 2255, tid: 2255, start: 0x5, length: 0x76669635, offset: 0, filename: }
cpu: 0, pid: 0, tid: 0 { type: mmap, pid: 0, tid: 0, start: 0, length: 0x6422ef6b, offset: 0, filename: }
cpu: 2, pid: 2255, tid: 2255 { type: mmap, pid: 2255, tid: 2255, start: 0x2, length: 0xe078757a, offset: 0, filename: }
cpu: 1, pid: 5769, tid: 5769 { type: fork, pid: 30127, ppid: 5769, tid: 30127, ptid: 5769, time: 103893991270534}
cpu: 6, pid: 30127, tid: 30127 { type: comm, pid: 30127, tid: 30127, comm: ls }
cpu: 6, pid: 30127, tid: 30127 { type: exit, pid: 30127, ppid: 30127, tid: 30127, ptid: 30127, time: 103893993273024}
The first 8 mmap events in this 8 way machine are a mistery that is still being
investigated.
More of the tools/perf/util/ APIs will be exposed via this python binding as
the need arises. For now the focus is on creating events and processing them,
symbol resolution is an obvious next step, with tracepoint variables as a close
second step.
Cc: Clark Williams <williams@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/python')
-rwxr-xr-x | tools/perf/python/twatch.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/perf/python/twatch.py b/tools/perf/python/twatch.py new file mode 100755 index 000000000000..5e9f3b7b7ee8 --- /dev/null +++ b/tools/perf/python/twatch.py | |||
@@ -0,0 +1,41 @@ | |||
1 | #! /usr/bin/python | ||
2 | # -*- python -*- | ||
3 | # -*- coding: utf-8 -*- | ||
4 | # twatch - Experimental use of the perf python interface | ||
5 | # Copyright (C) 2011 Arnaldo Carvalho de Melo <acme@redhat.com> | ||
6 | # | ||
7 | # This application is free software; you can redistribute it and/or | ||
8 | # modify it under the terms of the GNU General Public License | ||
9 | # as published by the Free Software Foundation; version 2. | ||
10 | # | ||
11 | # This application is distributed in the hope that it will be useful, | ||
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | # General Public License for more details. | ||
15 | |||
16 | import perf | ||
17 | |||
18 | def main(): | ||
19 | cpus = perf.cpu_map() | ||
20 | threads = perf.thread_map() | ||
21 | evsel = perf.evsel(task = 1, comm = 1, mmap = 0, | ||
22 | wakeup_events = 1, sample_period = 1, | ||
23 | sample_id_all = 1, | ||
24 | sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU | perf.SAMPLE_TID) | ||
25 | evsel.open(cpus = cpus, threads = threads); | ||
26 | evlist = perf.evlist() | ||
27 | evlist.add(evsel) | ||
28 | evlist.mmap(cpus = cpus, threads = threads) | ||
29 | while True: | ||
30 | evlist.poll(timeout = -1) | ||
31 | for cpu in cpus: | ||
32 | event = evlist.read_on_cpu(cpu) | ||
33 | if not event: | ||
34 | continue | ||
35 | print "cpu: %2d, pid: %4d, tid: %4d" % (event.sample_cpu, | ||
36 | event.sample_pid, | ||
37 | event.sample_tid), | ||
38 | print event | ||
39 | |||
40 | if __name__ == '__main__': | ||
41 | main() | ||