Skip to content

Commit d2bb637

Browse files
committed
refs #14599 - moved some ShowTime logic out of TimerResults
1 parent 21685b3 commit d2bb637

5 files changed

Lines changed: 15 additions & 12 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,10 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
464464
}
465465

466466
// TODO: show time *after* the whole program analysis
467-
if (settings.showtime == ShowTime::SUMMARY || settings.showtime == ShowTime::TOP5_SUMMARY)
468-
timerResults.showResults(settings.showtime);
467+
if (settings.showtime == ShowTime::SUMMARY)
468+
timerResults.showResults();
469+
else if (settings.showtime == ShowTime::TOP5_SUMMARY)
470+
timerResults.showResults(5);
469471

470472
// TODO: is this run again instead of using previously cached results?
471473
returnValue |= cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings, stdLogger.getCtuInfo());

lib/cppcheck.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,12 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
12941294
// TODO: clear earlier?
12951295
mLogger->clear();
12961296

1297-
if (mTimerResults && (mSettings.showtime == ShowTime::FILE || mSettings.showtime == ShowTime::TOP5_FILE))
1298-
mTimerResults->showResults(mSettings.showtime);
1297+
if (mTimerResults) {
1298+
if (mSettings.showtime == ShowTime::FILE)
1299+
mTimerResults->showResults();
1300+
else if (mSettings.showtime == ShowTime::TOP5_FILE)
1301+
mTimerResults->showResults(5);
1302+
}
12991303

13001304
return mLogger->exitcode();
13011305
}

lib/timer.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@ 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) const
41+
void TimerResults::showResults(size_t max_results, bool metrics) const
4242
{
43-
if (mode == ShowTime::NONE)
44-
return;
4543
std::vector<dataElementType> data;
46-
4744
{
4845
std::lock_guard<std::mutex> l(mResultsSync);
4946

@@ -57,7 +54,7 @@ void TimerResults::showResults(ShowTime mode, bool metrics) const
5754

5855
size_t ordinal = 1; // maybe it would be nice to have an ordinal in output later!
5956
for (auto iter=data.cbegin(); iter!=data.cend(); ++iter) {
60-
if ((mode != ShowTime::TOP5_FILE && mode != ShowTime::TOP5_SUMMARY) || (ordinal<=5)) {
57+
if (ordinal <= max_results) {
6158
const double sec = iter->second.getSeconds().count();
6259
std::cout << iter->first << ": " << sec << "s";
6360
if (metrics) {

lib/timer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <chrono>
2626
#include <cstdint>
27+
#include <limits>
2728
#include <map>
2829
#include <memory>
2930
#include <mutex>
@@ -66,7 +67,7 @@ class CPPCHECKLIB WARN_UNUSED TimerResults : public TimerResultsIntf {
6667
public:
6768
TimerResults() = default;
6869

69-
void showResults(ShowTime mode, bool metrics = true) const;
70+
void showResults(size_t max_results = std::numeric_limits<size_t>::max(), bool metrics = true) const;
7071
void addResults(const std::string& name, std::chrono::milliseconds duration) override;
7172

7273
void reset();

test/options.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ options::options(int argc, const char* const argv[])
5858

5959
options::~options()
6060
{
61-
// TODO: allow more than 5 results to be shown
6261
if (mTimerResults)
63-
mTimerResults->showResults(ShowTime::TOP5_FILE, false);
62+
mTimerResults->showResults(10, false);
6463
}
6564

6665
bool options::quiet() const

0 commit comments

Comments
 (0)