123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import sys
- import string
- def usage():
- print ("""usage: show_delta [<options>] <filename>
- This program parses the output from a set of printk message lines which
- have time data prefixed because the CONFIG_PRINTK_TIME option is set, or
- the kernel command line option "time" is specified. When run with no
- options, the time information is converted to show the time delta between
- each printk line and the next. When run with the '-b' option, all times
- are relative to a single (base) point in time.
- Options:
- -h Show this usage help.
- -b <base> Specify a base for time references.
- <base> can be a number or a string.
- If it is a string, the first message line
- which matches (at the beginning of the
- line) is used as the time reference.
- ex: $ dmesg >timefile
- $ show_delta -b NET4 timefile
- will show times relative to the line in the kernel output
- starting with "NET4".
- """)
- sys.exit(1)
- def get_time(line):
- if line[0]!="[":
- raise ValueError
-
- (time_str, rest) = string.split(line[1:],']',1)
- time = string.atof(time_str)
-
- return (time, rest)
- last_time = 0.0
- def convert_line(line, base_time):
- global last_time
- try:
- (time, rest) = get_time(line)
- except:
-
- return line
- if base_time:
-
- delta = time - base_time
- else:
-
- delta = time - last_time
- last_time = time
- return ("[%5.6f < %5.6f >]" % (time, delta)) + rest
- def main():
- base_str = ""
- filein = ""
- for arg in sys.argv[1:]:
- if arg=="-b":
- base_str = sys.argv[sys.argv.index("-b")+1]
- elif arg=="-h":
- usage()
- else:
- filein = arg
- if not filein:
- usage()
- try:
- lines = open(filein,"r").readlines()
- except:
- print ("Problem opening file: %s" % filein)
- sys.exit(1)
- if base_str:
- print ('base= "%s"' % base_str)
-
-
- try:
- base_time = float(base_str)
- except:
-
- found = 0
- for line in lines:
- try:
- (time, rest) = get_time(line)
- except:
- continue
- if string.find(rest, base_str)==1:
- base_time = time
- found = 1
-
- break
- if not found:
- print ('Couldn\'t find line matching base pattern "%s"' % base_str)
- sys.exit(1)
- else:
- base_time = 0.0
- for line in lines:
- print (convert_line(line, base_time),)
- main()
|