1. Leandro Lameiro
  2. tracevis_adds_legends_to_graph_and_refactors

Commits

David Mandelin  committed ed351a6

adding binary history output mode to C++ version

  • Participants
  • Parent commits 8039cff
  • Branches default

Comments (0)

Files changed (1)

File src/binlog.cpp

View file
 const size_t pagesize = 4096;
 const unsigned page_records = pagesize/sizeof(uint64);
 
+// options
+bool print_summary = true;
+bool print_history = false;
+
 static void rep(char ch, int n)
 {
   for (int i = 0; i < n; ++i)
     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);
+    }
+
     // Transition to interpreter
     if (rec0.s != S_INTERP && rec1.s == S_INTERP) {
       to_interp.t = rec1.t;
       to_interp.r = rec1.r;
     }
 
-#if 1
     // Transition from interpreter
     if (rec0.s == S_INTERP && rec1.s != S_INTERP) {
       //reason_summary[EReason(to_interp)] += rec1.t - to_interp.t;
       reason_summary[EReason(to_interp)] += rec1.t - to_interp.t;
     }
-#else
-    if (rec0.s == S_INTERP)
-      reason_summary[EReason(to_interp)] += dt;
-#endif
   }
 
   void enter(const Record& rec) {
 
 void process_record(History& h, uint64 raw)
 {
-  //Record(raw).list();
   Record rec(raw);
   if (rec.s)
     h.enter(rec);
     h.exit(rec);
 }
 
+bool streq(const char* s1, const char* s2)
+{
+  return !strcmp(s1, s2);
+}
+
 int main(int argc, char **argv)
 {
-  if (argc > 1)
-    filename = argv[1];
+  int i = 1;
+  for (; i < argc; ++i) {
+    const char* arg = argv[i];
+    if (streq(arg, "-h")) {
+      print_summary = false;
+      print_history = true;
+    }
+  }
+
+  if (i < argc)
+    filename = argv[i];
 
   FILE* f = fopen(filename, "rb");
   uint64 recs[page_records];
       process_record(h, recs[i]);
     }
   }
-  h.list_state_summary();
-  printf("\n");
-  h.list_reason_summary();
+  if (print_summary) {
+    h.list_state_summary();
+    printf("\n");
+    h.list_reason_summary();
+  }
   return 0;
 }