- 
        Couldn't load subscription status. 
- Fork 1.5k
Fix #14206 --showtime does not account for addons #7904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
41b0037
              4770995
              3ae5770
              2fee380
              2ba38c4
              b7e889a
              170782a
              7006ea4
              d8c18c3
              6e587b5
              2633020
              aa049f8
              270ba35
              98f362d
              bbb5199
              a576a54
              45e3b2d
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -29,7 +29,7 @@ namespace { | |
| using dataElementType = std::pair<std::string, TimerResultsData>; | ||
| bool more_second_sec(const dataElementType& lhs, const dataElementType& rhs) | ||
| { | ||
| return lhs.second.seconds() > rhs.second.seconds(); | ||
| return lhs.second.getSeconds() > rhs.second.getSeconds(); | ||
| } | ||
|  | ||
| // TODO: remove and print through (synchronized) ErrorLogger instead | ||
|  | @@ -42,8 +42,6 @@ void TimerResults::showResults(SHOWTIME_MODES mode) const | |
| { | ||
| if (mode == SHOWTIME_MODES::SHOWTIME_NONE || mode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) | ||
| return; | ||
|  | ||
| TimerResultsData overallData; | ||
| std::vector<dataElementType> data; | ||
|  | ||
| { | ||
|  | @@ -61,38 +59,20 @@ void TimerResults::showResults(SHOWTIME_MODES mode) const | |
|  | ||
| 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) { | ||
| const double sec = iter->second.seconds(); | ||
| const double sec = iter->second.getSeconds().count(); | ||
| const double secAverage = sec / static_cast<double>(iter->second.mNumberOfResults); | ||
| bool hasParent = false; | ||
| { | ||
| // Do not use valueFlow.. in "Overall time" because those are included in Tokenizer already | ||
| if (startsWith(iter->first,"valueFlow")) | ||
| hasParent = true; | ||
|  | ||
| // Do not use inner timers in "Overall time" | ||
| const std::string::size_type pos = iter->first.rfind("::"); | ||
| if (pos != std::string::npos) | ||
| hasParent = std::any_of(data.cbegin(), data.cend(), [iter,pos](const dataElementType& d) { | ||
| return d.first.size() == pos && iter->first.compare(0, d.first.size(), d.first) == 0; | ||
| }); | ||
| } | ||
| if (!hasParent) | ||
| overallData.mClocks += iter->second.mClocks; | ||
| if ((mode != SHOWTIME_MODES::SHOWTIME_TOP5_FILE && mode != SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY) || (ordinal<=5)) { | ||
| std::cout << iter->first << ": " << sec << "s (avg. " << secAverage << "s - " << iter->second.mNumberOfResults << " result(s))" << std::endl; | ||
| } | ||
| ++ordinal; | ||
| } | ||
|  | ||
| const double secOverall = overallData.seconds(); | ||
| std::cout << "Overall time: " << secOverall << "s" << std::endl; | ||
| } | ||
|  | ||
| void TimerResults::addResults(const std::string& str, std::clock_t clocks) | ||
| void TimerResults::addResults(const std::string& str, Duration duration) | ||
| { | ||
| std::lock_guard<std::mutex> l(mResultsSync); | ||
|  | ||
| mResults[str].mClocks += clocks; | ||
| mResults[str].mDuration += duration; | ||
| mResults[str].mNumberOfResults++; | ||
| } | ||
|  | ||
|  | @@ -105,14 +85,8 @@ void TimerResults::reset() | |
| Timer::Timer(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults) | ||
| : mStr(std::move(str)) | ||
| , mTimerResults(timerResults) | ||
| , mStart(std::clock()) | ||
| , mShowTimeMode(showtimeMode) | ||
| , mStopped(showtimeMode == SHOWTIME_MODES::SHOWTIME_NONE || showtimeMode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) | ||
| {} | ||
|  | ||
| Timer::Timer(bool fileTotal, std::string filename) | ||
| : mStr(std::move(filename)) | ||
| , mStopped(!fileTotal) | ||
| , mStartTimePoint(Clock::now()) | ||
| {} | ||
|  | ||
| Timer::~Timer() | ||
|  | @@ -122,23 +96,41 @@ Timer::~Timer() | |
|  | ||
| void Timer::stop() | ||
| { | ||
| if ((mShowTimeMode != SHOWTIME_MODES::SHOWTIME_NONE) && !mStopped) { | ||
| const std::clock_t end = std::clock(); | ||
| const std::clock_t diff = end - mStart; | ||
|  | ||
| if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE) { | ||
| const double sec = static_cast<double>(diff) / CLOCKS_PER_SEC; | ||
| std::lock_guard<std::mutex> l(stdCoutLock); | ||
| std::cout << mStr << ": " << sec << "s" << std::endl; | ||
| } else if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) { | ||
| const double sec = static_cast<double>(diff) / CLOCKS_PER_SEC; | ||
| if ((mShowTimeMode != SHOWTIME_MODES::SHOWTIME_NONE) && mStartTimePoint != TimePoint{}) { | ||
| Duration diff = std::chrono::duration_cast<Duration>(Clock::now() - mStartTimePoint); | ||
| if (!mTimerResults) { | ||
| if (mStr == "Summary" | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well I don't like the hard coded string literal I assume we can figure out a better solution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could it's just it would be an extra field with no particular good use. But sure for the purpose of "summary" and "other" the bool even will suffice. | ||
| && (mShowTimeMode != SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY && mShowTimeMode != SHOWTIME_MODES::SHOWTIME_TOP5_FILE && mShowTimeMode != SHOWTIME_MODES::SHOWTIME_SUMMARY)) | ||
| return; | ||
| if (mStr != "Summary" | ||
| && (mShowTimeMode != SHOWTIME_MODES::SHOWTIME_FILE && mShowTimeMode != SHOWTIME_MODES::SHOWTIME_FILE_TOTAL)) | ||
| return; | ||
| std::lock_guard<std::mutex> l(stdCoutLock); | ||
| std::cout << "Check time: " << mStr << ": " << sec << "s" << std::endl; | ||
| std::cout << (mStr == "Summary" ? "Overall time: " : "Check time: " + mStr + ": ")<< durationToString(diff) << std::endl; | ||
| } else { | ||
| if (mTimerResults) | ||
| mTimerResults->addResults(mStr, diff); | ||
| mTimerResults->addResults(mStr, diff); | ||
| } | ||
| } | ||
| } | ||
|  | ||
| mStopped = true; | ||
| std::string Timer::durationToString(Duration duration) | ||
| { | ||
| // Extract hours | ||
| auto hours = std::chrono::duration_cast<std::chrono::hours>(duration); | ||
| duration -= hours; // Subtract the extracted hours | ||
|  | ||
| // Extract minutes | ||
| auto minutes = std::chrono::duration_cast<std::chrono::minutes>(duration); | ||
| duration -= minutes; // Subtract the extracted minutes | ||
|  | ||
| // Extract seconds | ||
| std::chrono::duration<double> seconds = std::chrono::duration_cast<std::chrono::duration<double>>(duration); | ||
|  | ||
| std::string ellapsedTime; | ||
| if (hours.count() > 0) | ||
| ellapsedTime += std::to_string(hours.count()) + "h "; | ||
| if (minutes.count() > 0) | ||
| ellapsedTime += std::to_string(minutes.count()) + "m "; | ||
| std::string secondsStr{std::to_string(seconds.count())}; | ||
| return (ellapsedTime + secondsStr.substr(0, secondsStr.length() - 3) + "s "); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -112,7 +112,6 @@ | |
| #include <algorithm> | ||
| #include <array> | ||
| #include <cassert> | ||
| #include <chrono> | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we include it in the timer now | ||
| #include <cstdint> | ||
| #include <cstdlib> | ||
| #include <cstring> | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.