diff options
author | Frank Busse <bb0xfb@gmail.com> | 2019-08-07 20:57:27 +0100 |
---|---|---|
committer | Cristian Cadar <c.cadar@imperial.ac.uk> | 2019-08-12 10:22:51 +0100 |
commit | 64508909bcbd52d6a06ec0f299b3752368d10e31 (patch) | |
tree | 1dcfa493da33d61f1007265e7ac0876047c7a090 | |
parent | f9aa2a3534ac47e07cd1f8b21bafb784b7a0c6c6 (diff) | |
download | klee-64508909bcbd52d6a06ec0f299b3752368d10e31.tar.gz |
StatsTracker: switch from TRUNCATE to WAL journal mode
-rw-r--r-- | lib/Core/StatsTracker.cpp | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp index 152047dc..408e4d6d 100644 --- a/lib/Core/StatsTracker.cpp +++ b/lib/Core/StatsTracker.cpp @@ -253,47 +253,51 @@ StatsTracker::StatsTracker(Executor &_executor, std::string _objectFilename, } if (OutputStats) { - auto db_filename = executor.interpreterHandler->getOutputFilename("run.stats"); - if (sqlite3_open(db_filename.c_str(), &statsFile) == SQLITE_OK) { - // prepare statements - if(sqlite3_prepare_v2(statsFile, "BEGIN TRANSACTION", -1, &transactionBeginStmt, nullptr) != SQLITE_OK) { - klee_error("Cannot create prepared statement: %s", sqlite3_errmsg(statsFile)); - } + sqlite3_config(SQLITE_CONFIG_SINGLETHREAD); + sqlite3_enable_shared_cache(0); - if(sqlite3_prepare_v2(statsFile, "END TRANSACTION", -1, &transactionEndStmt, nullptr) != SQLITE_OK) { - klee_error("Cannot create prepared statement: %s", sqlite3_errmsg(statsFile)); - } + // open database + auto db_filename = executor.interpreterHandler->getOutputFilename("run.stats"); + if (sqlite3_open(db_filename.c_str(), &statsFile) != SQLITE_OK) { + std::ostringstream errorstream; + errorstream << "Can't open database: " << sqlite3_errmsg(statsFile); + sqlite3_close(statsFile); + klee_error("%s", errorstream.str().c_str()); + } - // set options - char *zErrMsg; - if (sqlite3_exec(statsFile, "PRAGMA synchronous = OFF", nullptr, nullptr, &zErrMsg) != SQLITE_OK) { - klee_error("%s", sqlite3ErrToStringAndFree("Can't set options for database: ", zErrMsg).c_str()); - } + // prepare statements + if (sqlite3_prepare_v2(statsFile, "BEGIN TRANSACTION", -1, &transactionBeginStmt, nullptr) != SQLITE_OK) { + klee_error("Cannot create prepared statement: %s", sqlite3_errmsg(statsFile)); + } - // note: we use TRUNCATE here a) for speed and b) to prevent creation of new file descriptors - if (sqlite3_exec(statsFile, "PRAGMA journal_mode = TRUNCATE", nullptr, nullptr, &zErrMsg) != SQLITE_OK) { - klee_error("%s", sqlite3ErrToStringAndFree("Can't set options for database: ", zErrMsg).c_str()); - } + if (sqlite3_prepare_v2(statsFile, "END TRANSACTION", -1, &transactionEndStmt, nullptr) != SQLITE_OK) { + klee_error("Cannot create prepared statement: %s", sqlite3_errmsg(statsFile)); + } - // begin transaction - auto rc = sqlite3_step(transactionBeginStmt); - if (rc != SQLITE_DONE) { - klee_warning("Can't begin transaction: %s", sqlite3_errmsg(statsFile)); - } - sqlite3_reset(transactionBeginStmt); + // set options + char *zErrMsg; + if (sqlite3_exec(statsFile, "PRAGMA synchronous = OFF", nullptr, nullptr, &zErrMsg) != SQLITE_OK) { + klee_error("%s", sqlite3ErrToStringAndFree("Can't set options for database: ", zErrMsg).c_str()); + } - // create table - writeStatsHeader(); - writeStatsLine(); + // note: we use WAL here a) for speed and b) to prevent creation of new file descriptors (as with TRUNCATE) + if (sqlite3_exec(statsFile, "PRAGMA journal_mode = WAL", nullptr, nullptr, &zErrMsg) != SQLITE_OK) { + klee_error("%s", sqlite3ErrToStringAndFree("Can't set options for database: ", zErrMsg).c_str()); + } - if (statsWriteInterval) - executor.addTimer(new WriteStatsTimer(this), statsWriteInterval); - } else { - std::ostringstream errorstream; - errorstream << "Can't open database: " << sqlite3_errmsg(statsFile); - sqlite3_close(statsFile); - klee_error("%s", errorstream.str().c_str()); + // begin transaction + auto rc = sqlite3_step(transactionBeginStmt); + if (rc != SQLITE_DONE) { + klee_warning("Can't begin transaction: %s", sqlite3_errmsg(statsFile)); } + sqlite3_reset(transactionBeginStmt); + + // create table + writeStatsHeader(); + writeStatsLine(); + + if (statsWriteInterval) + executor.addTimer(new WriteStatsTimer(this), statsWriteInterval); } // Add timer to calculate uncovered instructions if needed by the solver |