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

TOMOYO Linux Cross Reference
Linux/scripts/show_delta

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 /scripts/show_delta (Version linux-6.12-rc7) and /scripts/show_delta (Version linux-2.4.37.11)


  1 #!/usr/bin/env python                             
  2 # SPDX-License-Identifier: GPL-2.0-only           
  3 #                                                 
  4 # show_deltas: Read list of printk messages in    
  5 # time data, and format with time deltas.         
  6 #                                                 
  7 # Also, you can show the times relative to a f    
  8 #                                                 
  9 # Copyright 2003 Sony Corporation                 
 10 #                                                 
 11                                                   
 12 import sys                                        
 13 import string                                     
 14                                                   
 15 def usage():                                      
 16         print ("""usage: show_delta [<options>    
 17                                                   
 18 This program parses the output from a set of p    
 19 have time data prefixed because the CONFIG_PRI    
 20 the kernel command line option "time" is speci    
 21 options, the time information is converted to     
 22 each printk line and the next.  When run with     
 23 are relative to a single (base) point in time.    
 24                                                   
 25 Options:                                          
 26   -h            Show this usage help.             
 27   -b <base>     Specify a base for time refere    
 28                 <base> can be a number or a st    
 29                 If it is a string, the first m    
 30                 which matches (at the beginnin    
 31                 line) is used as the time refe    
 32                                                   
 33 ex: $ dmesg >timefile                             
 34     $ show_delta -b NET4 timefile                 
 35                                                   
 36 will show times relative to the line in the ke    
 37 starting with "NET4".                             
 38 """)                                              
 39         sys.exit(1)                               
 40                                                   
 41 # returns a tuple containing the seconds and t    
 42 # seconds is returned as a float                  
 43 # raise an exception if no timing data was fou    
 44 def get_time(line):                               
 45         if line[0]!="[":                          
 46                 raise ValueError                  
 47                                                   
 48         # split on closing bracket                
 49         (time_str, rest) = string.split(line[1    
 50         time = string.atof(time_str)              
 51                                                   
 52         #print "time=", time                      
 53         return (time, rest)                       
 54                                                   
 55                                                   
 56 # average line looks like:                        
 57 # [    0.084282] VFS: Mounted root (romfs file    
 58 # time data is expressed in seconds.useconds,     
 59 # convert_line adds a delta for each line         
 60 last_time = 0.0                                   
 61 def convert_line(line, base_time):                
 62         global last_time                          
 63                                                   
 64         try:                                      
 65                 (time, rest) = get_time(line)     
 66         except:                                   
 67                 # if any problem parsing time,    
 68                 return line                       
 69                                                   
 70         if base_time:                             
 71                 # show time from base             
 72                 delta = time - base_time          
 73         else:                                     
 74                 # just show time from last lin    
 75                 delta = time - last_time          
 76                 last_time = time                  
 77                                                   
 78         return ("[%5.6f < %5.6f >]" % (time, d    
 79                                                   
 80 def main():                                       
 81         base_str = ""                             
 82         filein = ""                               
 83         for arg in sys.argv[1:]:                  
 84                 if arg=="-b":                     
 85                         base_str = sys.argv[sy    
 86                 elif arg=="-h":                   
 87                         usage()                   
 88                 else:                             
 89                         filein = arg              
 90                                                   
 91         if not filein:                            
 92                 usage()                           
 93                                                   
 94         try:                                      
 95                 lines = open(filein,"r").readl    
 96         except:                                   
 97                 print ("Problem opening file:     
 98                 sys.exit(1)                       
 99                                                   
100         if base_str:                              
101                 print ('base= "%s"' % base_str    
102                 # assume a numeric base.  If t    
103                 # for a matching line.            
104                 try:                              
105                         base_time = float(base    
106                 except:                           
107                         # search for line matc    
108                         found = 0                 
109                         for line in lines:        
110                                 try:              
111                                         (time,    
112                                 except:           
113                                         contin    
114                                 if string.find    
115                                         base_t    
116                                         found     
117                                         # stop    
118                                         break     
119                         if not found:             
120                                 print ('Couldn    
121                                 sys.exit(1)       
122         else:                                     
123                 base_time = 0.0                   
124                                                   
125         for line in lines:                        
126                 print (convert_line(line, base    
127                                                   
128 if __name__ == "__main__":                        
129         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