about summary refs log tree commit diff stats
path: root/090trace_browser.cc
diff options
context:
space:
mode:
Diffstat (limited to '090trace_browser.cc')
-rw-r--r--090trace_browser.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/090trace_browser.cc b/090trace_browser.cc
index 676be4f2..93cba272 100644
--- a/090trace_browser.cc
+++ b/090trace_browser.cc
@@ -1,3 +1,6 @@
+//: A debugging helper that lets you zoom in/out on a trace.
+
+//: browse the trace we just created
 :(before "End Primitive Recipe Declarations")
 _BROWSE_TRACE,
 :(before "End Primitive Recipe Numbers")
@@ -12,6 +15,14 @@ case _BROWSE_TRACE: {
   break;
 }
 
+//: browse a trace loaded from a file
+:(after "Commandline Parsing")
+if (argc == 3 && is_equal(argv[1], "browse-trace")) {
+  load_trace(argv[2]);
+  start_trace_browser();
+  return 0;
+}
+
 :(before "End Globals")
 set<long long int> Visible;
 long long int Top_of_screen = 0;
@@ -211,3 +222,22 @@ void render_line(int screen_row, const string& s) {
     tb_change_cell(col, screen_row, ' ', TB_WHITE, TB_BLACK);
   }
 }
+
+void load_trace(const char* filename) {
+  ifstream tin(filename);
+  if (!tin) {
+    cerr << "no such file: " << filename << '\n';
+    exit(1);
+  }
+  Trace_stream = new trace_stream;
+  while (has_data(tin)) {
+    int depth;
+    tin >> depth;
+    string label;
+    tin >> label;
+    if (*--label.end() == ':') label.erase(--label.end());
+    string line;
+    getline(tin, line);
+    Trace_stream->past_lines.push_back(trace_line(depth, label, line));
+  }
+}