@@ -38,7 +38,7 @@ namespace {
3838
3939// TODO: this does not include any file context when SHOWTIME_FILE thus rendering it useless - should we include the logging with the progress logging?
4040// that could also get rid of the broader locking
41- void TimerResults::showResults (ShowTime mode, bool metrics, bool format ) const
41+ void TimerResults::showResults (ShowTime mode, bool metrics) const
4242{
4343 if (mode == ShowTime::NONE)
4444 return ;
@@ -60,11 +60,7 @@ void TimerResults::showResults(ShowTime mode, bool metrics, bool format) const
6060 const double sec = iter->second .getSeconds ().count ();
6161 const double secAverage = sec / static_cast <double >(iter->second .mNumberOfResults );
6262 if ((mode != ShowTime::TOP5_FILE && mode != ShowTime::TOP5_SUMMARY) || (ordinal<=5 )) {
63- std::cout << iter->first << " : " ;
64- if (format)
65- std::cout << TimerResultsData::durationToString (iter->second .mDuration );
66- else
67- std::cout << sec << " s" ;
63+ std::cout << iter->first << " : " << sec << " s" ;
6864 if (metrics)
6965 std::cout << " (avg. " << secAverage << " s - " << iter->second .mNumberOfResults << " result(s))" ;
7066 std::cout << std::endl;
@@ -87,10 +83,9 @@ void TimerResults::reset()
8783 mResults .clear ();
8884}
8985
90- Timer::Timer (std::string str, ShowTime showtimeMode, TimerResultsIntf* timerResults, Type type )
86+ Timer::Timer (std::string str, ShowTime showtimeMode, TimerResultsIntf* timerResults)
9187 : mName(std::move(str))
9288 , mMode(showtimeMode)
93- , mType(type)
9489 , mStart(Clock::now())
9590 , mResults(timerResults)
9691{}
@@ -104,14 +99,6 @@ void Timer::stop()
10499{
105100 if (mMode == ShowTime::NONE)
106101 return ;
107- if (mType == Type::OVERALL && mMode != ShowTime::TOP5_SUMMARY && mMode != ShowTime::SUMMARY) {
108- mMode = ShowTime::NONE;
109- return ;
110- }
111- if (mType == Type::FILE && mMode != ShowTime::TOP5_FILE && mMode != ShowTime::FILE && mMode != ShowTime::FILE_TOTAL) {
112- mMode = ShowTime::NONE;
113- return ;
114- }
115102 if (mStart != TimePoint{}) {
116103 if (!mResults ) {
117104 assert (false );
@@ -124,7 +111,7 @@ void Timer::stop()
124111 mMode = ShowTime::NONE; // prevent multiple stops
125112}
126113
127- std::string TimerResultsData:: durationToString (std::chrono::milliseconds duration)
114+ static std::string durationToString (std::chrono::milliseconds duration)
128115{
129116 // Extract hours
130117 auto hours = std::chrono::duration_cast<std::chrono::hours>(duration);
@@ -148,3 +135,22 @@ std::string TimerResultsData::durationToString(std::chrono::milliseconds duratio
148135 secondsStr.resize (pos + 4 ); // keep three decimal
149136 return (ellapsedTime + secondsStr + " s" );
150137}
138+
139+ OneShotTimer::OneShotTimer (std::string name, ShowTime showtime)
140+ {
141+ if (showtime == ShowTime::NONE)
142+ return ;
143+
144+ class MyResults : public TimerResultsIntf
145+ {
146+ private:
147+ void addResults (const std::string &name, std::chrono::milliseconds duration) override
148+ {
149+ // TODO: do not directly use std::cout
150+ std::cout << name << " : " << durationToString (duration) << std::endl;
151+ }
152+ };
153+
154+ mResults .reset (new MyResults);
155+ mTimer .reset (new Timer (std::move (name), showtime, mResults .get ()));
156+ }
0 commit comments