about summary refs log tree commit diff stats
path: root/cpp/002trace
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-19 15:36:49 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-19 15:37:47 -0800
commitf4b6b2c2876bb29c01bfd95f55347e7d74222974 (patch)
tree151c84af6dca71de824267275e4edfb665ec2a26 /cpp/002trace
parentcae5461b1dfeb70dac6b66192fc6b12952beb723 (diff)
downloadmu-f4b6b2c2876bb29c01bfd95f55347e7d74222974.tar.gz
784 - persist traces in literate version
Diffstat (limited to 'cpp/002trace')
-rw-r--r--cpp/002trace13
1 files changed, 12 insertions, 1 deletions
diff --git a/cpp/002trace b/cpp/002trace
index 4d584cb1..e3ebd17e 100644
--- a/cpp/002trace
+++ b/cpp/002trace
@@ -185,9 +185,20 @@ ostream& operator<<(ostream& os, unused die) {
 #define DUMP(layer)  cerr << Trace_stream->readable_contents(layer)
 
 // Trace_stream is a resource, lease_tracer uses RAII to manage it.
+string Trace_file;
+static string Trace_dir = ".traces/";
 struct lease_tracer {
   lease_tracer() { Trace_stream = new trace_stream; }
-  ~lease_tracer() { delete Trace_stream, Trace_stream = NULL; }
+  ~lease_tracer() {
+//?     cerr << "write to file? " << Trace_file << "$\n"; //? 2
+    if (!Trace_file.empty()) {
+//?       cerr << "writing\n"; //? 2
+      ofstream fout((Trace_dir+Trace_file).c_str());
+      fout << Trace_stream->readable_contents("");
+      fout.close();
+    }
+    delete Trace_stream, Trace_stream = NULL, Trace_file = "";
+  }
 };
 
 #define START_TRACING_UNTIL_END_OF_SCOPE  lease_tracer leased_tracer;