5#ifndef RUNTIME_VM_TIMER_H_
6#define RUNTIME_VM_TIMER_H_
25template <
typename Measure>
33 start_ = Measure::Now();
40 stop_ = Measure::Now();
41 int64_t elapsed = ElapsedMicros();
52 int64_t now = Measure::Now();
59 int64_t
result = max_contiguous_;
61 int64_t now = Measure::Now();
76 return (start_ == 0) && (stop_ == 0) && (total_ == 0) &&
77 (max_contiguous_ == 0) && !running_;
89 : total_(elapsed), max_contiguous_(elapsed) {}
91 int64_t ElapsedMicros()
const {
return stop_ - start_; }
93 RelaxedAtomic<int64_t> start_;
94 RelaxedAtomic<int64_t> stop_;
95 RelaxedAtomic<int64_t> total_;
96 RelaxedAtomic<int64_t> max_contiguous_;
98 bool running_ =
false;
105 Timer(int64_t elapsed, int64_t elapsed_cpu)
106 : monotonic_(elapsed), cpu_(elapsed) {}
133 bool IsReset()
const {
return monotonic_.IsReset(); }
136 monotonic_.AddTotal(other.monotonic_);
137 cpu_.AddTotal(other.cpu_);
163 int64_t total_elapsed,
164 int64_t total_elapsed_cpu) {
165 if ((total_elapsed == 0) ||
166 static_cast<double>(
Utils::Abs(total_elapsed - total_elapsed_cpu) /
179 DISALLOW_COPY_AND_ASSIGN(
Timer);
186 if (timer_ !=
nullptr) timer_->
Start();
189 if (timer_ !=
nullptr) timer_->
Stop();
static int64_t GetCurrentMonotonicMicros()
static int64_t GetCurrentThreadCPUMicros()
static char * SCreate(Zone *zone, const char *format,...) PRINTF_ATTRIBUTE(2
PrintTimeScope(const char *name)
T load(std::memory_order order=std::memory_order_relaxed) const
T fetch_add(T arg, std::memory_order order=std::memory_order_relaxed)
ThreadState * thread() const
int64_t MaxContiguous() const
int64_t TotalElapsedTime() const
void AddTotal(const TimerImpl &other)
TimerScope(ThreadState *thread, Timer *timer)
const char * FormatElapsedHumanReadable(Zone *zone) const
static const char * FormatElapsedHumanReadable(Zone *zone, int64_t total_elapsed, int64_t total_elapsed_cpu)
static const char * FormatTime(Zone *zone, int64_t total)
void AddTotal(const Timer &other)
int64_t MaxContiguous() const
int64_t TotalElapsedTimeCpu() const
static constexpr double kCpuTimeReportingThreshold
int64_t TotalElapsedTime() const
Timer(int64_t elapsed, int64_t elapsed_cpu)
static constexpr T Maximum(T x, T y)
constexpr intptr_t kMicrosecondsPerMillisecond
constexpr double MicrosecondsToSeconds(int64_t micros)
constexpr intptr_t kMicrosecondsPerSecond
constexpr double MicrosecondsToMilliseconds(int64_t micros)