X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsystemd-analyze;h=729aa05ca10a806a0944c8fd294ae9759ca55d19;hp=5e3a087e9d27a1b6b936818f0083d085c4e79ea7;hb=01448ff92d9549785242ffab453bf5bcde348c61;hpb=fe8954ab47b57703d2fb3116f5dbe389426e99bc diff --git a/src/systemd-analyze b/src/systemd-analyze index 5e3a087e9..729aa05ca 100755 --- a/src/systemd-analyze +++ b/src/systemd-analyze @@ -15,10 +15,10 @@ def acquire_time_data(): properties = dbus.Interface(bus.get_object('org.freedesktop.systemd1', i[6]), 'org.freedesktop.DBus.Properties') - ixt = int(properties.Get('org.freedesktop.systemd1.Unit', 'InactiveExitTimestamp')) - aet = int(properties.Get('org.freedesktop.systemd1.Unit', 'ActiveEnterTimestamp')) - axt = int(properties.Get('org.freedesktop.systemd1.Unit', 'ActiveExitTimestamp')) - iet = int(properties.Get('org.freedesktop.systemd1.Unit', 'InactiveEnterTimestamp')) + ixt = int(properties.Get('org.freedesktop.systemd1.Unit', 'InactiveExitTimestampMonotonic')) + aet = int(properties.Get('org.freedesktop.systemd1.Unit', 'ActiveEnterTimestampMonotonic')) + axt = int(properties.Get('org.freedesktop.systemd1.Unit', 'ActiveExitTimestampMonotonic')) + iet = int(properties.Get('org.freedesktop.systemd1.Unit', 'InactiveEnterTimestampMonotonic')) l.append((str(i[0]), ixt, aet, axt, iet)) @@ -27,12 +27,14 @@ def acquire_time_data(): def acquire_start_time(): properties = dbus.Interface(bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1'), 'org.freedesktop.DBus.Properties') - startup_time = int(properties.Get('org.freedesktop.systemd1.Manager', 'StartupTimestamp')) - finish_time = int(properties.Get('org.freedesktop.systemd1.Manager', 'FinishTimestamp')) + initrd_time = int(properties.Get('org.freedesktop.systemd1.Manager', 'InitRDTimestampMonotonic')) + startup_time = int(properties.Get('org.freedesktop.systemd1.Manager', 'StartupTimestampMonotonic')) + finish_time = int(properties.Get('org.freedesktop.systemd1.Manager', 'FinishTimestampMonotonic')) + assert initrd_time <= startup_time assert startup_time <= finish_time - return startup_time, finish_time + return initrd_time, startup_time, finish_time def draw_box(context, j, k, l, m, r = 0, g = 0, b = 0): context.save() @@ -63,7 +65,8 @@ def draw_text(context, x, y, text, size = 12, r = 0, g = 0, b = 0, vcenter = 0.5 context.restore() def help(): - sys.stdout.write("""systemd-analyze blame + sys.stdout.write("""systemd-analyze time +systemd-analyze blame systemd-analyze plot Process systemd profiling information @@ -74,7 +77,24 @@ Process systemd profiling information bus = dbus.SystemBus() -if len(sys.argv) <= 1 or sys.argv[1] == 'blame': +if len(sys.argv) <= 1 or sys.argv[1] == 'time': + + initrd_time, start_time, finish_time = acquire_start_time() + + if initrd_time > 0: + print "Startup finished in %lums (kernel) + %lums (initramfs) + %lums (userspace) = %lums" % ( \ + initrd_time/1000, \ + (start_time - initrd_time)/1000, \ + (finish_time - start_time)/1000, \ + finish_time/1000) + else: + print "Startup finished in %lums (kernel) + %lums (userspace) = %lums" % ( \ + start_time/1000, \ + (finish_time - start_time)/1000, \ + finish_time/1000) + + +elif sys.argv[1] == 'blame': data = acquire_time_data() s = sorted(data, key = lambda i: i[2] - i[1], reverse = True) @@ -90,13 +110,17 @@ if len(sys.argv) <= 1 or sys.argv[1] == 'blame': sys.stdout.write("%6lums %s\n" % ((aet - ixt) / 1000, name)) elif sys.argv[1] == 'plot': - import cairo + import cairo, os - start_time, finish_time = acquire_start_time() + initrd_time, start_time, finish_time = acquire_start_time() data = acquire_time_data() s = sorted(data, key = lambda i: i[1]) - count = 0 + # Account for kernel and initramfs bars if they exist + if initrd_time > 0: + count = 3 + else: + count = 2 for name, ixt, aet, axt, iet in s: @@ -110,7 +134,7 @@ elif sys.argv[1] == 'plot': bar_space = bar_height * 0.1 # 1000px = 10s, 1px = 10ms - width = (finish_time - start_time)/10000 + border*2 + width = finish_time/10000 + border*2 height = count * (bar_height + bar_space) + border * 2 if width < 1000: @@ -127,7 +151,7 @@ elif sys.argv[1] == 'plot': context.set_line_width(1) context.set_source_rgb(0.7, 0.7, 0.7) - for x in range(0, (finish_time - start_time)/10000, 100): + for x in range(0, finish_time/10000 + 100, 100): context.move_to(x, 0) context.line_to(x, height-border*2) @@ -140,11 +164,33 @@ elif sys.argv[1] == 'plot': context.stroke() context.restore() - for x in range(0, (finish_time - start_time)/10000, 100): + banner = "Running on %s (%s %s) %s" % (os.uname()[1], os.uname()[2], os.uname()[3], os.uname()[4]) + draw_text(context, 0, -15, banner, hcenter = 0, vcenter = 1) + + for x in range(0, finish_time/10000 + 100, 100): draw_text(context, x, -5, "%lus" % (x/100), vcenter = 0, hcenter = 0) y = 0 + # draw boxes for kernel and initramfs boot time + if initrd_time > 0: + draw_box(context, 0, y, initrd_time/10000, bar_height, 0.7, 0.7, 0.7) + draw_text(context, 10, y + bar_height/2, "kernel", hcenter = 0) + y += bar_height + bar_space + + draw_box(context, initrd_time/10000, y, start_time/10000-initrd_time/10000, bar_height, 0.7, 0.7, 0.7) + draw_text(context, initrd_time/10000 + 10, y + bar_height/2, "initramfs", hcenter = 0) + y += bar_height + bar_space + + else: + draw_box(context, 0, y, start_time/10000, bar_height, 0.6, 0.6, 0.6) + draw_text(context, 10, y + bar_height/2, "kernel", hcenter = 0) + y += bar_height + bar_space + + draw_box(context, start_time/10000, y, finish_time/10000-start_time/10000, bar_height, 0.7, 0.7, 0.7) + draw_text(context, start_time/10000 + 10, y + bar_height/2, "userspace", hcenter = 0) + y += bar_height + bar_space + for name, ixt, aet, axt, iet in s: drawn = False @@ -153,7 +199,7 @@ elif sys.argv[1] == 'plot': if ixt >= start_time and ixt <= finish_time: # Activating - a = ixt - start_time + a = ixt b = min(filter(lambda x: x >= ixt, (aet, axt, iet, finish_time))) - ixt draw_box(context, a/10000, y, b/10000, bar_height, 1, 0, 0) @@ -165,7 +211,7 @@ elif sys.argv[1] == 'plot': if aet >= start_time and aet <= finish_time: # Active - a = aet - start_time + a = aet b = min(filter(lambda x: x >= aet, (axt, iet, finish_time))) - aet draw_box(context, a/10000, y, b/10000, bar_height, .8, .6, .6) @@ -177,7 +223,7 @@ elif sys.argv[1] == 'plot': if axt >= start_time and axt <= finish_time: # Deactivating - a = axt - start_time + a = axt b = min(filter(lambda x: x >= axt, (iet, finish_time))) - axt draw_box(context, a/10000, y, b/10000, bar_height, .6, .4, .4) @@ -198,6 +244,18 @@ elif sys.argv[1] == 'plot': draw_text(context, 0, height-border*2, "Legend: Red = Activating; Pink = Active; Dark Pink = Deactivating", hcenter = 0, vcenter = -1) + if initrd_time > 0: + draw_text(context, 0, height-border*2 + bar_height, "Startup finished in %lums (kernel) + %lums (initramfs) + %lums (userspace) = %lums" % ( \ + initrd_time/1000, \ + (start_time - initrd_time)/1000, \ + (finish_time - start_time)/1000, \ + finish_time/1000), hcenter = 0, vcenter = -1) + else: + draw_text(context, 0, height-border*2 + bar_height, "Startup finished in %lums (kernel) + %lums (userspace) = %lums" % ( \ + start_time/1000, \ + (finish_time - start_time)/1000, \ + finish_time/1000), hcenter = 0, vcenter = -1) + surface.finish() elif sys.argv[1] in ("help", "--help", "-h"): help()