From e4ac3c9e6e5464a0fc0f8fd3763a572e0e180c04 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 1 Dec 2018 14:13:33 -0800 Subject: 4814 --- html/100trace_browser.cc.html | 238 +++++++++++++++++++++--------------------- 1 file changed, 121 insertions(+), 117 deletions(-) (limited to 'html/100trace_browser.cc.html') diff --git a/html/100trace_browser.cc.html b/html/100trace_browser.cc.html index 54fbdef7..4f8bbd64 100644 --- a/html/100trace_browser.cc.html +++ b/html/100trace_browser.cc.html @@ -11,17 +11,20 @@ @@ -56,6 +59,7 @@ if ('onhashchange' in window) { +https://github.com/akkartik/mu/blob/master/100trace_browser.cc
   1 //: A debugging helper that lets you zoom in/out on a trace.
   2 //: Warning: this tool has zero automated tests.
@@ -125,7 +129,7 @@ if ('onhashchange' in window) {
  66 :(before "End Primitive Recipe Declarations")
  67 _BROWSE_TRACE,
  68 :(before "End Primitive Recipe Numbers")
- 69 put(Recipe_ordinal, "$browse-trace", _BROWSE_TRACE);
+ 69 put(Recipe_ordinal, "$browse-trace", _BROWSE_TRACE);
  70 :(before "End Primitive Recipe Checks")
  71 case _BROWSE_TRACE: {
  72   break;
@@ -145,36 +149,36 @@ if ('onhashchange' in window) {
  86 }
  87 
  88 :(before "End Globals")
- 89 set<int> Visible;
- 90 int Top_of_screen = 0;
- 91 int Left_of_screen = 0;
- 92 int Last_printed_row = 0;
- 93 map<int, int> Trace_index;  // screen row -> trace index
- 94 string Current_search_pattern = "";
+ 89 set<int> Visible;
+ 90 int Top_of_screen = 0;
+ 91 int Left_of_screen = 0;
+ 92 int Last_printed_row = 0;
+ 93 map<int, int> Trace_index;  // screen row -> trace index
+ 94 string Current_search_pattern = "";
  95 :(before "End Types")
  96 enum search_direction { FORWARD, BACKWARD };
  97 :(before "End Globals")
- 98 search_direction Current_search_direction = FORWARD;
+ 98 search_direction Current_search_direction = FORWARD;
  99 
 100 :(code)
 101 void start_trace_browser() {
-102   if (!Trace_stream) return;
-103   cerr << "computing min depth to display\n";
+102   if (!Trace_stream) return;
+103   cerr << "computing min depth to display\n";
 104   int min_depth = 9999;
-105   for (int i = 0;  i < SIZE(Trace_stream->past_lines);  ++i) {
-106     trace_line& curr_line = Trace_stream->past_lines.at(i);
+105   for (int i = 0;  i < SIZE(Trace_stream->past_lines);  ++i) {
+106     trace_line& curr_line = Trace_stream->past_lines.at(i);
 107     if (curr_line.depth < min_depth) min_depth = curr_line.depth;
 108   }
 109   cerr << "min depth is " << min_depth << '\n';
-110   cerr << "computing lines to display\n";
-111   for (int i = 0;  i < SIZE(Trace_stream->past_lines);  ++i) {
-112     if (Trace_stream->past_lines.at(i).depth == min_depth)
-113       Visible.insert(i);
+110   cerr << "computing lines to display\n";
+111   for (int i = 0;  i < SIZE(Trace_stream->past_lines);  ++i) {
+112     if (Trace_stream->past_lines.at(i).depth == min_depth)
+113       Visible.insert(i);
 114   }
 115   tb_init();
 116   tb_clear();
-117   Display_row = Display_column = 0;
-118   Top_of_screen = 0;
+117   Display_row = Display_column = 0;
+118   Top_of_screen = 0;
 119   refresh_screen_rows();
 120   while (true) {
 121     render();
@@ -182,146 +186,146 @@ if ('onhashchange' in window) {
 123     if (key == 'q' || key == 'Q' || key == TB_KEY_CTRL_C) break;
 124     if (key == 'j' || key == TB_KEY_ARROW_DOWN) {
 125       // move cursor one line down
-126       if (Display_row < Last_printed_row) ++Display_row;
+126       if (Display_row < Last_printed_row) ++Display_row;
 127     }
 128     else if (key == 'k' || key == TB_KEY_ARROW_UP) {
 129       // move cursor one line up
-130       if (Display_row > 0) --Display_row;
+130       if (Display_row > 0) --Display_row;
 131     }
 132     else if (key == 't') {
 133       // move cursor to top of screen
-134       Display_row = 0;
+134       Display_row = 0;
 135     }
 136     else if (key == 'c') {
 137       // move cursor to center of screen
-138       Display_row = tb_height()/2;
-139       while (!contains_key(Trace_index, Display_row))
-140         --Display_row;
+138       Display_row = tb_height()/2;
+139       while (!contains_key(Trace_index, Display_row))
+140         --Display_row;
 141     }
 142     else if (key == 'b') {
 143       // move cursor to bottom of screen
-144       Display_row = tb_height()-1;
-145       while (!contains_key(Trace_index, Display_row))
-146         --Display_row;
+144       Display_row = tb_height()-1;
+145       while (!contains_key(Trace_index, Display_row))
+146         --Display_row;
 147     }
 148     else if (key == 'T') {
 149       // scroll line at cursor to top of screen
-150       Top_of_screen = get(Trace_index, Display_row);
-151       Display_row = 0;
+150       Top_of_screen = get(Trace_index, Display_row);
+151       Display_row = 0;
 152       refresh_screen_rows();
 153     }
 154     else if (key == 'h' || key == TB_KEY_ARROW_LEFT) {
 155       // pan screen one character left
-156       if (Left_of_screen > 0) --Left_of_screen;
+156       if (Left_of_screen > 0) --Left_of_screen;
 157     }
 158     else if (key == 'l' || key == TB_KEY_ARROW_RIGHT) {
 159       // pan screen one character right
-160       ++Left_of_screen;
+160       ++Left_of_screen;
 161     }
 162     else if (key == 'H') {
 163       // pan screen one screen-width left
-164       Left_of_screen -= (tb_width() - 5);
-165       if (Left_of_screen < 0) Left_of_screen = 0;
+164       Left_of_screen -= (tb_width() - 5);
+165       if (Left_of_screen < 0) Left_of_screen = 0;
 166     }
 167     else if (key == 'L') {
 168       // pan screen one screen-width right
-169       Left_of_screen += (tb_width() - 5);
+169       Left_of_screen += (tb_width() - 5);
 170     }
 171     else if (key == 'J' || key == TB_KEY_PGDN || key == TB_KEY_CTRL_F) {
 172       // page-down
-173       if (Trace_index.find(tb_height()-1) != Trace_index.end()) {
-174         Top_of_screen = get(Trace_index, tb_height()-1) + 1;
+173       if (Trace_index.find(tb_height()-1) != Trace_index.end()) {
+174         Top_of_screen = get(Trace_index, tb_height()-1) + 1;
 175         refresh_screen_rows();
 176       }
 177     }
 178     else if (key == 'K' || key == TB_KEY_PGUP || key == TB_KEY_CTRL_B) {
 179       // page-up is more convoluted
-180       for (int screen_row = tb_height();  screen_row > 0 && Top_of_screen > 0;  --screen_row) {
-181         --Top_of_screen;
-182         if (Top_of_screen <= 0) break;
-183         while (Top_of_screen > 0 && !contains_key(Visible, Top_of_screen))
-184           --Top_of_screen;
+180       for (int screen_row = tb_height();  screen_row > 0 && Top_of_screen > 0;  --screen_row) {
+181         --Top_of_screen;
+182         if (Top_of_screen <= 0) break;
+183         while (Top_of_screen > 0 && !contains_key(Visible, Top_of_screen))
+184           --Top_of_screen;
 185       }
-186       if (Top_of_screen >= 0)
+186       if (Top_of_screen >= 0)
 187         refresh_screen_rows();
 188     }
 189     else if (key == 'g' || key == TB_KEY_HOME) {
-190         Top_of_screen = 0;
-191         Last_printed_row = 0;
-192         Display_row = 0;
+190         Top_of_screen = 0;
+191         Last_printed_row = 0;
+192         Display_row = 0;
 193         refresh_screen_rows();
 194     }
 195     else if (key == 'G' || key == TB_KEY_END) {
 196       // go to bottom of screen; largely like page-up, interestingly
-197       Top_of_screen = SIZE(Trace_stream->past_lines)-1;
-198       for (int screen_row = tb_height();  screen_row > 0 && Top_of_screen > 0;  --screen_row) {
-199         --Top_of_screen;
-200         if (Top_of_screen <= 0) break;
-201         while (Top_of_screen > 0 && !contains_key(Visible, Top_of_screen))
-202           --Top_of_screen;
+197       Top_of_screen = SIZE(Trace_stream->past_lines)-1;
+198       for (int screen_row = tb_height();  screen_row > 0 && Top_of_screen > 0;  --screen_row) {
+199         --Top_of_screen;
+200         if (Top_of_screen <= 0) break;
+201         while (Top_of_screen > 0 && !contains_key(Visible, Top_of_screen))
+202           --Top_of_screen;
 203       }
 204       refresh_screen_rows();
 205       // move cursor to bottom
-206       Display_row = Last_printed_row;
+206       Display_row = Last_printed_row;
 207       refresh_screen_rows();
 208     }
 209     else if (key == TB_KEY_CARRIAGE_RETURN) {
 210       // expand lines under current by one level
-211       assert(contains_key(Trace_index, Display_row));
-212       int start_index = get(Trace_index, Display_row);
+211       assert(contains_key(Trace_index, Display_row));
+212       int start_index = get(Trace_index, Display_row);
 213       int index = 0;
 214       // simultaneously compute end_index and min_depth
 215       int min_depth = 9999;
-216       for (index = start_index+1;  index < SIZE(Trace_stream->past_lines);  ++index) {
-217         if (contains_key(Visible, index)) break;
-218         trace_line& curr_line = Trace_stream->past_lines.at(index);
-219         assert(curr_line.depth > Trace_stream->past_lines.at(start_index).depth);
+216       for (index = start_index+1;  index < SIZE(Trace_stream->past_lines);  ++index) {
+217         if (contains_key(Visible, index)) break;
+218         trace_line& curr_line = Trace_stream->past_lines.at(index);
+219         assert(curr_line.depth > Trace_stream->past_lines.at(start_index).depth);
 220         if (curr_line.depth < min_depth) min_depth = curr_line.depth;
 221       }
 222       int end_index = index;
 223       // mark as visible all intervening indices at min_depth
 224       for (index = start_index;  index < end_index;  ++index) {
-225         trace_line& curr_line = Trace_stream->past_lines.at(index);
+225         trace_line& curr_line = Trace_stream->past_lines.at(index);
 226         if (curr_line.depth == min_depth) {
-227           Visible.insert(index);
+227           Visible.insert(index);
 228         }
 229       }
 230       refresh_screen_rows();
 231     }
 232     else if (key == TB_KEY_BACKSPACE || key == TB_KEY_BACKSPACE2) {
 233       // collapse all lines under current
-234       assert(contains_key(Trace_index, Display_row));
-235       int start_index = get(Trace_index, Display_row);
+234       assert(contains_key(Trace_index, Display_row));
+235       int start_index = get(Trace_index, Display_row);
 236       int index = 0;
 237       // end_index is the next line at a depth same as or lower than start_index
-238       int initial_depth = Trace_stream->past_lines.at(start_index).depth;
-239       for (index = start_index+1;  index < SIZE(Trace_stream->past_lines);  ++index) {
-240         if (!contains_key(Visible, index)) continue;
-241         trace_line& curr_line = Trace_stream->past_lines.at(index);
+238       int initial_depth = Trace_stream->past_lines.at(start_index).depth;
+239       for (index = start_index+1;  index < SIZE(Trace_stream->past_lines);  ++index) {
+240         if (!contains_key(Visible, index)) continue;
+241         trace_line& curr_line = Trace_stream->past_lines.at(index);
 242         if (curr_line.depth <= initial_depth) break;
 243       }
 244       int end_index = index;
 245       // mark as visible all intervening indices at min_depth
 246       for (index = start_index+1;  index < end_index;  ++index) {
-247         Visible.erase(index);
+247         Visible.erase(index);
 248       }
 249       refresh_screen_rows();
 250     }
 251     else if (key == '/') {
 252       if (start_search_editor(FORWARD))
-253         search(Current_search_pattern, Current_search_direction);
+253         search(Current_search_pattern, Current_search_direction);
 254     }
 255     else if (key == '?') {
 256       if (start_search_editor(BACKWARD))
-257         search(Current_search_pattern, Current_search_direction);
+257         search(Current_search_pattern, Current_search_direction);
 258     }
 259     else if (key == 'n') {
-260       if (!Current_search_pattern.empty())
-261         search(Current_search_pattern, Current_search_direction);
+260       if (!Current_search_pattern.empty())
+261         search(Current_search_pattern, Current_search_direction);
 262     }
 263     else if (key == 'N') {
-264       if (!Current_search_pattern.empty())
-265         search(Current_search_pattern, opposite(Current_search_direction));
+264       if (!Current_search_pattern.empty())
+265         search(Current_search_pattern, opposite(Current_search_direction));
 266     }
 267   }
 268   tb_shutdown();
@@ -340,8 +344,8 @@ if ('onhashchange' in window) {
 281     int key = read_key();
 282     if (key == TB_KEY_ENTER) {
 283       if (!pattern.empty()) {
-284         Current_search_pattern = pattern;
-285         Current_search_direction = dir;
+284         Current_search_pattern = pattern;
+285         Current_search_direction = dir;
 286       }
 287       return true;
 288     }
@@ -427,24 +431,24 @@ if ('onhashchange' in window) {
 368 }
 369 
 370 void search_next(const string& pat) {
-371   for (int trace_index = get(Trace_index, Display_row)+1;  trace_index < SIZE(Trace_stream->past_lines);  ++trace_index) {
-372     if (!contains_key(Visible, trace_index)) continue;
-373     const trace_line& line = Trace_stream->past_lines.at(trace_index);
+371   for (int trace_index = get(Trace_index, Display_row)+1;  trace_index < SIZE(Trace_stream->past_lines);  ++trace_index) {
+372     if (!contains_key(Visible, trace_index)) continue;
+373     const trace_line& line = Trace_stream->past_lines.at(trace_index);
 374     if (line.label.find(pat) == string::npos && line.contents.find(pat) == string::npos) continue;
-375     Top_of_screen = trace_index;
-376     Display_row = 0;
+375     Top_of_screen = trace_index;
+376     Display_row = 0;
 377     refresh_screen_rows();
 378     return;
 379   }
 380 }
 381 
 382 void search_previous(const string& pat) {
-383   for (int trace_index = get(Trace_index, Display_row)-1;  trace_index >= 0;  --trace_index) {
-384     if (!contains_key(Visible, trace_index)) continue;
-385     const trace_line& line = Trace_stream->past_lines.at(trace_index);
+383   for (int trace_index = get(Trace_index, Display_row)-1;  trace_index >= 0;  --trace_index) {
+384     if (!contains_key(Visible, trace_index)) continue;
+385     const trace_line& line = Trace_stream->past_lines.at(trace_index);
 386     if (line.label.find(pat) == string::npos && line.contents.find(pat) == string::npos) continue;
-387     Top_of_screen = trace_index;
-388     Display_row = 0;
+387     Top_of_screen = trace_index;
+388     Display_row = 0;
 389     refresh_screen_rows();
 390     return;
 391   }
@@ -460,15 +464,15 @@ if ('onhashchange' in window) {
 401 // update Trace_indices for each screen_row on the basis of Top_of_screen and Visible
 402 void refresh_screen_rows() {
 403   int screen_row = 0, index = 0;
-404   Trace_index.clear();
-405   for (screen_row = 0, index = Top_of_screen;  screen_row < tb_height() && index < SIZE(Trace_stream->past_lines);  ++screen_row, ++index) {
+404   Trace_index.clear();
+405   for (screen_row = 0, index = Top_of_screen;  screen_row < tb_height() && index < SIZE(Trace_stream->past_lines);  ++screen_row, ++index) {
 406     // skip lines without depth for now
-407     while (!contains_key(Visible, index)) {
+407     while (!contains_key(Visible, index)) {
 408       ++index;
-409       if (index >= SIZE(Trace_stream->past_lines)) goto done;
+409       if (index >= SIZE(Trace_stream->past_lines)) goto done;
 410     }
-411     assert(index < SIZE(Trace_stream->past_lines));
-412     put(Trace_index, screen_row, index);
+411     assert(index < SIZE(Trace_stream->past_lines));
+412     put(Trace_index, screen_row, index);
 413   }
 414 done:;
 415 }
@@ -476,8 +480,8 @@ if ('onhashchange' in window) {
 417 void render() {
 418   int screen_row = 0;
 419   for (screen_row = 0;  screen_row < tb_height();  ++screen_row) {
-420     if (!contains_key(Trace_index, screen_row)) break;
-421     trace_line& curr_line = Trace_stream->past_lines.at(get(Trace_index, screen_row));
+420     if (!contains_key(Trace_index, screen_row)) break;
+421     trace_line& curr_line = Trace_stream->past_lines.at(get(Trace_index, screen_row));
 422     ostringstream out;
 423     out << std::setw(4) << curr_line.depth << ' ' << curr_line.label << ": " << curr_line.contents;
 424     if (screen_row < tb_height()-1) {
@@ -489,37 +493,37 @@ if ('onhashchange' in window) {
 430         if (delta > 999) out << static_cast<char>(2);
 431       }
 432     }
-433     render_line(screen_row, out.str(), screen_row == Display_row);
+433     render_line(screen_row, out.str(), screen_row == Display_row);
 434   }
 435   // clear rest of screen
-436   Last_printed_row = screen_row-1;
+436   Last_printed_row = screen_row-1;
 437   for (;  screen_row < tb_height();  ++screen_row)
 438     render_line(screen_row, "~", /*cursor_line?*/false);
 439   // move cursor back to display row at the end
-440   tb_set_cursor(0, Display_row);
+440   tb_set_cursor(0, Display_row);
 441 }
 442 
 443 int lines_hidden(int screen_row) {
-444   assert(contains_key(Trace_index, screen_row));
-445   if (!contains_key(Trace_index, screen_row+1))
-446     return SIZE(Trace_stream->past_lines) - get(Trace_index, screen_row);
+444   assert(contains_key(Trace_index, screen_row));
+445   if (!contains_key(Trace_index, screen_row+1))
+446     return SIZE(Trace_stream->past_lines) - get(Trace_index, screen_row);
 447   else
-448     return get(Trace_index, screen_row+1) - get(Trace_index, screen_row);
+448     return get(Trace_index, screen_row+1) - get(Trace_index, screen_row);
 449 }
 450 
 451 void render_line(int screen_row, const string& s, bool cursor_line) {
 452   int col = 0;
 453   int color = TB_WHITE;
 454   int background_color = cursor_line ? /*subtle grey*/240 : TB_BLACK;
-455   vector<pair<size_t, size_t> > highlight_ranges = find_all_occurrences(s, Current_search_pattern);
+455   vector<pair<size_t, size_t> > highlight_ranges = find_all_occurrences(s, Current_search_pattern);
 456   tb_set_cursor(0, screen_row);
-457   for (col = 0;  col < tb_width() && col+Left_of_screen < SIZE(s);  ++col) {
-458     char c = s.at(col+Left_of_screen);  // todo: unicode
+457   for (col = 0;  col < tb_width() && col+Left_of_screen < SIZE(s);  ++col) {
+458     char c = s.at(col+Left_of_screen);  // todo: unicode
 459     if (c == '\n') c = ';';  // replace newlines with semi-colons
 460     // escapes. hack: can't start a line with them.
 461     if (c == '\1') { color = /*red*/1;  c = ' '; }
 462     if (c == '\2') { color = TB_WHITE;  c = ' '; }
-463     if (in_range(highlight_ranges, col+Left_of_screen))
+463     if (in_range(highlight_ranges, col+Left_of_screen))
 464       tb_print(c, TB_BLACK, /*yellow*/11);
 465     else
 466       tb_print(c, color, background_color);
@@ -556,7 +560,7 @@ if ('onhashchange' in window) {
 497     cerr << "no such file: " << filename << '\n';
 498     exit(1);
 499   }
-500   Trace_stream = new trace_stream;
+500   Trace_stream = new trace_stream;
 501   while (has_data(tin)) {
 502     tin >> std::noskipws;
 503       skip_whitespace_but_not_newline(tin);
@@ -573,9 +577,9 @@ if ('onhashchange' in window) {
 514     if (*--label.end() == ':') label.erase(--label.end());
 515     string line;
 516     getline(tin, line);
-517     Trace_stream->past_lines.push_back(trace_line(depth, label, line));
+517     Trace_stream->past_lines.push_back(trace_line(depth, label, line));
 518   }
-519   cerr << "lines read: " << Trace_stream->past_lines.size() << '\n';
+519   cerr << "lines read: " << Trace_stream->past_lines.size() << '\n';
 520 }
 521 
 522 int read_key() {
-- 
cgit 1.4.1-2-gfad0