2 # SPDX-License-Identifier: GPL-2.0-only
4 # show_deltas: Read list of printk messages instrumented with
5 # time data, and format with time deltas.
7 # Also, you can show the times relative to a fixed point.
9 # Copyright 2003 Sony Corporation
16 print ("""usage: show_delta [<options>] <filename>
18 This program parses the output from a set of printk message lines which
19 have time data prefixed because the CONFIG_PRINTK_TIME option is set, or
20 the kernel command line option "time" is specified. When run with no
21 options, the time information is converted to show the time delta between
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.
26 -h Show this usage help.
27 -b <base> Specify a base for time references.
28 <base> can be a number or a string.
29 If it is a string, the first message line
30 which matches (at the beginning of the
31 line) is used as the time reference.
34 $ show_delta -b NET4 timefile
36 will show times relative to the line in the kernel output
41 # returns a tuple containing the seconds and text for each message line
42 # seconds is returned as a float
43 # raise an exception if no timing data was found
48 # split on closing bracket
49 (time_str
, rest
) = string
.split(line
[1:],']',1)
50 time
= string
.atof(time_str
)
56 # average line looks like:
57 # [ 0.084282] VFS: Mounted root (romfs filesystem) readonly
58 # time data is expressed in seconds.useconds,
59 # convert_line adds a delta for each line
61 def convert_line(line
, base_time
):
65 (time
, rest
) = get_time(line
)
67 # if any problem parsing time, don't convert anything
72 delta
= time
- base_time
74 # just show time from last line
75 delta
= time
- last_time
78 return ("[%5.6f < %5.6f >]" % (time
, delta
)) + rest
83 for arg
in sys
.argv
[1:]:
85 base_str
= sys
.argv
[sys
.argv
.index("-b")+1]
95 lines
= open(filein
,"r").readlines()
97 print ("Problem opening file: %s" % filein
)
101 print ('base= "%s"' % base_str
)
102 # assume a numeric base. If that fails, try searching
103 # for a matching line.
105 base_time
= float(base_str
)
107 # search for line matching <base> string
111 (time
, rest
) = get_time(line
)
114 if string
.find(rest
, base_str
)==1:
117 # stop at first match
120 print ('Couldn\'t find line matching base pattern "%s"' % base_str
)
126 print (convert_line(line
, base_time
),)