Anonymous avatar Anonymous committed 19d9016

adding event support to binlog.cpp

Comments (0)

Files changed (1)

  *
  *       length            contents
  *
- *       12                literal text |TraceVis-History|
- *        4                text format-version-id (e.g. |0001|).
+ *       12                text:   |TraceVis-History|
+ *        4                text:   format-version-id (e.g. |0001|).
  *
- *        8                uint64 rdtsc time elapsed for entire log
- *        4                uint32 count of following records = M (= S_COUNT)
- *       8M              M uint64 rdtsc time totals by state, from 0 to S_COUNT-1
+ *        8                uint64: rdtsc time elapsed for entire log
+ *        4                uint32: count of following records = M (= S_COUNT)
+ *       8M              M uint64: rdtsc time totals by state, from 0 to S_COUNT-1
  *       9N              N 9-byte packed records (X = 17+9N)
- *             0                 byte VM state transitioned to
- *             8                 uint64 rdtsc timestamp, starting from 0
+ *                         Each record represents a transition out of an activity.
+ *             0                 byte:   VM state before transition
+ *             8                 uint64: rdtsc timestamp
  */
 
 #include <stdio.h>
     }
   }
 
+  void write(int state, uint64 time) {
+    if (print_history) {
+      putc(state, history_file);
+      uint64 t = time - t0;
+      fwrite(&t, sizeof(t), 1, history_file);
+    }
+  }
+
   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) {
-      putc(rec0.s, history_file);
-      uint64 t = rec1.t - t0;
-      fwrite(&t, 1, sizeof(rec1.t), history_file);
-    }
+    write(rec0.s, rec1.t);
 
     // Transition to interpreter
     if (rec0.s != S_INTERP && rec1.s == S_INTERP) {
   }
 
   void enter(const Record& rec) {
-    assert(rec.s >= 0);
-    assert(rec.s < S_COUNT);
-
-    if (stack.size() == 0) {
-      t0 = rec.t;
-      stack.push_back(Record(rec.t, 0, 0));
+    // State values >= S_COUNT represent events instead of states.
+    if (rec.s >= S_COUNT) {
+      write(rec.s, rec.t);
+    } else {
+	if (stack.size() == 0) {
+	  t0 = rec.t;
+	  stack.push_back(Record(rec.t, 0, 0));
+	}
+	transition(stack.back(), rec);
+	stack.push_back(rec);
     }
-    transition(stack.back(), rec);
-    stack.push_back(rec);
   }
 
   void exit(const Record& rec) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.