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

TOMOYO Linux Cross Reference
Linux/tools/perf/scripts/python/stackcollapse.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/scripts/python/stackcollapse.py (Version linux-6.12-rc7) and /tools/perf/scripts/python/stackcollapse.py (Version linux-3.10.108)


  1 # stackcollapse.py - format perf samples with     
  2 # SPDX-License-Identifier: GPL-2.0                
  3 #                                                 
  4 # This script's output has two space-separated    
  5 # separated stack including the program name (    
  6 # function names from the call stack.  The sec    
  7 #                                                 
  8 #  swapper;start_kernel;rest_init;cpu_idle;def    
  9 #                                                 
 10 # The file is sorted according to the first fi    
 11 #                                                 
 12 # Input may be created and processed using:       
 13 #                                                 
 14 #  perf record -a -g -F 99 sleep 60               
 15 #  perf script report stackcollapse > out.stac    
 16 #                                                 
 17 # (perf script record stackcollapse works too)    
 18 #                                                 
 19 # Written by Paolo Bonzini <pbonzini@redhat.com    
 20 # Based on Brendan Gregg's stackcollapse-perf.    
 21                                                   
 22 from __future__ import print_function             
 23                                                   
 24 import os                                         
 25 import sys                                        
 26 from collections import defaultdict               
 27 from optparse import OptionParser, make_option    
 28                                                   
 29 sys.path.append(os.environ['PERF_EXEC_PATH'] +    
 30     '/scripts/python/Perf-Trace-Util/lib/Perf/    
 31                                                   
 32 from perf_trace_context import *                  
 33 from Core import *                                
 34 from EventClass import *                          
 35                                                   
 36 # command line parsing                            
 37                                                   
 38 option_list = [                                   
 39     # formatting options for the bottom entry     
 40     make_option("--include-tid", dest="include    
 41                  action="store_true", default=    
 42                  help="include thread id in st    
 43     make_option("--include-pid", dest="include    
 44                  action="store_true", default=    
 45                  help="include process id in s    
 46     make_option("--no-comm", dest="include_com    
 47                  action="store_false", default    
 48                  help="do not separate stacks     
 49     make_option("--tidy-java", dest="tidy_java    
 50                  action="store_true", default=    
 51                  help="beautify Java signature    
 52     make_option("--kernel", dest="annotate_ker    
 53                  action="store_true", default=    
 54                  help="annotate kernel functio    
 55 ]                                                 
 56                                                   
 57 parser = OptionParser(option_list=option_list)    
 58 (opts, args) = parser.parse_args()                
 59                                                   
 60 if len(args) != 0:                                
 61     parser.error("unexpected command line argu    
 62 if opts.include_tid and not opts.include_comm:    
 63     parser.error("requesting tid but not comm     
 64 if opts.include_pid and not opts.include_comm:    
 65     parser.error("requesting pid but not comm     
 66                                                   
 67 # event handlers                                  
 68                                                   
 69 lines = defaultdict(lambda: 0)                    
 70                                                   
 71 def process_event(param_dict):                    
 72     def tidy_function_name(sym, dso):             
 73         if sym is None:                           
 74             sym = '[unknown]'                     
 75                                                   
 76         sym = sym.replace(';', ':')               
 77         if opts.tidy_java:                        
 78             # the original stackcollapse-perf.    
 79             # example of converting this:         
 80             #    Lorg/mozilla/javascript/Membe    
 81             # to this:                            
 82             #    org/mozilla/javascript/Member    
 83             sym = sym.replace('<', '')            
 84             sym = sym.replace('>', '')            
 85             if sym[0] == 'L' and sym.find('/')    
 86                 sym = sym[1:]                     
 87             try:                                  
 88                 sym = sym[:sym.index('(')]        
 89             except ValueError:                    
 90                 pass                              
 91                                                   
 92         if opts.annotate_kernel and dso == '[k    
 93             return sym + '_[k]'                   
 94         else:                                     
 95             return sym                            
 96                                                   
 97     stack = list()                                
 98     if 'callchain' in param_dict:                 
 99         for entry in param_dict['callchain']:     
100             entry.setdefault('sym', dict())       
101             entry['sym'].setdefault('name', No    
102             entry.setdefault('dso', None)         
103             stack.append(tidy_function_name(en    
104                                             en    
105     else:                                         
106         param_dict.setdefault('symbol', None)     
107         param_dict.setdefault('dso', None)        
108         stack.append(tidy_function_name(param_    
109                                         param_    
110                                                   
111     if opts.include_comm:                         
112         comm = param_dict["comm"].replace(' ',    
113         sep = "-"                                 
114         if opts.include_pid:                      
115             comm = comm + sep + str(param_dict    
116             sep = "/"                             
117         if opts.include_tid:                      
118             comm = comm + sep + str(param_dict    
119         stack.append(comm)                        
120                                                   
121     stack_string = ';'.join(reversed(stack))      
122     lines[stack_string] = lines[stack_string]     
123                                                   
124 def trace_end():                                  
125     list = sorted(lines)                          
126     for stack in list:                            
127         print("%s %d" % (stack, lines[stack]))    
                                                      

~ [ 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