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 |
| 28 counter_->Increment(); |
| 29 AddAndSubmitResults(delta); |
| 30 |
| 31 RuntimeCallTimer* parent_timer = parent(); |
| 32 if (parent_timer) { |
| 33 // Subtract the elapsed time from the parent to correctly calculate its own |
| 34 // time. |
| 35 parent_timer->SubtractSubtime(delta); |
| 36 } |
| 37 return parent_timer; |
| 38 } |
| 39 |
13 RuntimeCallTimerScope::RuntimeCallTimerScope( | 40 RuntimeCallTimerScope::RuntimeCallTimerScope( |
14 Isolate* isolate, RuntimeCallStats::CounterId counter_id) { | 41 Isolate* isolate, RuntimeCallStats::CounterId counter_id) { |
15 if (V8_UNLIKELY(FLAG_runtime_stats)) { | 42 if (V8_UNLIKELY(FLAG_runtime_stats)) { |
16 Initialize(isolate->counters()->runtime_call_stats(), counter_id); | 43 Initialize(isolate->counters()->runtime_call_stats(), counter_id); |
17 } | 44 } |
18 } | 45 } |
19 | 46 |
20 RuntimeCallTimerScope::RuntimeCallTimerScope( | 47 RuntimeCallTimerScope::RuntimeCallTimerScope( |
21 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) { | 48 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) { |
22 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id); | 49 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id); |
23 } | 50 } |
24 | 51 |
25 RuntimeCallTimerScope::RuntimeCallTimerScope( | 52 RuntimeCallTimerScope::RuntimeCallTimerScope( |
26 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) { | 53 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) { |
27 if (V8_UNLIKELY(FLAG_runtime_stats)) { | 54 if (V8_UNLIKELY(FLAG_runtime_stats)) { |
28 Initialize(stats, counter_id); | 55 Initialize(stats, counter_id); |
29 } | 56 } |
30 } | 57 } |
31 | 58 |
32 } // namespace internal | 59 } // namespace internal |
33 } // namespace v8 | 60 } // namespace v8 |
34 | 61 |
35 #endif // V8_COUNTERS_INL_H_ | 62 #endif // V8_COUNTERS_INL_H_ |
OLD | NEW |