Commits

Anonymous committed 444461b

add event support to vis.py

  • Participants
  • Parent commits 19d9016

Comments (0)

Files changed (2)

File scripts/acts.py

     'native',
 ]
 
+event_start = 8;
+
 # Must match C++ enum
 reasons = [
     'none',

File scripts/vis.py

 from config import *
 from acts import *
 from binlog import parse_input, collect
+from time import clock
 
 BLACK = (0, 0, 0)
+WHITE = (255, 255, 255)
 font = ImageFont.load_default()
 
 states = [
     state_count = struct.unpack_from('I', f.read(4))[0]
     for i in range(state_count):
         summary.append(struct.unpack_from('Q', f.read(8))[0])
-    
+
+    # This method is actually faster than reading it all into a buffer and decoding
+    # from there.
     transitions = []
+    t0 = clock()
     while True:
         raw = f.read(9)
         if len(raw) < 9: break
         s = struct.unpack_from('B', raw)[0]
         t = struct.unpack_from('Q', raw, 1)[0]
         transitions.append((s, t))
+    t1 = clock()
+
+    print 'read time: ', (t1-t0)
     
     return Data(duration, summary, transitions)
 
 
     eps = []
 
-    # estimated progress
+    # estimated progress of program run 
     ep = 0
 
+    # text progress indicator for graph generation
+    dot = W*H//80
+
+    # Flush events. We need to save them and draw them after filling the main area
+    # because otherwise they will be overwritten. Format is (x, y) to plot flush at.
+    events = []
+
     ti = 0
     for i in range(W*H):
+        if i % dot == 0:
+            sys.stdout.write('.')
+            sys.stdout.flush()
+        x, y = i/H, i%H
+
         t0 = pp * i
         t1 = t0 + pp
         color = [ 0, 0, 0 ]
         tx = t0
         while ti < len(ts):
-            q = (min(ts[ti][1], t1)-tx)/pp
-            c = states[ts[ti][0]]
+            state, time = ts[ti];
+            # States past this limit are actually events rather than state transitions
+            if state >= event_start:
+                events.append((x, y))
+                ti += 1
+                continue
+
+            q = (min(time, t1)-tx)/pp
+            c = states[state]
             color[0] += q * c[0]
             color[1] += q * c[1]
             color[2] += q * c[2]
-            ep += q * speedups[ts[ti][0]]
-            if ts[ti][1] > t1:
+            ep += q * speedups[state]
+            if time > t1:
                 break
-            tx = ts[ti][1]
+            tx = time
             ti += 1
         
         color[0] = int(color[0])
         color[1] = int(color[1])
         color[2] = int(color[2])
 
-        d.point((i/H, i%H), fill=tuple(color))
+        d.point((x, y), fill=tuple(color))
 
         if i % H == H - 1:
             eps.append(ep)
             ep = 0
 
+    for x, y in events:
+        d.ellipse((x-10, y-10, x+10, y+10), fill=(255, 222, 222), outline=(160, 10, 10))
+        d.text((x, y), 'F', fill=BLACK, font=font)
+
+    print
+
     epmax = 2.5*H
 
     d.line((0, H+4+HA-1.0*H/epmax*HA, W,  H+4+HA-1.0*H/epmax*HA), fill=(192, 192, 192))