Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ void TimerResults::showResults(ShowTime mode) const
std::lock_guard<std::mutex> 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<std::mutex> 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) {
Expand All @@ -71,6 +73,9 @@ void TimerResults::addResults(const std::string& str, std::chrono::milliseconds
{
std::lock_guard<std::mutex> l(mResultsSync);

const auto it = mResults.find(str);
if (it == mResults.end())
mResultsOrder.emplace_back(str);
mResults[str].mDuration += duration;
mResults[str].mNumberOfResults++;
}
Expand All @@ -79,6 +84,7 @@ void TimerResults::reset()
{
std::lock_guard<std::mutex> l(mResultsSync);
mResults.clear();
mResultsOrder.clear();
}

Timer::Timer(std::string str, ShowTime showtimeMode, TimerResultsIntf* timerResults, Type type)
Expand Down
2 changes: 2 additions & 0 deletions lib/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <mutex>
#include <string>
#include <utility>
#include <vector>

enum class ShowTime : std::uint8_t {
NONE,
Expand Down Expand Up @@ -67,6 +68,7 @@ class CPPCHECKLIB WARN_UNUSED TimerResults : public TimerResultsIntf {

private:
std::map<std::string, TimerResultsData> mResults;
std::vector<std::string> mResultsOrder;
mutable std::mutex mResultsSync;
};

Expand Down