From 20eb0485850073fafdac07a630cededf8b99c536 Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Wed, 23 Mar 2016 21:48:12 +0100 Subject: Refactoring of conditional flush into own function. @delcypher: Thanks a lot Dan! --- lib/Solver/QueryLoggingSolver.cpp | 24 ++++++++++++++---------- lib/Solver/QueryLoggingSolver.h | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/Solver/QueryLoggingSolver.cpp b/lib/Solver/QueryLoggingSolver.cpp index 6084e2e1..f93bec3c 100644 --- a/lib/Solver/QueryLoggingSolver.cpp +++ b/lib/Solver/QueryLoggingSolver.cpp @@ -39,6 +39,16 @@ QueryLoggingSolver::QueryLoggingSolver(Solver *_solver, std::string path, QueryLoggingSolver::~QueryLoggingSolver() { delete solver; } +void QueryLoggingSolver::flushBufferConditionally(bool writeToFile) { + logBuffer.flush(); + if (writeToFile) { + os << logBuffer.str(); + os.flush(); + } + // prepare the buffer for reuse + BufferString = ""; +} + void QueryLoggingSolver::startQuery(const Query &query, const char *typeName, const Query *falseQuery, const std::vector *objects) { @@ -52,11 +62,7 @@ void QueryLoggingSolver::startQuery(const Query &query, const char *typeName, printQuery(query, falseQuery, objects); if (DumpPartialQueryiesEarly) { - logBuffer.flush(); - os << logBuffer.str(); - os.flush(); - // prepare the buffer for reuse - BufferString = ""; + flushBufferConditionally(true); } startTime = getWallTime(); } @@ -74,7 +80,7 @@ void QueryLoggingSolver::finishQuery(bool success) { } void QueryLoggingSolver::flushBuffer() { - logBuffer.flush(); + bool writeToFile = false; if ((0 == minQueryTimeToLog) || (static_cast(lastQueryTime * 1000) > minQueryTimeToLog)) { @@ -86,13 +92,11 @@ void QueryLoggingSolver::flushBuffer() { (solver->impl->getOperationStatusCode()))) { // we do additional check here to log only timeouts in case // user specified negative value for minQueryTimeToLog param - os << logBuffer.str(); - os.flush(); + writeToFile = true; } } - // prepare the buffer for reuse - BufferString = ""; + flushBufferConditionally(writeToFile); } bool QueryLoggingSolver::computeTruth(const Query &query, bool &isValid) { diff --git a/lib/Solver/QueryLoggingSolver.h b/lib/Solver/QueryLoggingSolver.h index 3068f2ab..bb266c67 100644 --- a/lib/Solver/QueryLoggingSolver.h +++ b/lib/Solver/QueryLoggingSolver.h @@ -55,6 +55,7 @@ protected: virtual void printQuery(const Query &query, const Query *falseQuery = 0, const std::vector *objects = 0) = 0; + void flushBufferConditionally(bool writeToFile); public: QueryLoggingSolver(Solver *_solver, std::string path, -- cgit 1.4.1