mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 23:55:08 +00:00
09d9d5eedc
- Don't emit so many progress messages - Allow user to control how often progress is emitted - Include number of active threads in progress
58 lines
1.2 KiB
C++
58 lines
1.2 KiB
C++
#include "timer.h"
|
|
|
|
#include <loguru.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
Timer::Timer() {
|
|
Reset();
|
|
}
|
|
|
|
long long Timer::ElapsedMicroseconds() const {
|
|
std::chrono::time_point<Clock> end = Clock::now();
|
|
long long elapsed = elapsed_;
|
|
if (start_.has_value()) {
|
|
elapsed +=
|
|
std::chrono::duration_cast<std::chrono::microseconds>(end - *start_)
|
|
.count();
|
|
}
|
|
return elapsed;
|
|
}
|
|
|
|
long long Timer::ElapsedMicrosecondsAndReset() {
|
|
long long elapsed = ElapsedMicroseconds();
|
|
Reset();
|
|
return elapsed;
|
|
}
|
|
|
|
void Timer::Reset() {
|
|
start_ = Clock::now();
|
|
elapsed_ = 0;
|
|
}
|
|
|
|
void Timer::ResetAndPrint(const std::string& message) {
|
|
long long elapsed = ElapsedMicroseconds();
|
|
long long milliseconds = elapsed / 1000;
|
|
long long remaining = elapsed - milliseconds;
|
|
LOG_S(INFO) << message << " took " << milliseconds << "." << remaining
|
|
<< "ms";
|
|
Reset();
|
|
}
|
|
|
|
void Timer::Pause() {
|
|
assert(start_.has_value());
|
|
|
|
std::chrono::time_point<Clock> end = Clock::now();
|
|
long long elapsed =
|
|
std::chrono::duration_cast<std::chrono::microseconds>(end - *start_)
|
|
.count();
|
|
|
|
elapsed_ += elapsed;
|
|
start_ = nullopt;
|
|
}
|
|
|
|
void Timer::Resume() {
|
|
assert(!start_.has_value());
|
|
start_ = Clock::now();
|
|
}
|