Skip to content

Commit 7cf97e0

Browse files
committed
refs #14599 - moved some ShowTime logic out of TimerResults
1 parent 77d4a16 commit 7cf97e0

5 files changed

Lines changed: 17 additions & 13 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <iostream>
5757
#include <list>
5858
#include <map>
59+
#include <memory>
5960
#include <set>
6061
#include <sstream>
6162
#include <unordered_set>
@@ -464,8 +465,10 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
464465
}
465466

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

470473
// TODO: is this run again instead of using previously cached results?
471474
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "timer.h"
2020

2121
#include <algorithm>
22-
#include <cstddef>
2322
#include <iostream>
2423
#include <utility>
2524
#include <vector>
@@ -37,12 +36,9 @@ namespace {
3736

3837
// TODO: this does not include any file context when SHOWTIME_FILE thus rendering it useless - should we include the logging with the progress logging?
3938
// that could also get rid of the broader locking
40-
void TimerResults::showResults(ShowTime mode, bool metrics) const
39+
void TimerResults::showResults(size_t max_results, bool metrics) const
4140
{
42-
if (mode == ShowTime::NONE)
43-
return;
4441
std::vector<dataElementType> data;
45-
4642
{
4743
std::lock_guard<std::mutex> l(mResultsSync);
4844

@@ -56,7 +52,7 @@ void TimerResults::showResults(ShowTime mode, bool metrics) const
5652

5753
size_t ordinal = 1; // maybe it would be nice to have an ordinal in output later!
5854
for (auto iter=data.cbegin(); iter!=data.cend(); ++iter) {
59-
if ((mode != ShowTime::TOP5_FILE && mode != ShowTime::TOP5_SUMMARY) || (ordinal<=5)) {
55+
if (ordinal <= max_results) {
6056
const double sec = iter->second.getSeconds().count();
6157
std::cout << iter->first << ": " << sec << "s";
6258
if (metrics) {

lib/timer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
#include "config.h"
2424

2525
#include <chrono>
26+
#include <cstddef>
2627
#include <cstdint>
28+
#include <limits>
2729
#include <map>
2830
#include <memory>
2931
#include <mutex>
@@ -66,7 +68,7 @@ class CPPCHECKLIB WARN_UNUSED TimerResults : public TimerResultsIntf {
6668
public:
6769
TimerResults() = default;
6870

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

7274
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)