portfolio: add stat to track time spent waiting for interrupted threads to stop
authorKshitij Bansal <kshitij@cs.nyu.edu>
Thu, 20 Feb 2014 13:57:39 +0000 (08:57 -0500)
committerKshitij Bansal <kshitij@cs.nyu.edu>
Thu, 20 Feb 2014 13:57:39 +0000 (08:57 -0500)
src/main/command_executor_portfolio.cpp
src/main/command_executor_portfolio.h
src/main/portfolio.cpp
src/main/portfolio.h
src/util/statistics_registry.cpp
src/util/statistics_registry.h

index 24469c6683b100e835fd669472ceea6c22f06060..7392b2b628a6924c4c691f35dbf4ca58741951c8 100644 (file)
@@ -47,12 +47,14 @@ CommandExecutorPortfolio::CommandExecutorPortfolio
   d_channelsOut(),
   d_channelsIn(),
   d_ostringstreams(),
-  d_statLastWinner("portfolio::lastWinner")
+  d_statLastWinner("portfolio::lastWinner"),
+  d_statWaitTime("portfolio::waitTime")
 {
   assert(d_threadOptions.size() == d_numThreads);
 
   d_statLastWinner.setData(d_lastWinner);
   d_stats.registerStat_(&d_statLastWinner);
+  d_stats.registerStat_(&d_statWaitTime);
 
   /* Duplication, Individualisation */
   d_exprMgrs.push_back(&d_exprMgr);
@@ -86,6 +88,9 @@ CommandExecutorPortfolio::~CommandExecutorPortfolio()
   }
   d_exprMgrs.clear();
   d_smts.clear();
+
+  d_stats.unregisterStat_(&d_statLastWinner);
+  d_stats.unregisterStat_(&d_statWaitTime);
 }
 
 void CommandExecutorPortfolio::lemmaSharingInit()
@@ -283,6 +288,8 @@ bool CommandExecutorPortfolio::doCommandSingleton(Command* cmd)
     assert(d_channelsOut.size() == d_numThreads
            || d_numThreads == 1);
     assert(d_smts.size() == d_numThreads);
+    assert( !d_statWaitTime.running() );
+
     boost::function<void()>
       smFn = d_numThreads <= 1 ? boost::function<void()>() :
              boost::bind(sharingManager<ChannelFormat>,
@@ -293,7 +300,10 @@ bool CommandExecutorPortfolio::doCommandSingleton(Command* cmd)
 
     pair<int, bool> portfolioReturn =
         runPortfolio(d_numThreads, smFn, fns,
-                     d_options[options::waitToJoin]);
+                     d_options[options::waitToJoin], d_statWaitTime);
+
+    assert( d_statWaitTime.running() );
+    d_statWaitTime.stop();
 
     delete d_seq;
     d_seq = new CommandSequence();
index a8d4a421350ca0d6a56f365bfe66c1e8511b1013..91f9a5169d43eedc6c847b0cb9a5e2248f3dd9bf 100644 (file)
@@ -52,6 +52,7 @@ class CommandExecutorPortfolio : public CommandExecutor {
 
   // Stats
   ReferenceStat<int> d_statLastWinner;
+  TimerStat d_statWaitTime;
 
 public:
   CommandExecutorPortfolio(ExprManager &exprMgr,
index 21c1b60a3b22331a06fb364fdfe6475d30c36b57..ebf36b0cdc1ef0bf48b1376dd98a6814a7fee09c 100644 (file)
 
 #include "smt/smt_engine.h"
 #include "util/result.h"
+#include "util/statistics_registry.h"
 #include "options/options.h"
 
+
 namespace CVC4 {
 
 /** Mutex to make sure at most one thread is winner */
@@ -60,7 +62,8 @@ template<typename T, typename S>
 std::pair<int, S> runPortfolio(int numThreads,
                                boost::function<T()> driverFn,
                                boost::function<S()> threadFns[],
-                               bool optionWaitToJoin) {
+                               bool optionWaitToJoin,
+                               TimerStat& statWaitTime) {
   boost::thread thread_driver;
   boost::thread* threads = new boost::thread[numThreads];
   S* threads_returnValue = new S[numThreads];
@@ -82,6 +85,8 @@ std::pair<int, S> runPortfolio(int numThreads,
     condition_var_main_wait.wait(lock);
   }
 
+  statWaitTime.start();
+
   if(not driverFn.empty()) {
     thread_driver.interrupt();
     thread_driver.join();
@@ -107,6 +112,7 @@ std::pair<int, bool>
 runPortfolio<void, bool>(int,
                          boost::function<void()>, 
                          boost::function<bool()>*,
-                         bool);
+                         bool,
+                         TimerStat&);
 
 }/* CVC4 namespace */
index 61a4c055f7c3f86c09fa00df772b41a1ed08bc4c..c2d313a4471c61ead1af1ec4c6bcc080ebb03b46 100644 (file)
 #include "smt/smt_engine.h"
 #include "expr/command.h"
 #include "options/options.h"
+#include "util/statistics_registry.h"
 
 namespace CVC4 {
 
 template<typename T, typename S>
 std::pair<int, S> runPortfolio(int numThreads, 
-                              boost::function<T()> driverFn,
-                              boost::function<S()> threadFns[],
-                              bool optionWaitToJoin);
+                               boost::function<T()> driverFn,
+                               boost::function<S()> threadFns[],
+                               bool optionWaitToJoin,
+                               TimerStat& statWaitTime);
 // as we have defined things, S=void would give compile errors
 // do we want to fix this? yes, no, maybe?
 
index 67cc3a53cfc84d48c2a46255a3f2387a59da854b..61762b84d535766b41255347e85bd0aef8dffb8b 100644 (file)
@@ -119,6 +119,10 @@ void TimerStat::stop() {
   }
 }/* TimerStat::stop() */
 
+bool TimerStat::running() const {
+  return d_running;
+}/* TimerStat::running() */
+
 timespec TimerStat::getData() const {
   ::timespec data = d_data;
   if(__CVC4_USE_STATISTICS && d_running) {
index eb5245e2588055146afd33f58a145d072be97d46..bd33557d9d9e74b42ab1b78452320530b34a5d8e 100644 (file)
@@ -808,6 +808,9 @@ public:
    */
   void stop();
 
+  /** If the timer is currently running */
+  bool running() const;
+
   timespec getData() const;
 
   SExpr getValue() const;