counters-inl.h 1.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// 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 {

13 14 15 16 17
void RuntimeCallTimer::Start(RuntimeCallCounter* counter,
                             RuntimeCallTimer* parent) {
  DCHECK(!IsStarted());
  counter_ = counter;
  parent_.SetValue(parent);
18
  if (base::AsAtomic32::Relaxed_Load(&FLAG_runtime_stats) ==
19 20 21
      v8::tracing::TracingCategoryObserver::ENABLED_BY_SAMPLING) {
    return;
  }
22
  base::TimeTicks now = RuntimeCallTimer::Now();
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  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();
41
  base::TimeTicks now = RuntimeCallTimer::Now();
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
  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(); }

60 61
RuntimeCallTimerScope::RuntimeCallTimerScope(Isolate* isolate,
                                             HeapObject* heap_object,
62
                                             RuntimeCallCounterId counter_id)
63
    : RuntimeCallTimerScope(isolate, counter_id) {}
64 65 66 67 68

}  // namespace internal
}  // namespace v8

#endif  // V8_COUNTERS_INL_H_