2525#include < utility>
2626#include < vector>
2727
28- constexpr char Timer::OVERALL[];
29-
3028namespace {
3129 using dataElementType = std::pair<std::string, TimerResultsData>;
3230 bool more_second_sec (const dataElementType& lhs, const dataElementType& rhs)
@@ -84,11 +82,12 @@ void TimerResults::reset()
8482 mResults .clear ();
8583}
8684
87- Timer::Timer (std::string str, ShowTime showtimeMode, TimerResultsIntf* timerResults)
88- : mStr(std::move(str))
89- , mTimerResults(timerResults)
90- , mShowTimeMode(showtimeMode)
91- , mStartTimePoint(Clock::now())
85+ Timer::Timer (std::string str, ShowTime showtimeMode, TimerResultsIntf* timerResults, Type type)
86+ : mName(std::move(str))
87+ , mMode(showtimeMode)
88+ , mType(type)
89+ , mStart(Clock::now())
90+ , mResults(timerResults)
9291{}
9392
9493Timer::~Timer ()
@@ -98,22 +97,26 @@ Timer::~Timer()
9897
9998void Timer::stop ()
10099{
101- if ((mShowTimeMode != ShowTime::NONE) && mStartTimePoint != TimePoint{}) {
102- auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now () - mStartTimePoint );
103- if (!mTimerResults ) {
104- if (mStr == OVERALL
105- && (mShowTimeMode != ShowTime::TOP5_SUMMARY && mShowTimeMode != ShowTime::TOP5_FILE && mShowTimeMode != ShowTime::SUMMARY))
106- return ;
107- if (mStr != OVERALL
108- && (mShowTimeMode != ShowTime::FILE && mShowTimeMode != ShowTime::FILE_TOTAL))
109- return ;
100+ if (mMode == ShowTime::NONE)
101+ return ;
102+ if (mType == Type::OVERALL && mMode != ShowTime::TOP5_SUMMARY && mMode != ShowTime::SUMMARY) {
103+ mMode = ShowTime::NONE;
104+ return ;
105+ }
106+ if (mType == Type::FILE && mMode != ShowTime::TOP5_FILE && mMode != ShowTime::FILE && mMode != ShowTime::FILE_TOTAL) {
107+ mMode = ShowTime::NONE;
108+ return ;
109+ }
110+ if (mStart != TimePoint{}) {
111+ auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now () - mStart );
112+ if (!mResults ) {
110113 std::lock_guard<std::mutex> l (stdCoutLock);
111- std::cout << (mStr == OVERALL ? " Overall time: " : " Check time: " + mStr + " : " )<< TimerResultsData::durationToString (diff) << std::endl;
114+ std::cout << (mType == Type:: OVERALL ? " Overall time: " : " Check time: " + mName + " : " ) << TimerResultsData::durationToString (diff) << std::endl;
112115 } else {
113- mTimerResults ->addResults (mStr , diff);
116+ mResults ->addResults (mName , diff);
114117 }
115118 }
116- mShowTimeMode = ShowTime::NONE; // prevent multiple stops
119+ mMode = ShowTime::NONE; // prevent multiple stops
117120}
118121
119122std::string TimerResultsData::durationToString (std::chrono::milliseconds duration)
0 commit comments