From 094548498bfd351d2b2f7323e7757113654dbab1 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 14 Jul 2015 15:51:15 -0700 Subject: 1782 - stop tracing anything but warnings inside edit Speeds up edit.mu tests by 10x, and shrinks memory usage by 100x. We need a more efficient implementation of traces, but we can keep going for now. We didn't really need to reclaim memory just yet, after all. Mu is pretty memory-efficient. --- 003trace.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to '003trace.cc') diff --git a/003trace.cc b/003trace.cc index d7b78668..11bad7a2 100644 --- a/003trace.cc +++ b/003trace.cc @@ -103,14 +103,17 @@ struct trace_stream { string curr_layer; int curr_depth; string dump_layer; + string collect_layer; // if set, ignore all other layers + ofstream null_stream; // never opens a file, so writes silently fail trace_stream() :curr_stream(NULL), curr_depth(0) {} ~trace_stream() { if (curr_stream) delete curr_stream; } - ostringstream& stream(string layer) { + ostream& stream(string layer) { return stream(0, layer); } - ostringstream& stream(int depth, string layer) { + ostream& stream(int depth, string layer) { + if (!collect_layer.empty() && layer != collect_layer) return null_stream; newline(); curr_stream = new ostringstream; curr_layer = layer; @@ -154,7 +157,6 @@ trace_stream* Trace_stream = NULL; // Top-level helper. IMPORTANT: can't nest. #define trace(...) !Trace_stream ? cerr /*print nothing*/ : Trace_stream->stream(__VA_ARGS__) -//? #define trace(...) true ? cerr /*print nothing*/ : Trace_stream->stream(__VA_ARGS__) // Warnings should go straight to cerr by default since calls to trace() have // some unfriendly constraints (they delay printing, they can't nest) #define raise ((!Trace_stream || !Hide_warnings) ? (tb_shutdown(),cerr) /*do print*/ : Trace_stream->stream("warn")) -- cgit 1.4.1-2-gfad0