~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/python/twatch.py

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/perf/python/twatch.py (Version linux-6.12-rc7) and /tools/perf/python/twatch.py (Version linux-4.16.18)


  1 #! /usr/bin/env python                         !!   1 #! /usr/bin/python
  2 # SPDX-License-Identifier: GPL-2.0-only        << 
  3 # -*- python -*-                                    2 # -*- python -*-
  4 # -*- coding: utf-8 -*-                             3 # -*- coding: utf-8 -*-
  5 #   twatch - Experimental use of the perf pyth      4 #   twatch - Experimental use of the perf python interface
  6 #   Copyright (C) 2011 Arnaldo Carvalho de Mel<      5 #   Copyright (C) 2011 Arnaldo Carvalho de Melo <acme@redhat.com>
  7 #                                                   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.
  8                                                    15 
  9 import perf                                        16 import perf
 10                                                    17 
 11 def main(context_switch = 0, thread = -1):         18 def main(context_switch = 0, thread = -1):
 12         cpus = perf.cpu_map()                      19         cpus = perf.cpu_map()
 13         threads = perf.thread_map(thread)          20         threads = perf.thread_map(thread)
 14         evsel = perf.evsel(type   = perf.TYPE_     21         evsel = perf.evsel(type   = perf.TYPE_SOFTWARE,
 15                            config = perf.COUNT     22                            config = perf.COUNT_SW_DUMMY,
 16                            task = 1, comm = 1,     23                            task = 1, comm = 1, mmap = 0, freq = 0,
 17                            wakeup_events = 1,      24                            wakeup_events = 1, watermark = 1,
 18                            sample_id_all = 1,      25                            sample_id_all = 1, context_switch = context_switch,
 19                            sample_type = perf.     26                            sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)
 20                                                    27 
 21         """What we want are just the PERF_RECO     28         """What we want are just the PERF_RECORD_ lifetime events for threads,
 22          using the default, PERF_TYPE_HARDWARE     29          using the default, PERF_TYPE_HARDWARE + PERF_COUNT_HW_CYCLES & freq=1
 23          (the default), makes perf reenable ir     30          (the default), makes perf reenable irq_vectors:local_timer_entry, when
 24          disabling nohz, not good for some use     31          disabling nohz, not good for some use cases where all we want is to get
 25          threads comes and goes... So use (per     32          threads comes and goes... So use (perf.TYPE_SOFTWARE, perf_COUNT_SW_DUMMY,
 26          freq=0) instead."""                       33          freq=0) instead."""
 27                                                    34 
 28         evsel.open(cpus = cpus, threads = thre     35         evsel.open(cpus = cpus, threads = threads);
 29         evlist = perf.evlist(cpus, threads)        36         evlist = perf.evlist(cpus, threads)
 30         evlist.add(evsel)                          37         evlist.add(evsel)
 31         evlist.mmap()                              38         evlist.mmap()
 32         while True:                                39         while True:
 33                 evlist.poll(timeout = -1)          40                 evlist.poll(timeout = -1)
 34                 for cpu in cpus:                   41                 for cpu in cpus:
 35                         event = evlist.read_on     42                         event = evlist.read_on_cpu(cpu)
 36                         if not event:              43                         if not event:
 37                                 continue           44                                 continue
 38                         print("cpu: {0}, pid:  !!  45                         print "cpu: %2d, pid: %4d, tid: %4d" % (event.sample_cpu,
 39                                                !!  46                                                                 event.sample_pid,
 40                                                !!  47                                                                 event.sample_tid),
 41                                                !!  48                         print event
 42                                                    49 
 43 if __name__ == '__main__':                         50 if __name__ == '__main__':
 44     """                                            51     """
 45         To test the PERF_RECORD_SWITCH record,     52         To test the PERF_RECORD_SWITCH record, pick a pid and replace
 46         in the following line.                     53         in the following line.
 47                                                    54 
 48         Example output:                            55         Example output:
 49                                                    56 
 50 cpu: 3, pid: 31463, tid: 31593 { type: context     57 cpu: 3, pid: 31463, tid: 31593 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31593, switch_out: 1 }
 51 cpu: 1, pid: 31463, tid: 31489 { type: context     58 cpu: 1, pid: 31463, tid: 31489 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31489, switch_out: 1 }
 52 cpu: 2, pid: 31463, tid: 31496 { type: context     59 cpu: 2, pid: 31463, tid: 31496 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31496, switch_out: 1 }
 53 cpu: 3, pid: 31463, tid: 31491 { type: context     60 cpu: 3, pid: 31463, tid: 31491 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31491, switch_out: 0 }
 54                                                    61 
 55         It is possible as well to use event.mi     62         It is possible as well to use event.misc & perf.PERF_RECORD_MISC_SWITCH_OUT
 56         to figure out if this is a context swi     63         to figure out if this is a context switch in or out of the monitored threads.
 57                                                    64 
 58         If bored, please add command line opti     65         If bored, please add command line option parsing support for these options :-)
 59     """                                            66     """
 60     # main(context_switch = 1, thread = 31463)     67     # main(context_switch = 1, thread = 31463)
 61     main()                                         68     main()
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php