#! /usr/bin/python1# -*- python -*-2# -*- coding: utf-8 -*-3# twatch - Experimental use of the perf python interface4# Copyright (C) 2011 Arnaldo Carvalho de Melo <[email protected]>5#6# This application is free software; you can redistribute it and/or7# modify it under the terms of the GNU General Public License8# as published by the Free Software Foundation; version 2.9#10# This application is distributed in the hope that it will be useful,11# but WITHOUT ANY WARRANTY; without even the implied warranty of12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13# General Public License for more details.1415import perf1617def main():18cpus = perf.cpu_map()19threads = perf.thread_map()20evsel = perf.evsel(task = 1, comm = 1, mmap = 0,21wakeup_events = 1, sample_period = 1,22sample_id_all = 1,23sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU | perf.SAMPLE_TID)24evsel.open(cpus = cpus, threads = threads);25evlist = perf.evlist(cpus, threads)26evlist.add(evsel)27evlist.mmap()28while True:29evlist.poll(timeout = -1)30for cpu in cpus:31event = evlist.read_on_cpu(cpu)32if not event:33continue34print "cpu: %2d, pid: %4d, tid: %4d" % (event.sample_cpu,35event.sample_pid,36event.sample_tid),37print event3839if __name__ == '__main__':40main()414243