ccls/src/timer.h

37 lines
827 B
C
Raw Normal View History

2017-03-25 19:18:25 +00:00
#pragma once
#include <chrono>
2017-03-31 04:13:58 +00:00
#include <string>
2017-03-25 19:18:25 +00:00
struct Timer {
using Clock = std::chrono::high_resolution_clock;
// Creates a new timer. A timer is always running.
Timer();
// Returns elapsed microseconds.
long long ElapsedMicroseconds() const;
// Returns elapsed microseconds and restarts/resets the timer.
long long ElapsedMicrosecondsAndReset();
2017-03-25 19:18:25 +00:00
// Restart/reset the timer.
void Reset();
2017-03-31 04:13:58 +00:00
// Resets timer and prints a message like "<foo> took 5ms"
void ResetAndPrint(const std::string& message);
2017-10-20 20:56:26 +00:00
// Pause the timer.
void Pause();
// Resume the timer after it has been paused.
void Resume();
2017-03-25 19:18:25 +00:00
// Raw start time.
2018-03-31 20:41:38 +00:00
std::chrono::time_point<Clock> start_;
2017-10-20 20:56:26 +00:00
// Elapsed time.
2018-03-31 20:41:38 +00:00
long long elapsed_;
2017-03-25 19:18:25 +00:00
};
2018-01-12 18:01:35 +00:00
struct ScopedPerfTimer {
~ScopedPerfTimer();
std::string message_;
2018-03-31 20:41:38 +00:00
Timer timer_;
2018-01-12 18:01:35 +00:00
};