Skip to content

Commit b715ac1

Browse files
committed
Convert boost timer to std impl
1 parent 8c45c4a commit b715ac1

File tree

8 files changed

+43
-21
lines changed

8 files changed

+43
-21
lines changed

Superbuild/BoostExternal.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ SET(boost_Libraries
5454
"serialization"
5555
"system"
5656
"thread"
57-
"timer"
5857
CACHE INTERNAL "Boost library name.")
5958

6059
IF(BUILD_WITH_PYTHON)

src/Core/Logging/Logger.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,24 @@ using namespace SCIRun::Core::Logging;
3737

3838
LegacyLoggerInterface::~LegacyLoggerInterface() {}
3939

40+
SimpleScopedTimer::SimpleScopedTimer() : start_(std::chrono::steady_clock::now())
41+
{
42+
}
43+
44+
double SimpleScopedTimer::elapsedSeconds() const
45+
{
46+
const auto end = std::chrono::steady_clock::now();
47+
const std::chrono::duration<double> elapsedSeconds = end - start_;
48+
return elapsedSeconds.count();
49+
}
50+
4051
ScopedTimeRemarker::ScopedTimeRemarker(LegacyLoggerInterface* log, const std::string& label) : log_(log), label_(label)
4152
{}
4253

4354
ScopedTimeRemarker::~ScopedTimeRemarker()
4455
{
4556
std::ostringstream perf;
46-
perf << label_ << " took " << timer_.elapsed().wall << " seconds." << std::endl;
57+
perf << label_ << " took " << timer_.elapsedSeconds() << " seconds." << std::endl;
4758
log_->status(perf.str());
4859
}
4960

@@ -55,7 +66,7 @@ ScopedTimeLogger::ScopedTimeLogger(const std::string& label, bool shouldLog): la
5566

5667
ScopedTimeLogger::~ScopedTimeLogger()
5768
{
58-
auto time = timer_.elapsed().wall;
69+
auto time = timer_.elapsedSeconds();
5970
if (shouldLog_)
6071
LOG_DEBUG("{} took {} seconds.", label_, time);
6172
}

src/Core/Logging/ScopedTimeRemarker.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define CORE_LOGGING_SCOPEDTIMEREMARKER_H
3333

3434
#include <string>
35-
#include <boost/timer/timer.hpp>
35+
#include <chrono>
3636
#include <Core/Logging/LoggerFwd.h>
3737
#include <Core/Logging/share.h>
3838

@@ -42,6 +42,17 @@ namespace SCIRun
4242
{
4343
namespace Logging
4444
{
45+
class SCISHARE SimpleScopedTimer
46+
{
47+
public:
48+
SimpleScopedTimer();
49+
SimpleScopedTimer(const SimpleScopedTimer&) = delete;
50+
SimpleScopedTimer& operator=(const SimpleScopedTimer&) = delete;
51+
double elapsedSeconds() const;
52+
private:
53+
const std::chrono::time_point<std::chrono::steady_clock> start_;
54+
};
55+
4556
class SCISHARE ScopedTimeRemarker
4657
{
4758
public:
@@ -50,7 +61,7 @@ namespace SCIRun
5061
private:
5162
LegacyLoggerInterface* log_;
5263
std::string label_;
53-
boost::timer::cpu_timer timer_;
64+
SimpleScopedTimer timer_;
5465
};
5566

5667
class SCISHARE ScopedTimeLogger
@@ -61,7 +72,7 @@ namespace SCIRun
6172
private:
6273
std::string label_;
6374
bool shouldLog_;
64-
boost::timer::cpu_timer timer_;
75+
SimpleScopedTimer timer_;
6576
};
6677
}
6778
}

src/Interface/Application/ModuleWidget.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ bool ModuleWidget::executeWithSignals()
10971097
Q_EMIT signalExecuteButtonIconChangeToStop();
10981098
errored_ = false;
10991099
//colorLocked_ = true; //TODO
1100-
timer_.start();
1100+
timer_ = std::make_unique<SimpleScopedTimer>();
11011101
theModule_->executeWithSignals();
11021102
if (!disabled_)
11031103
Q_EMIT updateProgressBarSignal(1);
@@ -1350,7 +1350,7 @@ void ModuleWidget::updateProgressBar(double percent)
13501350

13511351
void ModuleWidget::updateModuleTime()
13521352
{
1353-
fullWidgetDisplay_->getProgressBar()->setFormat(QString("%1 s : %p%").arg(timer_.elapsed().wall));
1353+
fullWidgetDisplay_->getProgressBar()->setFormat(QString("%1 s : %p%").arg(timer_->elapsedSeconds()));
13541354
}
13551355

13561356
void ModuleWidget::launchDocumentation()

src/Interface/Application/ModuleWidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
#include <boost/shared_ptr.hpp>
3535
#include <boost/scoped_ptr.hpp>
3636
#include <boost/bimap.hpp>
37-
#include <boost/timer/timer.hpp>
3837
#include <deque>
3938
#include <atomic>
4039
#include <Interface/Application/Note.h>
4140
#include <Interface/Application/HasNotes.h>
41+
#include <Core/Logging/ScopedTimeRemarker.h>
4242

4343
#include <Dataflow/Network/NetworkFwd.h>
4444
#include <Dataflow/Network/ExecutableObject.h>
@@ -260,7 +260,7 @@ private Q_SLOTS:
260260
ModuleWidgetDisplayPtr fullWidgetDisplay_;
261261
private:
262262
boost::shared_ptr<PortWidgetManager> ports_;
263-
boost::timer::cpu_timer timer_;
263+
std::unique_ptr<Core::Logging::SimpleScopedTimer> timer_;
264264
bool deletedFromGui_, colorLocked_;
265265
bool executedOnce_, skipExecuteDueToFatalError_, disabled_, programmablePortEnabled_{false};
266266
std::atomic<bool> errored_;

src/Interface/Application/NetworkExecutionProgressBar.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ void NetworkExecutionProgressBar::incrementModulesDone(double execTime, const st
9393
counterLabel_->setText(counterLabelString());
9494
progressBar_->setValue(numModulesDone_);
9595
totalExecutionTime_ += execTime;
96-
auto wallTime = executionTimer_.elapsed().wall;
9796
//Green - completed modules\n??? - Unexecuted modules\nRed - errored modules\n
98-
progressBar_->setToolTip(QString("Total execution time: %1\nTotal wall time: %2")
99-
.arg(totalExecutionTime_).arg(wallTime));
97+
progressBar_->setToolTip(QString("Total execution time: %1\nTotal wall time: TODO")
98+
.arg(totalExecutionTime_));// .arg(wallTime));
10099
timingStream_ << '\t' << moduleId.c_str() << "," << execTime << ',' << totalExecutionTime_
101-
<< ',' << wallTime << '\n';
100+
// << ',' << wallTime
101+
<< '\n';
102102

103103
if (numModulesDone_ == totalModules_)
104104
timingStream_ << "TIMING LOG: " << "execution ended at " << QTime::currentTime().toString("hh:mm:ss.zzz") << '\n';
@@ -110,7 +110,7 @@ void NetworkExecutionProgressBar::resetModulesDone()
110110
Guard g(mutex_.get());
111111
numModulesDone_ = 0;
112112
totalExecutionTime_ = 0;
113-
executionTimer_.stop();
113+
//executionTimer_.reset();
114114
counterLabel_->setText(counterLabelString());
115115
progressBar_->setValue(numModulesDone_);
116116
progressBar_->setToolTip("");

src/Interface/Application/NetworkExecutionProgressBar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#include <QTextStream>
3434
#include <QProgressBar>
3535
#ifndef Q_MOC_RUN
36+
#include <Core/Logging/ScopedTimeRemarker.h>
3637
#include <Core/Utils/SmartPointers.h>
37-
#include <boost/timer/timer.hpp>
3838
#include <Core/Thread/Mutex.h>
3939
#endif
4040

@@ -98,7 +98,7 @@ class NetworkExecutionProgressBar : public QObject
9898
size_t totalModules_;
9999
double totalExecutionTime_;
100100
Core::Thread::Mutex mutex_;
101-
boost::timer::cpu_timer executionTimer_;
101+
//std::unique_ptr<Core::Logging::SimpleScopedTimer> executionTimer_;
102102
QString timingLog_;
103103
QTextStream timingStream_;
104104

src/Testing/Utils/MatrixTestUtilities.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <gtest/gtest.h>
3333
#include <boost/test/tools/floating_point_comparison.hpp>
3434
#include <boost/tuple/tuple.hpp>
35-
#include <boost/timer/timer.hpp>
3635
#include <boost/assign.hpp>
3736
#include <boost/filesystem.hpp>
3837
#include <stdexcept>
@@ -41,9 +40,12 @@
4140
#include <Core/Datatypes/DenseColumnMatrix.h>
4241
#include <Core/Datatypes/SparseRowMatrix.h>
4342
#include <Core/Utils/StringUtil.h>
43+
#include <Core/Logging/ScopedTimeRemarker.h>
4444

4545
#include <Testing/Utils/share.h>
4646

47+
48+
4749
namespace SCIRun
4850
{
4951

@@ -214,17 +216,16 @@ struct SCISHARE ScopedTimer
214216
explicit ScopedTimer(const std::string& name) : name_(name)
215217
{
216218
std::cout << "Starting timer " << name_ << std::endl;
217-
//t_.start();
218219
}
219220

220221
~ScopedTimer()
221222
{
222-
auto elapsed = t_.elapsed().wall;
223+
const auto elapsed = t_.elapsedSeconds();
223224
std::cout << "Timer " << name_ << " stopped at " << elapsed << " seconds." << std::endl;
224225
}
225226

226227
std::string name_;
227-
boost::timer::cpu_timer t_;
228+
Core::Logging::SimpleScopedTimer t_;
228229
};
229230

230231
// TODO: move to Field utils file

0 commit comments

Comments
 (0)