OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COUNTERS_INL_H_ | 5 #ifndef V8_COUNTERS_INL_H_ |
6 #define V8_COUNTERS_INL_H_ | 6 #define V8_COUNTERS_INL_H_ |
7 | 7 |
8 #include "src/counters.h" | 8 #include "src/counters.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 void RuntimeCallTimer::Start(RuntimeCallCounter* counter, | |
14 RuntimeCallTimer* parent) { | |
15 counter_ = counter; | |
16 parent_.SetValue(parent); | |
17 if (FLAG_runtime_stats != | |
18 v8::tracing::TracingCategoryObserver::ENABLED_BY_SAMPLING) { | |
19 timer_.Start(); | |
20 } | |
21 } | |
22 | |
23 RuntimeCallTimer* RuntimeCallTimer::Stop() { | |
24 if (!timer_.IsStarted()) return parent(); | |
25 base::TimeDelta delta = timer_.Elapsed(); | |
26 timer_.Stop(); | |
27 counter_->count++; | |
28 counter_->time += delta; | |
29 if (parent()) { | |
30 // Adjust parent timer so that it does not include sub timer's time. | |
31 parent()->Subtract(delta); | |
32 } | |
33 return parent(); | |
34 } | |
35 | |
36 void RuntimeCallTimer::Subtract(base::TimeDelta delta) { | |
37 // Adjust the current timer instead of directly subtracting the sub-timers | |
38 // from the current counter. This way we can easily change the counter of an | |
39 // active timer scope. Otherwise we would end up subtracting the time from the | |
40 // previous counter and add the own time to the newly changed counter. | |
41 timer_.Subtract(delta); | |
42 } | |
43 | |
44 void RuntimeCallTimer::Snapshot() { | |
45 base::TimeTicks now = base::TimeTicks::HighResolutionNow(); | |
46 RuntimeCallTimer* timer = this; | |
47 base::TimeDelta delta = base::TimeDeltae::FromMicroseconds(0); | |
Igor Sheludko
2016/11/21 10:54:02
s/TimeDeltae/TimeDelta/
| |
48 // Walk up the timer chain until the the timer doesn't have a parent. | |
49 while (timer != nullptr) { | |
50 // Iteration 1: subtract 0 from the the current timer (this). | |
Igor Sheludko
2016/11/21 10:54:02
s/the the/the/
| |
51 // Iteration n+1: subtract the time (delta) from the subtimer. | |
Igor Sheludko
2016/11/21 10:54:02
subtract subtimer's time (delta) from the the curr
| |
52 timer->Subtract(delta); | |
53 delta = timer->timer_.Restart(now); | |
54 timer->counter_->time += delta; | |
55 timer = timer->parent(); | |
56 } | |
57 } | |
58 | |
13 RuntimeCallTimerScope::RuntimeCallTimerScope( | 59 RuntimeCallTimerScope::RuntimeCallTimerScope( |
14 Isolate* isolate, RuntimeCallStats::CounterId counter_id) { | 60 Isolate* isolate, RuntimeCallStats::CounterId counter_id) { |
15 if (V8_UNLIKELY(FLAG_runtime_stats)) { | 61 if (V8_UNLIKELY(FLAG_runtime_stats)) { |
16 Initialize(isolate->counters()->runtime_call_stats(), counter_id); | 62 Initialize(isolate->counters()->runtime_call_stats(), counter_id); |
17 } | 63 } |
18 } | 64 } |
19 | 65 |
20 RuntimeCallTimerScope::RuntimeCallTimerScope( | 66 RuntimeCallTimerScope::RuntimeCallTimerScope( |
21 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) { | 67 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) { |
22 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id); | 68 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id); |
23 } | 69 } |
24 | 70 |
25 RuntimeCallTimerScope::RuntimeCallTimerScope( | 71 RuntimeCallTimerScope::RuntimeCallTimerScope( |
26 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) { | 72 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) { |
27 if (V8_UNLIKELY(FLAG_runtime_stats)) { | 73 if (V8_UNLIKELY(FLAG_runtime_stats)) { |
28 Initialize(stats, counter_id); | 74 Initialize(stats, counter_id); |
29 } | 75 } |
30 } | 76 } |
31 | 77 |
32 } // namespace internal | 78 } // namespace internal |
33 } // namespace v8 | 79 } // namespace v8 |
34 | 80 |
35 #endif // V8_COUNTERS_INL_H_ | 81 #endif // V8_COUNTERS_INL_H_ |
OLD | NEW |