blob: 2225162ee1fc169de376f04c62b6abb6df6611ea [file] [log] [blame]
Arnaldo Carvalho de Melo877108e2011-01-29 15:44:29 -02001#! /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
16import perf
17
18def main():
19 cpus = perf.cpu_map()
20 threads = perf.thread_map()
21 evsel = perf.evsel(task = 1, comm = 1, mmap = 0,
Arnaldo Carvalho de Melocfeb1d92012-01-30 14:43:21 -020022 wakeup_events = 1, watermark = 1,
Arnaldo Carvalho de Melo877108e2011-01-29 15:44:29 -020023 sample_id_all = 1,
Arnaldo Carvalho de Melo32235652013-08-01 17:00:45 -030024 sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)
Arnaldo Carvalho de Melo877108e2011-01-29 15:44:29 -020025 evsel.open(cpus = cpus, threads = threads);
Arnaldo Carvalho de Melo7e2ed092011-01-30 11:59:43 -020026 evlist = perf.evlist(cpus, threads)
Arnaldo Carvalho de Melo877108e2011-01-29 15:44:29 -020027 evlist.add(evsel)
Arnaldo Carvalho de Melo7e2ed092011-01-30 11:59:43 -020028 evlist.mmap()
Arnaldo Carvalho de Melo877108e2011-01-29 15:44:29 -020029 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
40if __name__ == '__main__':
41 main()