import sys import os import string def get_times(dirname): f = file(dirname + "/proc_ps.log") p_rc_sysinit = 0 p_X = 0 p_network = 0 in_network = False line = f.readline().strip() while line: timestamp = int(line) line = f.readline().strip() seen_network = False while line: if not line.strip(): break if not p_rc_sysinit and line.find("(rc.sysinit)") >= 0: p_rc_sysinit = timestamp if line.find("S10network") >= 0: seen_network = True if not p_X and line.find("(Xorg)") >= 0: p_X = timestamp f.close() return (p_rc_sysinit, p_X, p_network) line = f.readline().strip() if in_network and not seen_network: p_network = timestamp - p_network in_network = False if not p_network and seen_network: p_network = timestamp in_network = True line = f.readline().strip() f.close() return (p_rc_sysinit, p_X, p_network) def get_cpu(dirname): f = file(dirname + "/header") lines = f.readlines() f.close() for line in lines: if line.find("system.cpu") >= 0: args = line.strip().split() return string.join(args[5:]) return "unknown" def get_maxdisk(dirname, maxtime): f = file(dirname + "/proc_diskstats.log") lines = f.readlines() f.close() new_entry = True diskio = {} lastdiskio = {} timestamp = 0 last_timestamp = 0 for line in lines: line = line.strip() if not line: new_entry = True continue if new_entry: last_timestamp = timestamp timestamp = int(line) new_entry = False if timestamp > maxtime: break continue args = line.split() name = args[2] io = int(float(int(args[5]) - lastdiskio.get(name, 1000000000)) / float(timestamp - last_timestamp) * 100.0 / 2.0) lastdiskio[name] = int(args[5]) #if name[:2] == "sd" and len(name) == 3: if io > diskio.get(name, 0): diskio[args[2]] = io maxname = "" maxio = 0 for name, io in diskio.items(): if io > maxio: maxio = io maxname = name return (maxname, maxio) if __name__ == '__main__': argv = sys.argv[1:] if not len(argv): sys.exit(0) print_html = False if "--html" == argv[0]: argv = argv[1:] print_html = True times = [] for fname in argv: os.system("rm -fr /tmp/bootchart") os.mkdir("/tmp/bootchart") os.system("tar -xz -C /tmp/bootchart -f %s 2>/dev/null" % fname) (a, b, net) = get_times("/tmp/bootchart") if a and b: (maxname, maxio) = get_maxdisk("/tmp/bootchart", b) times.append( [ (b - a - net)/100, net/100, maxio, maxname, get_cpu("/tmp/bootchart"), fname ] ) os.system("rm -fr /tmp/bootchart") times.sort() if print_html: print '' for values in times: if print_html: out = "" else: out = "" for val in values: if print_html: if str(val).startswith("Bootchart-"): out += '' % (val[:-3], val) else: out += "" else: out += str(val) + "," if print_html: out += "" print out if print_html: print "
Time from rc.sysinit to XorgTime for S10networkMaxioMaxio DeviceCPUFilename
%s" + str(val) + "

"