Index: src/counters-inl.h |
diff --git a/src/counters-inl.h b/src/counters-inl.h |
index 7219ef778a6ea6a06ce25ad457b7a1299c5d7194..0dd5eb361dbe180fa42db08237f81eb5e1526585 100644 |
--- a/src/counters-inl.h |
+++ b/src/counters-inl.h |
@@ -10,6 +10,50 @@ |
namespace v8 { |
namespace internal { |
+void RuntimeCallTimer::Start(RuntimeCallCounter* counter, |
+ RuntimeCallTimer* parent) { |
+ counter_ = counter; |
+ parent_.SetValue(parent); |
+ if (FLAG_runtime_stats != |
+ v8::tracing::TracingCategoryObserver::ENABLED_BY_SAMPLING) { |
+ timer_.Start(); |
+ } |
+} |
+ |
+RuntimeCallTimer* RuntimeCallTimer::Stop() { |
+ if (!timer_.IsStarted()) return parent(); |
+ base::TimeDelta delta = timer_.Elapsed(); |
+ timer_.Stop(); |
+ counter_->count++; |
+ counter_->time += delta; |
+ if (parent()) { |
+ // Adjust parent timer so that it does not include sub timer's time. |
+ parent()->Subtract(delta); |
+ } |
+ return parent(); |
+} |
+ |
+void RuntimeCallTimer::Subtract(base::TimeDelta delta) { |
+ // Adjust the current timer instead of directly subtracting the sub-timers |
+ // from the current counter. This way we can easily the counter of an active |
Igor Sheludko
2016/11/18 18:56:27
.. can easily [change?] the counter of ...
Camillo Bruni
2016/11/21 10:50:03
done.
|
+ // timer scope. Otherwise we would end up subtracting the time from the |
+ // previous counter and add the own time to the newly changed counter. |
+ timer_.Subtract(delta); |
+} |
+ |
+void RuntimeCallTimer::Snapshot() { |
+ base::TimeTicks now = base::TimeTicks::HighResolutionNow(); |
Igor Sheludko
2016/11/18 18:56:27
I'd prefer to make ElapsedTimer::Now() public to b
Camillo Bruni
2016/11/21 10:50:03
done.
|
+ RuntimeCallTimer* timer = this; |
+ base::TimeDelta delta; |
Igor Sheludko
2016/11/18 18:56:27
base::TimeDelta delta = timer_.Restart(now);
Igor Sheludko
2016/11/20 23:47:16
Please ignore this, but...
|
+ |
+ while (timer) { |
+ timer->Subtract(delta); |
+ delta = timer->timer_.Restart(now); |
Igor Sheludko
2016/11/20 23:47:16
... move this up before Subtract().
|
+ timer->counter_->time += delta; |
+ timer = timer->parent(); |
+ } |
+} |
+ |
RuntimeCallTimerScope::RuntimeCallTimerScope( |
Isolate* isolate, RuntimeCallStats::CounterId counter_id) { |
if (V8_UNLIKELY(FLAG_runtime_stats)) { |