summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2013-07-08 19:34:46 (GMT)
committerNico Weber <thakis@chromium.org>2013-07-08 19:34:46 (GMT)
commit8de46a9685f562b75319bb48263e8c787e86d48b (patch)
tree21f41c2d59b4cfb0a5b467ccdfaa293946c157b1 /src
parent1f7fa18dea3a57653811f75072871da08d1cff7b (diff)
downloadNinja-8de46a9685f562b75319bb48263e8c787e86d48b.zip
Ninja-8de46a9685f562b75319bb48263e8c787e86d48b.tar.gz
Ninja-8de46a9685f562b75319bb48263e8c787e86d48b.tar.bz2
Add a 'recompact' tool, which forces recompaction of the build and deps logs.
This is useful for performance comparisons between two build directories.
Diffstat (limited to 'src')
-rw-r--r--src/build_log.cc2
-rw-r--r--src/deps_log.cc2
-rw-r--r--src/ninja.cc36
3 files changed, 34 insertions, 6 deletions
diff --git a/src/build_log.cc b/src/build_log.cc
index 6b73002..2478e22 100644
--- a/src/build_log.cc
+++ b/src/build_log.cc
@@ -109,7 +109,6 @@ BuildLog::~BuildLog() {
bool BuildLog::OpenForWrite(const string& path, string* err) {
if (needs_recompaction_) {
- Close();
if (!Recompact(path, err))
return false;
}
@@ -351,6 +350,7 @@ bool BuildLog::Recompact(const string& path, string* err) {
METRIC_RECORD(".ninja_log recompact");
printf("Recompacting log...\n");
+ Close();
string temp_path = path + ".recompact";
FILE* f = fopen(temp_path.c_str(), "wb");
if (!f) {
diff --git a/src/deps_log.cc b/src/deps_log.cc
index ce9bf06..63e0d95 100644
--- a/src/deps_log.cc
+++ b/src/deps_log.cc
@@ -43,7 +43,6 @@ DepsLog::~DepsLog() {
bool DepsLog::OpenForWrite(const string& path, string* err) {
if (needs_recompaction_) {
- Close();
if (!Recompact(path, err))
return false;
}
@@ -265,6 +264,7 @@ bool DepsLog::Recompact(const string& path, string* err) {
METRIC_RECORD(".ninja_deps recompact");
printf("Recompacting deps...\n");
+ Close();
string temp_path = path + ".recompact";
// OpenForWrite() opens for append. Make sure it's not appending to a
diff --git a/src/ninja.cc b/src/ninja.cc
index 3b381b7..0c9bee1 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -110,15 +110,16 @@ struct NinjaMain {
int ToolCommands(int argc, char* argv[]);
int ToolClean(int argc, char* argv[]);
int ToolCompilationDatabase(int argc, char* argv[]);
+ int ToolRecompact(int argc, char* argv[]);
int ToolUrtle(int argc, char** argv);
/// Open the build log.
/// @return false on error.
- bool OpenBuildLog();
+ bool OpenBuildLog(bool recompact_only = false);
/// Open the deps log: load it, then open for writing.
/// @return false on error.
- bool OpenDepsLog();
+ bool OpenDepsLog(bool recompact_only = false);
/// Ensure the build directory exists, creating it if necessary.
/// @return false on error.
@@ -602,6 +603,17 @@ int NinjaMain::ToolCompilationDatabase(int argc, char* argv[]) {
return 0;
}
+int NinjaMain::ToolRecompact(int argc, char* argv[]) {
+ if (!EnsureBuildDirExists())
+ return 1;
+
+ if (!OpenBuildLog(/*recompact_only=*/true) ||
+ !OpenDepsLog(/*recompact_only=*/true))
+ return 1;
+
+ return 0;
+}
+
int NinjaMain::ToolUrtle(int argc, char** argv) {
// RLE encoded.
const char* urtle =
@@ -652,6 +664,8 @@ const Tool* ChooseTool(const string& tool_name) {
Tool::RUN_AFTER_LOAD, &NinjaMain::ToolTargets },
{ "compdb", "dump JSON compilation database to stdout",
Tool::RUN_AFTER_LOAD, &NinjaMain::ToolCompilationDatabase },
+ { "recompact", "recompacts ninja-internal data structures",
+ Tool::RUN_AFTER_LOAD, &NinjaMain::ToolRecompact },
{ "urtle", NULL,
Tool::RUN_AFTER_FLAGS, &NinjaMain::ToolUrtle },
{ NULL, NULL, Tool::RUN_AFTER_FLAGS, NULL }
@@ -712,7 +726,7 @@ bool DebugEnable(const string& name) {
}
}
-bool NinjaMain::OpenBuildLog() {
+bool NinjaMain::OpenBuildLog(bool recompact_only) {
string log_path = ".ninja_log";
if (!build_dir_.empty())
log_path = build_dir_ + "/" + log_path;
@@ -728,6 +742,13 @@ bool NinjaMain::OpenBuildLog() {
err.clear();
}
+ if (recompact_only) {
+ bool success = build_log_.Recompact(log_path, &err);
+ if (!success)
+ Error("failed recompaction: %s", err.c_str());
+ return success;
+ }
+
if (!config_.dry_run) {
if (!build_log_.OpenForWrite(log_path, &err)) {
Error("opening build log: %s", err.c_str());
@@ -740,7 +761,7 @@ bool NinjaMain::OpenBuildLog() {
/// Open the deps log: load it, then open for writing.
/// @return false on error.
-bool NinjaMain::OpenDepsLog() {
+bool NinjaMain::OpenDepsLog(bool recompact_only) {
string path = ".ninja_deps";
if (!build_dir_.empty())
path = build_dir_ + "/" + path;
@@ -756,6 +777,13 @@ bool NinjaMain::OpenDepsLog() {
err.clear();
}
+ if (recompact_only) {
+ bool success = deps_log_.Recompact(path, &err);
+ if (!success)
+ Error("failed recompaction: %s", err.c_str());
+ return success;
+ }
+
if (!config_.dry_run) {
if (!deps_log_.OpenForWrite(path, &err)) {
Error("opening deps log: %s", err.c_str());