2016-05-11 12:59:46 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef V8_COUNTERS_INL_H_
|
|
|
|
#define V8_COUNTERS_INL_H_
|
|
|
|
|
|
|
|
#include "src/counters.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2016-11-24 10:05:22 +00:00
|
|
|
void RuntimeCallTimer::Start(RuntimeCallCounter* counter,
|
|
|
|
RuntimeCallTimer* parent) {
|
|
|
|
DCHECK(!IsStarted());
|
|
|
|
counter_ = counter;
|
|
|
|
parent_.SetValue(parent);
|
|
|
|
if (FLAG_runtime_stats ==
|
|
|
|
v8::tracing::TracingCategoryObserver::ENABLED_BY_SAMPLING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
base::TimeTicks now = Now();
|
|
|
|
if (parent) parent->Pause(now);
|
|
|
|
Resume(now);
|
|
|
|
DCHECK(IsStarted());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuntimeCallTimer::Pause(base::TimeTicks now) {
|
|
|
|
DCHECK(IsStarted());
|
|
|
|
elapsed_ += (now - start_ticks_);
|
|
|
|
start_ticks_ = base::TimeTicks();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuntimeCallTimer::Resume(base::TimeTicks now) {
|
|
|
|
DCHECK(!IsStarted());
|
|
|
|
start_ticks_ = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
RuntimeCallTimer* RuntimeCallTimer::Stop() {
|
|
|
|
if (!IsStarted()) return parent();
|
|
|
|
base::TimeTicks now = Now();
|
|
|
|
Pause(now);
|
|
|
|
counter_->Increment();
|
|
|
|
CommitTimeToCounter();
|
|
|
|
|
|
|
|
RuntimeCallTimer* parent_timer = parent();
|
|
|
|
if (parent_timer) {
|
|
|
|
parent_timer->Resume(now);
|
|
|
|
}
|
|
|
|
return parent_timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuntimeCallTimer::CommitTimeToCounter() {
|
|
|
|
counter_->Add(elapsed_);
|
|
|
|
elapsed_ = base::TimeDelta();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RuntimeCallTimer::IsStarted() { return start_ticks_ != base::TimeTicks(); }
|
|
|
|
|
|
|
|
base::TimeTicks RuntimeCallTimer::Now() {
|
|
|
|
return base::TimeTicks::HighResolutionNow();
|
|
|
|
}
|
|
|
|
|
2016-05-11 12:59:46 +00:00
|
|
|
RuntimeCallTimerScope::RuntimeCallTimerScope(
|
2016-09-08 18:56:14 +00:00
|
|
|
Isolate* isolate, RuntimeCallStats::CounterId counter_id) {
|
2016-11-04 00:30:44 +00:00
|
|
|
if (V8_UNLIKELY(FLAG_runtime_stats)) {
|
2016-11-15 16:08:16 +00:00
|
|
|
Initialize(isolate->counters()->runtime_call_stats(), counter_id);
|
2016-05-11 12:59:46 +00:00
|
|
|
}
|
2016-09-08 18:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RuntimeCallTimerScope::RuntimeCallTimerScope(
|
|
|
|
HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) {
|
2016-11-15 16:08:16 +00:00
|
|
|
RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
RuntimeCallTimerScope::RuntimeCallTimerScope(
|
|
|
|
RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) {
|
2016-11-04 00:30:44 +00:00
|
|
|
if (V8_UNLIKELY(FLAG_runtime_stats)) {
|
2016-11-15 16:08:16 +00:00
|
|
|
Initialize(stats, counter_id);
|
2016-09-08 18:56:14 +00:00
|
|
|
}
|
2016-05-11 12:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_COUNTERS_INL_H_
|