3 # -*- coding: utf-8 -*-
4 # twatch - Experimental use of the perf python interface
5 # Copyright (C) 2011 Arnaldo Carvalho de Melo <acme@redhat.com>
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.
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.
20 threads = perf.thread_map()
21 evsel = perf.evsel(type = perf.TYPE_SOFTWARE,
22 config = perf.COUNT_SW_DUMMY,
23 task = 1, comm = 1, mmap = 0, freq = 0,
24 wakeup_events = 1, watermark = 1,
26 sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)
28 """What we want are just the PERF_RECORD_ lifetime events for threads,
29 using the default, PERF_TYPE_HARDWARE + PERF_COUNT_HW_CYCLES & freq=1
30 (the default), makes perf reenable irq_vectors:local_timer_entry, when
31 disabling nohz, not good for some use cases where all we want is to get
32 threads comes and goes... So use (perf.TYPE_SOFTWARE, perf_COUNT_SW_DUMMY,
35 evsel.open(cpus = cpus, threads = threads);
36 evlist = perf.evlist(cpus, threads)
40 evlist.poll(timeout = -1)
42 event = evlist.read_on_cpu(cpu)
45 print "cpu: %2d, pid: %4d, tid: %4d" % (event.sample_cpu,
50 if __name__ == '__main__':