This PR does some refactoring on how we handle statistics in the driver, and some minor cleanup along the way.
The SmtEngine now has dedicated statistics for the data collected within the driver and provides utility functions to set them.
The driver pushes the collected statistics to the SmtEngine instead of adding them itself to the statistics registry.
The node manager no longer holds a statistics registry (that nobody used anymore anyway)
The command executor no longer holds a pointer to the SmtEngine itself. The pointer is not necessary and seems to become stale after we call reset on the command executor (which, luckily, we don't seem to do usually)
The main motivation for this change is to make the whole statistics infrastructure private to the library and not exporting it to the outside world.
d_rng.reset(new Random(o[options::seed]));
#if CVC4_STATISTICS_ON
d_stats.reset(new Statistics());
- d_nodeMgr->getStatisticsRegistry()->registerStat(&d_stats->d_consts);
- d_nodeMgr->getStatisticsRegistry()->registerStat(&d_stats->d_vars);
- d_nodeMgr->getStatisticsRegistry()->registerStat(&d_stats->d_terms);
+ d_smtEngine->getStatisticsRegistry()->registerStat(&d_stats->d_consts);
+ d_smtEngine->getStatisticsRegistry()->registerStat(&d_stats->d_vars);
+ d_smtEngine->getStatisticsRegistry()->registerStat(&d_stats->d_terms);
#endif
}
/** The node manager of this solver. */
std::unique_ptr<NodeManager> d_nodeMgr;
+ /** The statistics collected on the Api level. */
+ std::unique_ptr<Statistics> d_stats;
/** The SMT engine of this solver. */
std::unique_ptr<SmtEngine> d_smtEngine;
/** The random number generator of this solver. */
std::unique_ptr<Random> d_rng;
- /** The statistics collected on the Api level. */
- std::unique_ptr<Statistics> d_stats;
};
} // namespace api
#include "expr/node_manager.h"
#include <algorithm>
+#include <sstream>
#include <stack>
#include <utility>
#include "expr/skolem_manager.h"
#include "expr/type_checker.h"
#include "util/resource_manager.h"
-#include "util/statistics_registry.h"
using namespace std;
using namespace CVC4::expr;
typedef expr::Attribute<attr::LambdaBoundVarListTag, Node> LambdaBoundVarListAttr;
NodeManager::NodeManager()
- : d_statisticsRegistry(new StatisticsRegistry()),
- d_skManager(new SkolemManager),
+ : d_skManager(new SkolemManager),
d_bvManager(new BoundVarManager),
next_id(0),
d_attrManager(new expr::attr::AttributeManager()),
}
// defensive coding, in case destruction-order issues pop up (they often do)
- delete d_statisticsRegistry;
- d_statisticsRegistry = NULL;
delete d_attrManager;
d_attrManager = NULL;
}
class Solver;
}
-class StatisticsRegistry;
class ResourceManager;
class SkolemManager;
class BoundVarManager;
static thread_local NodeManager* s_current;
- StatisticsRegistry* d_statisticsRegistry;
-
/** The skolem manager */
std::unique_ptr<SkolemManager> d_skManager;
/** The bound variable manager */
/** Get this node manager's bound variable manager */
BoundVarManager* getBoundVarManager() { return d_bvManager.get(); }
- /** Get this node manager's statistics registry */
- StatisticsRegistry* getStatisticsRegistry() const
- {
- return d_statisticsRegistry;
- }
-
/** Subscribe to NodeManager events */
void subscribeEvents(NodeManagerListener* listener) {
Assert(std::find(d_listeners.begin(), d_listeners.end(), listener)
CommandExecutor::CommandExecutor(Options& options)
: d_solver(new api::Solver(&options)),
d_symman(new SymbolManager(d_solver.get())),
- d_smtEngine(d_solver->getSmtEngine()),
d_options(options),
- d_stats(),
d_result()
{
}
void CommandExecutor::flushStatistics(std::ostream& out) const
{
// SmtEngine + node manager flush statistics is part of the call below
- d_smtEngine->flushStatistics(out);
- d_stats.flushInformation(out);
+ getSmtEngine()->flushStatistics(out);
}
void CommandExecutor::safeFlushStatistics(int fd) const
{
// SmtEngine + node manager flush statistics is part of the call below
- d_smtEngine->safeFlushStatistics(fd);
- d_stats.safeFlushInformation(fd);
+ getSmtEngine()->safeFlushStatistics(fd);
}
bool CommandExecutor::doCommand(Command* cmd)
* symbol manager.
*/
std::unique_ptr<SymbolManager> d_symman;
- SmtEngine* d_smtEngine;
Options& d_options;
- StatisticsRegistry d_stats;
api::Result d_result;
public:
api::Result getResult() const { return d_result; }
void reset();
- StatisticsRegistry& getStatisticsRegistry() {
- return d_stats;
- }
-
- SmtEngine* getSmtEngine() { return d_smtEngine; }
+ SmtEngine* getSmtEngine() const { return d_solver->getSmtEngine(); }
/**
* Flushes statistics to a file descriptor.
#include <stdio.h>
#include <unistd.h>
+#include <chrono>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include "parser/parser_builder.h"
#include "smt/command.h"
#include "util/result.h"
-#include "util/statistics_registry.h"
using namespace std;
using namespace CVC4;
/** A pointer to the CommandExecutor (the signal handlers need it) */
CVC4::main::CommandExecutor* pExecutor = nullptr;
- /** A pointer to the totalTime driver stat (the signal handlers need it) */
- CVC4::TimerStat* pTotalTime = nullptr;
-
}/* CVC4::main namespace */
}/* CVC4 namespace */
int runCvc4(int argc, char* argv[], Options& opts) {
- // Timer statistic
- pTotalTime = new TimerStat("driver::totalTime");
- pTotalTime->start();
-
+ std::chrono::time_point totalTimeStart = std::chrono::steady_clock::now();
// For the signal handlers' benefit
pOptions = &opts;
int returnValue = 0;
{
- // Timer statistic
- RegisterStatistic statTotalTime(&pExecutor->getStatisticsRegistry(),
- pTotalTime);
-
- // Filename statistics
- ReferenceStat<std::string> s_statFilename("driver::filename", filenameStr);
- RegisterStatistic statFilenameReg(&pExecutor->getStatisticsRegistry(),
- &s_statFilename);
// notify SmtEngine that we are starting to parse
pExecutor->getSmtEngine()->notifyStartParsing(filenameStr);
// or other on_exit/atexit stuff.
_exit(returnValue);
#endif /* CVC4_COMPETITION_MODE */
+ pExecutor->getSmtEngine()->setResultStatistic(result.toString());
+ std::chrono::duration totalTime = std::chrono::steady_clock::now() - totalTimeStart;
+ pExecutor->getSmtEngine()->setTotalTimeStatistic(std::chrono::duration<double>(totalTime).count());
- ReferenceStat<api::Result> s_statSatResult("driver::sat/unsat", result);
- RegisterStatistic statSatResultReg(&pExecutor->getStatisticsRegistry(),
- &s_statSatResult);
-
- pTotalTime->stop();
-
- // Tim: I think that following comment is out of date?
- // Set the global executor pointer to nullptr first. If we get a
- // signal while dumping statistics, we don't want to try again.
pExecutor->flushOutputStreams();
#ifdef CVC4_DEBUG
#endif /* CVC4_DEBUG */
}
- // On exceptional exit, these are leaked, but that's okay... they
- // need to be around in that case for main() to print statistics.
- delete pTotalTime;
delete pExecutor;
- pTotalTime = nullptr;
pExecutor = nullptr;
signal_handlers::cleanup();
#include "parser/parser_builder.h"
#include "parser/parser_exception.h"
#include "util/result.h"
-#include "util/statistics.h"
using namespace std;
using namespace CVC4;
*opts.getErr() << "(error \"" << e << "\")" << endl;
}
if(opts.getStatistics() && pExecutor != NULL) {
- pTotalTime->stop();
pExecutor->flushStatistics(*opts.getErr());
}
}
#include "base/exception.h"
#include "cvc4autoconfig.h"
#include "options/options.h"
-#include "util/statistics.h"
-#include "util/statistics_registry.h"
-#include "util/stats_timer.h"
#ifndef CVC4__MAIN__MAIN_H
#define CVC4__MAIN__MAIN_H
/** A reference for use by the signal handlers to print statistics */
extern CVC4::main::CommandExecutor* pExecutor;
-/** A reference for use by the signal handlers to print statistics */
-extern CVC4::TimerStat* pTotalTime;
-
/**
* If true, will not spin on segfault even when CVC4_DEBUG is on.
* Useful for nightly regressions, noninteractive performance runs
#include "options/options.h"
#include "smt/smt_engine.h"
#include "util/safe_print.h"
-#include "util/statistics.h"
using CVC4::Exception;
using namespace std;
{
if (pOptions != NULL && pOptions->getStatistics() && pExecutor != NULL)
{
- if (pTotalTime != NULL && pTotalTime->running())
- {
- pTotalTime->stop();
- }
pExecutor->safeFlushStatistics(STDERR_FILENO);
}
}
return res;
}
-void SmtEngine::notifyStartParsing(std::string filename)
+void SmtEngine::notifyStartParsing(const std::string& filename)
{
d_state->setFilename(filename);
+ d_stats->d_driverFilename.set(filename);
// Copy the original options. This is called prior to beginning parsing.
// Hence reset should revert to these options, which note is after reading
// the command line.
{
return d_state->getFilename();
}
+
+void SmtEngine::setResultStatistic(const std::string& result) {
+ d_stats->d_driverResult.set(result);
+}
+
+void SmtEngine::setTotalTimeStatistic(double seconds) {
+ d_stats->d_driverTotalTime.set(seconds);
+}
+
void SmtEngine::setLogicInternal()
{
Assert(!d_state->isFullyInited())
if (key == "all-statistics")
{
vector<SExpr> stats;
- StatisticsRegistry* sr = getNodeManager()->getStatisticsRegistry();
- for (StatisticsRegistry::const_iterator i = sr->begin(); i != sr->end();
- ++i)
- {
- vector<SExpr> v;
- v.push_back((*i).first);
- v.push_back((*i).second);
- stats.push_back(v);
- }
for (StatisticsRegistry::const_iterator i = d_env->getStatisticsRegistry()->begin();
i != d_env->getStatisticsRegistry()->end();
++i)
void SmtEngine::flushStatistics(std::ostream& out) const
{
- getNodeManager()->getStatisticsRegistry()->flushInformation(out);
d_env->getStatisticsRegistry()->flushInformation(out);
}
void SmtEngine::safeFlushStatistics(int fd) const
{
- getNodeManager()->getStatisticsRegistry()->safeFlushInformation(fd);
d_env->getStatisticsRegistry()->safeFlushInformation(fd);
}
* to a state where its options were prior to parsing but after e.g.
* reading command line options.
*/
- void notifyStartParsing(std::string filename) CVC4_EXPORT;
+ void notifyStartParsing(const std::string& filename) CVC4_EXPORT;
/** return the input name (if any) */
const std::string& getFilename() const;
+ /**
+ * Helper method for the API to put the last check result into the statistics.
+ */
+ void setResultStatistic(const std::string& result) CVC4_EXPORT;
+ /**
+ * Helper method for the API to put the total runtime into the statistics.
+ */
+ void setTotalTimeStatistic(double seconds) CVC4_EXPORT;
+
/**
* Get the model (only if immediately preceded by a SAT or NOT_ENTAILED
* query). Only permitted if produce-models is on.
d_solveTime("smt::SmtEngine::solveTime"),
d_pushPopTime("smt::SmtEngine::pushPopTime"),
d_processAssertionsTime("smt::SmtEngine::processAssertionsTime"),
- d_simplifiedToFalse("smt::SmtEngine::simplifiedToFalse", 0)
+ d_simplifiedToFalse("smt::SmtEngine::simplifiedToFalse", 0),
+ d_driverFilename("driver::filename", ""),
+ d_driverResult("driver::sat/unsat", ""),
+ d_driverTotalTime("driver::totalTime", 0.0)
{
smtStatisticsRegistry()->registerStat(&d_definitionExpansionTime);
smtStatisticsRegistry()->registerStat(&d_numConstantProps);
smtStatisticsRegistry()->registerStat(&d_pushPopTime);
smtStatisticsRegistry()->registerStat(&d_processAssertionsTime);
smtStatisticsRegistry()->registerStat(&d_simplifiedToFalse);
+ smtStatisticsRegistry()->registerStat(&d_driverFilename);
+ smtStatisticsRegistry()->registerStat(&d_driverResult);
+ smtStatisticsRegistry()->registerStat(&d_driverTotalTime);
}
SmtEngineStatistics::~SmtEngineStatistics()
smtStatisticsRegistry()->unregisterStat(&d_pushPopTime);
smtStatisticsRegistry()->unregisterStat(&d_processAssertionsTime);
smtStatisticsRegistry()->unregisterStat(&d_simplifiedToFalse);
+ smtStatisticsRegistry()->unregisterStat(&d_driverFilename);
+ smtStatisticsRegistry()->unregisterStat(&d_driverResult);
+ smtStatisticsRegistry()->unregisterStat(&d_driverTotalTime);
}
} // namespace smt
/** Has something simplified to false? */
IntStat d_simplifiedToFalse;
+
+ /** Name of the input file */
+ BackedStat<std::string> d_driverFilename;
+ /** Result of the last check */
+ BackedStat<std::string> d_driverResult;
+ /** Total time of the current run */
+ BackedStat<double> d_driverTotalTime;
}; /* struct SmtEngineStatistics */
} // namespace smt