diff options
author | Evan Martin <martine@danga.com> | 2012-01-05 21:35:47 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-01-05 22:03:55 (GMT) |
commit | d5165bafdabbfba23d33a5e0ceb9e0e680384183 (patch) | |
tree | 7f61a5d96d62c1f75d60b761b7d1059a0783c2bd /src/ninja.cc | |
parent | 9e31e01595656cc2dacd2f97fb6e765799518254 (diff) | |
download | Ninja-d5165bafdabbfba23d33a5e0ceb9e0e680384183.zip Ninja-d5165bafdabbfba23d33a5e0ceb9e0e680384183.tar.gz Ninja-d5165bafdabbfba23d33a5e0ceb9e0e680384183.tar.bz2 |
add a '-d stats' flag for detailed timings
1) Add a system for recording detailed timing info of functions.
2) Add a -d flag for requesting debug info at runtime, with the
above as the first user.
Diffstat (limited to 'src/ninja.cc')
-rw-r--r-- | src/ninja.cc | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/ninja.cc b/src/ninja.cc index a55bfc4..3f76e9c 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -39,6 +39,7 @@ #include "edit_distance.h" #include "graph.h" #include "graphviz.h" +#include "metrics.h" #include "parsers.h" #include "state.h" #include "util.h" @@ -85,6 +86,7 @@ void Usage(const BuildConfig& config) { " -n dry run (don't run commands but pretend they succeeded)\n" " -v show all command lines while building\n" "\n" +" -d MODE enable debugging (use -d list to list modes)\n" " -t TOOL run a subtool\n" " use '-t list' to list subtools.\n" " terminates toplevel options; further flags are passed to the tool.\n", @@ -517,6 +519,23 @@ int RunTool(const string& tool, Globals* globals, int argc, char** argv) { return 1; } +/// Enable a debugging mode. Returns false if Ninja should exit instead +/// of continuing. +bool DebugEnable(const string& name, Globals* globals) { + if (name == "list") { + printf("debugging modes:\n" +" stats print operation counts/timing info\n"); +//"multiple modes can be enabled via -d FOO -d BAR\n"); + return false; + } else if (name == "stats") { + g_metrics = new Metrics; + return true; + } else { + printf("ninja: unknown debug setting '%s'\n", name.c_str()); + return false; + } +} + int RunBuild(Globals* globals, int argc, char** argv) { string err; vector<Node*> targets; @@ -551,7 +570,6 @@ int RunBuild(Globals* globals, int argc, char** argv) { return 0; } - } // anonymous namespace int main(int argc, char** argv) { @@ -572,9 +590,13 @@ int main(int argc, char** argv) { int opt; while (tool.empty() && - (opt = getopt_long(argc, argv, "f:hj:k:nt:vC:", kLongOptions, + (opt = getopt_long(argc, argv, "d:f:hj:k:nt:vC:", kLongOptions, NULL)) != -1) { switch (opt) { + case 'd': + if (!DebugEnable(optarg, &globals)) + return 1; + break; case 'f': input_file = optarg; break; @@ -680,5 +702,8 @@ reload: } } - return RunBuild(&globals, argc, argv); + int result = RunBuild(&globals, argc, argv); + if (g_metrics) + g_metrics->Report(); + return result; } |