diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-07-26 10:09:29 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-07-26 10:09:29 -0700 |
commit | 257add0f7e437f0a1a355a748be0c97e03882b0c (patch) | |
tree | 917af5e78761b1ce7f6f5e47b3736777b4930896 /003trace.cc | |
parent | 3b798ea2c9dadca94f808f168dc2cb37abcaeb94 (diff) | |
download | mu-257add0f7e437f0a1a355a748be0c97e03882b0c.tar.gz |
4421
Clean up the rat's nest that all my trace management globals had gradually turned into. a) Get rid of 'Start_tracing'. Horryibly named, I don't know how I missed that until now. b) Never use START_TRACING_UNTIL_END_OF_SCOPE in main(). It's confusing to combine it with atexit(delete Trace_stream), because the atexit() never has to run. Instead we'll just manually initialize Trace_stream and let atexit() clean up. c) If we run tests we only want a trace for the test run itself. So delete the Trace_stream that was initialized at the top of main -- once it's clear we had no load-time errors. d) Clean up horribly "Load Recipes" waypoints, combine them with the better name, "Mu Prelude". Putting these together, we have the following manual tests: - CFLAGS=-g mu x.mu Should not create last_run. - CFLAGS=-g mu --trace x.mu Should create last_run. Should write it out exactly once. - CFLAGS=-g mu --trace x.mu # when x.mu has an error Should create last_run. Should write it out exactly once. - CFLAGS=-g mu --trace test copy_literal # C test Should create last_run. Should write it out exactly once. - CFLAGS=-g mu --trace test recipe_with_header # Mu test Should create last_run. Should write it out exactly once. I don't know how to automate these scenarios yet. We need a way to run our build toolchain atop our stack.
Diffstat (limited to '003trace.cc')
-rw-r--r-- | 003trace.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/003trace.cc b/003trace.cc index 57604ee0..8fe3ebb0 100644 --- a/003trace.cc +++ b/003trace.cc @@ -85,6 +85,28 @@ Hide_errors = false; Dump_trace = false; Dump_label = ""; +//: Support for tracing an entire run. +//: Traces can have a lot of overhead, so only turn them on when asked. +:(before "End Commandline Options(*arg)") +else if (is_equal(*arg, "--trace")) { + Save_trace = true; +} +:(before "End Commandline Parsing") +if (Save_trace) { + cerr << "initializing trace\n"; + Trace_stream = new trace_stream; +} +:(code) +void cleanup_main() { + if (!Trace_stream) return; + if (Save_trace) + Trace_stream->save(); + delete Trace_stream; + Trace_stream = NULL; +} +:(before "End One-time Setup") +atexit(cleanup_main); + :(before "End Types") // Pre-define some global constants that trace_stream needs to know about. // Since they're in the Types section, they'll be included in any cleaved @@ -118,6 +140,7 @@ struct trace_stream { } void save() { + cerr << "saving trace to last_run\n"; ofstream fout("last_run"); fout << readable_contents(""); fout.close(); |