Skip to content

Commit 3ae5770

Browse files
committed
Rework + test fix
1 parent 4770995 commit 3ae5770

4 files changed

Lines changed: 13 additions & 31 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ namespace {
409409

410410
int CppCheckExecutor::check(int argc, const char* const argv[])
411411
{
412-
WholeProgramTimer timer;
412+
auto startTime{Timer::now()};
413413
Settings settings;
414414
CmdLineLoggerStd logger;
415415
Suppressions supprs;
@@ -421,16 +421,16 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
421421
return EXIT_SUCCESS;
422422
}
423423

424-
if (settings.showtime == SHOWTIME_MODES::SHOWTIME_NONE)
425-
timer.cancell();
426-
427424
settings.loadSummaries();
428425

429426
mFiles = parser.getFiles();
430427
mFileSettings = parser.getFileSettings();
431428

432429
const int ret = check_wrapper(settings, supprs);
433430

431+
if (settings.showtime != SHOWTIME_MODES::SHOWTIME_NONE)
432+
Timer::calculateAndOutputTimeDiff(startTime, Timer::now());
433+
434434
return ret;
435435
}
436436

lib/timer.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,9 @@ void Timer::stop()
140140
mStopped = true;
141141
}
142142

143-
WholeProgramTimer::~WholeProgramTimer()
143+
void Timer::calculateAndOutputTimeDiff(const std::chrono::system_clock::time_point& start, const std::chrono::system_clock::time_point& end)
144144
{
145-
stop();
146-
}
147-
148-
void WholeProgramTimer::stop()
149-
{
150-
if (mCancelled)
151-
return;
152-
const auto end = std::chrono::high_resolution_clock::now();
153-
auto diff = std::chrono::duration_cast<std::chrono::microseconds>(end - mStart);
145+
auto diff = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
154146

155147
// Extract hours
156148
auto hours = std::chrono::duration_cast<std::chrono::hours>(diff);

lib/timer.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ class CPPCHECKLIB Timer {
7979
Timer(const Timer&) = delete;
8080
Timer& operator=(const Timer&) = delete;
8181

82+
static std::chrono::system_clock::time_point now() {
83+
return std::chrono::high_resolution_clock::now();
84+
}
85+
86+
static void calculateAndOutputTimeDiff(const std::chrono::system_clock::time_point& start, const std::chrono::system_clock::time_point& end);
87+
8288
void stop();
8389

8490
static void run(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults, const std::function<void()>& f) {
@@ -94,21 +100,5 @@ class CPPCHECKLIB Timer {
94100
bool mStopped{};
95101
};
96102

97-
class CPPCHECKLIB WholeProgramTimer {
98-
public:
99-
WholeProgramTimer()
100-
: mStart(std::chrono::high_resolution_clock::now())
101-
{}
102-
~WholeProgramTimer();
103-
104-
void stop();
105-
106-
void cancell() {
107-
mCancelled = true;
108-
}
109-
private:
110-
std::chrono::system_clock::time_point mStart;
111-
bool mCancelled{false};
112-
};
113103
//---------------------------------------------------------------------------
114104
#endif // timerH

test/testprocessexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class TestProcessExecutorBase : public TestFixture {
248248
$.showtime = SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY));
249249
const std::string output_s = GET_REDIRECT_OUTPUT;
250250
// once: top5 results + overall + empty line
251-
TODO_ASSERT_EQUALS(5 + 1 + 1, 2, cppcheck::count_all_of(output_s, '\n'));
251+
TODO_ASSERT_EQUALS(5 + 1 + 1, 1, cppcheck::count_all_of(output_s, '\n'));
252252
// should only report the top5 once
253253
ASSERT(output_s.find("1 result(s)") == std::string::npos);
254254
TODO_ASSERT(output_s.find("2 result(s)") != std::string::npos);

0 commit comments

Comments
 (0)