diff --git a/lib/timer.cpp b/lib/timer.cpp index a135ad13233..2cac304d58f 100644 --- a/lib/timer.cpp +++ b/lib/timer.cpp @@ -47,14 +47,16 @@ void TimerResults::showResults(ShowTime mode) const std::lock_guard l(mResultsSync); data.reserve(mResults.size()); - data.insert(data.begin(), mResults.cbegin(), mResults.cend()); + for (const auto& key : mResultsOrder) + data.emplace_back(*mResults.find(key)); } - std::sort(data.begin(), data.end(), more_second_sec); + if (mode == ShowTime::TOP5_FILE || mode == ShowTime::TOP5_SUMMARY) + std::sort(data.begin(), data.end(), more_second_sec); // lock the whole logging operation to avoid multiple threads printing their results at the same time std::lock_guard l(stdCoutLock); - std::cout << std::endl; + std::cout << std::endl; // TODO: get rid of this size_t ordinal = 1; // maybe it would be nice to have an ordinal in output later! for (auto iter=data.cbegin(); iter!=data.cend(); ++iter) { @@ -71,6 +73,9 @@ void TimerResults::addResults(const std::string& str, std::chrono::milliseconds { std::lock_guard l(mResultsSync); + const auto it = mResults.find(str); + if (it == mResults.end()) + mResultsOrder.emplace_back(str); mResults[str].mDuration += duration; mResults[str].mNumberOfResults++; } @@ -79,6 +84,7 @@ void TimerResults::reset() { std::lock_guard l(mResultsSync); mResults.clear(); + mResultsOrder.clear(); } Timer::Timer(std::string str, ShowTime showtimeMode, TimerResultsIntf* timerResults, Type type) diff --git a/lib/timer.h b/lib/timer.h index 043e1c40b14..fd32dedb530 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -28,6 +28,7 @@ #include #include #include +#include enum class ShowTime : std::uint8_t { NONE, @@ -67,6 +68,7 @@ class CPPCHECKLIB WARN_UNUSED TimerResults : public TimerResultsIntf { private: std::map mResults; + std::vector mResultsOrder; mutable std::mutex mResultsSync; };