about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-11-29 12:42:04 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-11-29 12:42:04 -0800
commit8f2496770dcf1160a2150acd73a3d082298b4d06 (patch)
treefb2e9fc554910103127dee74083270315f98f4b6
parent81c87f08fa4fd9a27908b1d92c8aa897ad20cbb8 (diff)
downloadmu-8f2496770dcf1160a2150acd73a3d082298b4d06.tar.gz
2609 - run $browse-trace on old runs
This is long overdue. Let's see if it gets me using traces more during
debugging.

Though perhaps I'm being too persnickety. These are all valid ways to
debug programs:

a) print directly to screen
b) log, and then dump the log on some condition
c) temporarily print selected log statements directly to screen
d) log, and then browse the log using the zoom interface

For a) to work we need to normally keep prints empty.
For b) to work the log needs to be of some manageable size, where it's
tractable to find interesting features.
d) is the ultimate weapon, but might be slow because it's interactive

c) seems like the ugly case. Should I be trying to avoid it altogether?
Let's try, and see if d) is useable when we want to do c). For simple
cases it's still totally acceptable to just print. If the prints get too
complex to parse, then we move to the zoom interface. Hopefully it'll be
easier because we have to spend less time getting the prints just so.

(Independent of all this, often the best way to make a log manageable so
any of the approaches works: distill the bad behavior down to a test.
But that leads to chicken-and-egg situations where you need to first
understand before you can distill.)
-rw-r--r--000organization.cc1
-rw-r--r--001help.cc3
-rw-r--r--090trace_browser.cc30
3 files changed, 34 insertions, 0 deletions
diff --git a/000organization.cc b/000organization.cc
index 61c60b63..0f2518f5 100644
--- a/000organization.cc
+++ b/000organization.cc
@@ -105,6 +105,7 @@ int main(int argc, char* argv[]) {
 
   // End One-time Setup
 
+  // Commandline Parsing
   // End Commandline Parsing
 
   return 0;  // End Main
diff --git a/001help.cc b/001help.cc
index 4b7c3858..b2ca4c46 100644
--- a/001help.cc
+++ b/001help.cc
@@ -16,6 +16,9 @@ if (argc <= 1 || is_equal(argv[1], "--help")) {
        << "You can test directories just like files.\n"
        << "To pass ingredients to a mu program, provide them after '--':\n"
        << "  mu file_or_dir1 file_or_dir2 ... -- ingredient1 ingredient2 ...\n"
+       << "\n"
+       << "To browse a trace generated by a previous run:\n"
+       << "  mu browse-trace file\n"
        ;
   return 0;
 }
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));
+  }
+}