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);
|
2019-03-07 17:26:16 +00:00
|
|
|
if (TracingFlags::runtime_stats.load(std::memory_order_relaxed) ==
|
2016-11-24 10:05:22 +00:00
|
|
|
v8::tracing::TracingCategoryObserver::ENABLED_BY_SAMPLING) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-09 14:11:50 +00:00
|
|
|
base::TimeTicks now = RuntimeCallTimer::Now();
|
2016-11-24 10:05:22 +00:00
|
|
|
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();
|
2017-11-09 14:11:50 +00:00
|
|
|
base::TimeTicks now = RuntimeCallTimer::Now();
|
2016-11-24 10:05:22 +00:00
|
|
|
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(); }
|
|
|
|
|
2018-07-17 08:49:20 +00:00
|
|
|
RuntimeCallTimerScope::RuntimeCallTimerScope(Isolate* isolate,
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject heap_object,
|
2017-11-29 15:50:22 +00:00
|
|
|
RuntimeCallCounterId counter_id)
|
2018-07-17 08:49:20 +00:00
|
|
|
: RuntimeCallTimerScope(isolate, counter_id) {}
|
2016-05-11 12:59:46 +00:00
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_COUNTERS_INL_H_
|