mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-26 20:44:32 +08:00
7e2ed09753
So that we don't have to pass it around to the several methods that needs it, simplifying usage. There is one case where we don't have the thread/cpu map in advance, which is in the parsing routines used by top, stat, record, that we have to wait till all options are parsed to know if a cpu or thread list was passed to then create those maps. For that case consolidate the cpu and thread map creation via perf_evlist__create_maps() out of the code in top and record, while also providing a perf_evlist__set_maps() for cases where multiple evlists share maps or for when maps that represent CPU sockets, for instance, get crafted out of topology information or subsets of threads in a particular application are to be monitored, providing more granularity in specifying which cpus and threads to monitor. 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>
42 lines
1.3 KiB
Python
Executable File
42 lines
1.3 KiB
Python
Executable File
#! /usr/bin/python
|
|
# -*- python -*-
|
|
# -*- coding: utf-8 -*-
|
|
# twatch - Experimental use of the perf python interface
|
|
# Copyright (C) 2011 Arnaldo Carvalho de Melo <acme@redhat.com>
|
|
#
|
|
# 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():
|
|
cpus = perf.cpu_map()
|
|
threads = perf.thread_map()
|
|
evsel = perf.evsel(task = 1, comm = 1, mmap = 0,
|
|
wakeup_events = 1, sample_period = 1,
|
|
sample_id_all = 1,
|
|
sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU | perf.SAMPLE_TID)
|
|
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__':
|
|
main()
|