+ sys.stdout.write("%6lums %s\n" % ((aet - ixt) / 1000, name))
+
+elif sys.argv[1] == 'plot':
+ import cairo
+
+ start_time, finish_time = acquire_start_time()
+ data = acquire_time_data()
+ s = sorted(data, key = lambda i: i[1])
+
+ # 1000px = 10s, 1px = 10ms
+ border = 100
+ width = (finish_time - start_time)/10000 + border*2
+ height = 3000
+
+ bar_height = 20
+ bar_space = bar_height * 0.1
+
+ surface = cairo.SVGSurface(sys.stdout, width, height)
+ context = cairo.Context(surface)
+
+ draw_box(context, 0, 0, width, height, 1, 1, 1)
+
+ context.translate(border + 0.5, border + 0.5)
+
+ context.save()
+ 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):
+ context.move_to(x, 0)
+ context.line_to(x, height-border*2)
+
+ context.move_to(0, 0)
+ context.line_to(width-border*2, 0)
+
+ context.move_to(0, height-border*2)
+ context.line_to(width-border*2, height-border*2)
+
+ context.stroke()
+ context.restore()
+
+ for x in range(0, (finish_time - start_time)/10000, 100):
+ draw_text(context, x, -5, "%lus" % (x/100), center = False)
+
+ y = 0
+
+ for name, ixt, aet, axt, iet in s:
+
+ drawn = False
+ left = -1
+
+ if ixt >= start_time and aet > ixt:
+
+ # Activating
+ a = ixt - start_time
+ b = aet - ixt
+ draw_box(context, a/10000, y, b/10000, bar_height, 1, 0, 0)
+ drawn = True
+
+ if left < 0:
+ left = a
+
+ if aet >= start_time and axt > aet:
+
+ # Active
+ a = aet - start_time
+ b = axt - aet
+ draw_box(context, a/10000, y, b/10000, bar_height, .7, .5, .5)
+ drawn = True
+
+ if left < 0:
+ left = a
+
+ if axt >= start_time and iet > axt:
+
+ # Deactivating
+ a = axt - start_time
+ b = iet - axt
+ draw_box(context, a/10000, y, b/10000, bar_height, .6, .4, .4)
+ drawn = True
+
+ if left < 0:
+ left = a
+
+ if drawn:
+ draw_text(context, left/10000 + 10, y + bar_height/2, name)
+
+ y += bar_height + bar_space
+
+ surface.finish()
+