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


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