Commits

Anonymous committed 0b87096

added support for cooked mode in vis.py

Comments (0)

Files changed (2)

-import sys
+import os, struct, sys
 import Image, ImageDraw, ImageFont
 
 from config import *
     ts = []
     for x in hist.timeline:
         ts.append((x.s0, x.t-t0))
+    total = ts[-1][1] - ts[0][1]
 
-    draw(ts, outfile)
+    draw(total, ts, outfile)
 
-def draw(ts, outfile):
+def run_cooked(filename, outfile):
+    f = open(filename)
+    f.seek(-8, os.SEEK_END)
+    dt = f.read(8)
+    dt = struct.unpack_from('Q', dt)[0]
+    print 'dt = ', dt
+    
+    f.seek(0)
+    ts = []
+    while True:
+        s = f.read(9)
+        if len(s) < 9: break
+        t, s = struct.unpack_from('QB', s)
+        ts.append((s, t))
+
+    draw(dt, ts, outfile)
+
+def draw(total, ts, outfile):
     W, H, HA, HB = 1600, 256, 64, 64
     HZ = H + 4 + HA + 4 + HB
     im = Image.new('RGBA', (W, HZ + 20))
 
     pp = 1.0 * total / (W*H)
     pc_us = 1.0 * total / CPU_SPEED / W * 1e6
-    print "Parsed %d items, t=%f, t/pixel=%f, t0=%d"%(len(ts), total/CPU_SPEED, pp/CPU_SPEED*1000, hist.timeline[0].t)
+    print "Parsed %d items, t=%f, t/pixel=%f"%(len(ts), total/CPU_SPEED, pp/CPU_SPEED*1000)
 
     d.rectangle((0, H + 4, W, H + 4 + HA), (255, 255, 255))
 
 
   Record                  to_interp;
   std::vector<ReasonCounter>   reason_summary;
+  uint64                  t0;
+  uint64                  t1;
 
   History() : to_interp(0, 0, 0) {
     for (int i = 0; i < S_COUNT; ++i) {
   }
 
   void transition(const Record& rec0, const Record& rec1) {
+    t1 = rec1.t;
     uint64 dt = rec1.t - rec0.t;
     state_summary[rec0.s] += dt;
 
     if (print_history) {
-      fwrite(&rec1.t, 1, sizeof(rec1.t), stdout);
-      putc(rec1.r, stdout);
       putc(rec0.s, stdout);
-      putc(rec1.s, stdout);
+      uint64 t = rec1.t - t0;
+      fwrite(&t, 1, sizeof(rec1.t), stdout);
     }
 
     // Transition to interpreter
   }
 
   void enter(const Record& rec) {
-    if (stack.size() == 0)
+    if (stack.size() == 0) {
+      t0 = rec.t;
       stack.push_back(Record(rec.t, 0, 0));
+    }
     transition(stack.back(), rec);
     stack.push_back(rec);
   }
       process_record(h, recs[i]);
     }
   }
+  if (print_history) {
+    uint64 dt = h.t1 - h.t0;
+    fwrite(&dt, 1, sizeof(dt), stdout);
+    fprintf(stderr, "dt = %llu %12.3f\n", dt, dt/CPU_SPEED);
+  }
   if (print_summary) {
     h.list_state_summary();
     printf("\n");