#! /usr/bin/python # -*- python -*- # -*- coding: utf-8 -*- # twatch - Experimental use of the perf python interface # Copyright (C) 2011 Arnaldo Carvalho de Melo # # This application is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; version 2. # # This application is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. import perf def main(context_switch = 0, thread = -1): cpus = perf.cpu_map() threads = perf.thread_map(thread) evsel = perf.evsel(type = perf.TYPE_SOFTWARE, config = perf.COUNT_SW_DUMMY, task = 1, comm = 1, mmap = 0, freq = 0, wakeup_events = 1, watermark = 1, sample_id_all = 1, context_switch = context_switch, sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU) """What we want are just the PERF_RECORD_ lifetime events for threads, using the default, PERF_TYPE_HARDWARE + PERF_COUNT_HW_CYCLES & freq=1 (the default), makes perf reenable irq_vectors:local_timer_entry, when disabling nohz, not good for some use cases where all we want is to get threads comes and goes... So use (perf.TYPE_SOFTWARE, perf_COUNT_SW_DUMMY, freq=0) instead.""" evsel.open(cpus = cpus, threads = threads); evlist = perf.evlist(cpus, threads) evlist.add(evsel) evlist.mmap() while True: evlist.poll(timeout = -1) for cpu in cpus: event = evlist.read_on_cpu(cpu) if not event: continue print "cpu: %2d, pid: %4d, tid: %4d" % (event.sample_cpu, event.sample_pid, event.sample_tid), print event if __name__ == '__main__': """ To test the PERF_RECORD_SWITCH record, pick a pid and replace in the following line. Example output: cpu: 3, pid: 31463, tid: 31593 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31593, switch_out: 1 } cpu: 1, pid: 31463, tid: 31489 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31489, switch_out: 1 } 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: 31491 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31491, switch_out: 0 } It is possible as well to use event.misc & perf.PERF_RECORD_MISC_SWITCH_OUT to figure out if this is a context switch in or out of the monitored threads. If bored, please add command line option parsing support for these options :-) """ # main(context_switch = 1, thread = 31463) main() put type='submit' value='search'/>
path: root/tools/perf/util
ModeNameSize
-rw-r--r--Build5870logplain
-rwxr-xr-xPERF-VERSION-GEN1010logplain
-rw-r--r--alias.c1471logplain
-rw-r--r--annotate.c44411logplain
-rw-r--r--annotate.h5583logplain
-rw-r--r--auxtrace.c47774logplain
-rw-r--r--auxtrace.h22142logplain
-rw-r--r--block-range.c6948logplain
-rw-r--r--block-range.h1607logplain
-rw-r--r--bpf-loader.c40787logplain
-rw-r--r--bpf-loader.h6215logplain
-rw-r--r--bpf-prologue.c11226logplain
-rw-r--r--bpf-prologue.h847logplain
-rw-r--r--build-id.c19054logplain
-rw-r--r--build-id.h1859logplain
d---------c++184logplain
-rw-r--r--cache.h733logplain
-rw-r--r--call-path.c2893logplain
-rw-r--r--call-path.h2203logplain
-rw-r--r--callchain.c29332logplain
-rw-r--r--callchain.h7881logplain
-rw-r--r--cgroup.c3195logplain
-rw-r--r--cgroup.h359logplain
-rw-r--r--cloexec.c1950logplain
-rw-r--r--cloexec.h251logplain
-rw-r--r--color.c4787logplain
-rw-r--r--color.h1647logplain
-rw-r--r--comm.c2239logplain
-rw-r--r--comm.h561logplain
-rw-r--r--config.c16262logplain
-rw-r--r--config.h2113logplain
-rw-r--r--counts.c1026logplain
-rw-r--r--counts.h790logplain
-rw-r--r--cpumap.c12627logplain
-rw-r--r--cpumap.h1954logplain
-rw-r--r--cs-etm.h2061logplain
-rw-r--r--ctype.c2018logplain
-rw-r--r--data-convert-bt.c36671logplain
-rw-r--r--data-convert-bt.h302logplain
-rw-r--r--data-convert.h141logplain
-rw-r--r--data.c3459logplain
-rw-r--r--data.h1369logplain
-rw-r--r--db-export.c11434logplain
-rw-r--r--db-export.h3816logplain
-rw-r--r--debug.c4417logplain
-rw-r--r--debug.h2023logplain
-rw-r--r--demangle-java.c4219logplain
-rw-r--r--demangle-java.h249logplain
-rw-r--r--demangle-rust.c6602logplain
-rw-r--r--demangle-rust.h170logplain
-rw-r--r--drv_configs.c1834logplain
-rw-r--r--drv_configs.h844logplain
-rw-r--r--dso.c31994logplain
-rw-r--r--dso.h10399logplain
-rw-r--r--dwarf-aux.c33828logplain
-rw-r--r--dwarf-aux.h5101logplain
-rw-r--r--dwarf-regs.c1816logplain
-rw-r--r--env.c1884logplain
-rw-r--r--env.h1268logplain
-rw-r--r--event.c36670logplain
-rw-r--r--event.h15997logplain
-rw-r--r--evlist.c47104logplain
-rw-r--r--evlist.h12584logplain
-rw-r--r--evsel.c63917logplain
-rw-r--r--evsel.h13041logplain
-rw-r--r--evsel_fprintf.c5831logplain
-rw-r--r--find-vdso-map.c581logplain
-rw-r--r--genelf.c11653logplain
-rw-r--r--genelf.h1814logplain
-rw-r--r--genelf_debug.c14374logplain
-rwxr-xr-xgenerate-cmdlist.sh1141logplain
-rw-r--r--group.h122logplain
-rw-r--r--header.c73410logplain
-rw-r--r--header.h4365logplain
-rw-r--r--help-unknown-cmd.c3221logplain