URL
https://opencores.org/ocsvn/test_project/test_project/trunk
Subversion Repositories test_project
[/] [test_project/] [trunk/] [linux_sd_driver/] [scripts/] [show_delta] - Rev 62
Compare with Previous | Blame | View Log
#!/usr/bin/env python## show_deltas: Read list of printk messages instrumented with# time data, and format with time deltas.## Also, you can show the times relative to a fixed point.## Copyright 2003 Sony Corporation## GPL 2.0 applies.import sysimport stringdef usage():print """usage: show_delta [<options>] <filename>This program parses the output from a set of printk message lines whichhave time data prefixed because the CONFIG_PRINTK_TIME option is set, orthe kernel command line option "time" is specified. When run with nooptions, the time information is converted to show the time delta betweeneach printk line and the next. When run with the '-b' option, all timesare 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 linewhich matches (at the beginning of theline) is used as the time reference.ex: $ dmesg >timefile$ show_delta -b NET4 timefilewill show times relative to the line in the kernel outputstarting with "NET4"."""sys.exit(1)# returns a tuple containing the seconds and text for each message line# seconds is returned as a float# raise an exception if no timing data was founddef get_time(line):if line[0]!="[":raise ValueError# split on closing bracket(time_str, rest) = string.split(line[1:],']',1)time = string.atof(time_str)#print "time=", timereturn (time, rest)# average line looks like:# [ 0.084282] VFS: Mounted root (romfs filesystem) readonly# time data is expressed in seconds.useconds,# convert_line adds a delta for each linelast_time = 0.0def convert_line(line, base_time):global last_timetry:(time, rest) = get_time(line)except:# if any problem parsing time, don't convert anythingreturn lineif base_time:# show time from basedelta = time - base_timeelse:# just show time from last linedelta = time - last_timelast_time = timereturn ("[%5.6f < %5.6f >]" % (time, delta)) + restdef 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 = argif not filein:usage()try:lines = open(filein,"r").readlines()except:print "Problem opening file: %s" % fileinsys.exit(1)if base_str:print 'base= "%s"' % base_str# assume a numeric base. If that fails, try searching# for a matching line.try:base_time = float(base_str)except:# search for line matching <base> stringfound = 0for line in lines:try:(time, rest) = get_time(line)except:continueif string.find(rest, base_str)==1:base_time = timefound = 1# stop at first matchbreakif not found:print 'Couldn\'t find line matching base pattern "%s"' % base_strsys.exit(1)else:base_time = 0.0for line in lines:print convert_line(line, base_time),main()
