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 DCHECK(!IsStarted()); |
| 16 counter_ = counter; |
| 17 parent_.SetValue(parent); |
| 18 if (FLAG_runtime_stats == |
| 19 v8::tracing::TracingCategoryObserver::ENABLED_BY_SAMPLING) { |
| 20 return; |
| 21 } |
| 22 base::TimeTicks now = Now(); |
| 23 if (parent) parent->Pause(now); |
| 24 Resume(now); |
| 25 DCHECK(IsStarted()); |
| 26 } |
| 27 |
| 28 void RuntimeCallTimer::Pause(base::TimeTicks now) { |
| 29 DCHECK(IsStarted()); |
| 30 elapsed_ += (now - start_ticks_); |
| 31 start_ticks_ = base::TimeTicks(); |
| 32 } |
| 33 |
| 34 void RuntimeCallTimer::Resume(base::TimeTicks now) { |
| 35 DCHECK(!IsStarted()); |
| 36 start_ticks_ = now; |
| 37 } |
| 38 |
| 39 RuntimeCallTimer* RuntimeCallTimer::Stop() { |
| 40 if (!IsStarted()) return parent(); |
| 41 base::TimeTicks now = Now(); |
| 42 Pause(now); |
| 43 counter_->Increment(); |
| 44 CommitTimeToCounter(); |
| 45 |
| 46 RuntimeCallTimer* parent_timer = parent(); |
| 47 if (parent_timer) { |
| 48 parent_timer->Resume(now); |
| 49 } |
| 50 return parent_timer; |
| 51 } |
| 52 |
| 53 void RuntimeCallTimer::CommitTimeToCounter() { |
| 54 counter_->Add(elapsed_); |
| 55 elapsed_ = base::TimeDelta(); |
| 56 } |
| 57 |
| 58 bool RuntimeCallTimer::IsStarted() { return start_ticks_ != base::TimeTicks(); } |
| 59 |
| 60 base::TimeTicks RuntimeCallTimer::Now() { |
| 61 return base::TimeTicks::HighResolutionNow(); |
| 62 } |
| 63 |
13 RuntimeCallTimerScope::RuntimeCallTimerScope( | 64 RuntimeCallTimerScope::RuntimeCallTimerScope( |
14 Isolate* isolate, RuntimeCallStats::CounterId counter_id) { | 65 Isolate* isolate, RuntimeCallStats::CounterId counter_id) { |
15 if (V8_UNLIKELY(FLAG_runtime_stats)) { | 66 if (V8_UNLIKELY(FLAG_runtime_stats)) { |
16 Initialize(isolate->counters()->runtime_call_stats(), counter_id); | 67 Initialize(isolate->counters()->runtime_call_stats(), counter_id); |
17 } | 68 } |
18 } | 69 } |
19 | 70 |
20 RuntimeCallTimerScope::RuntimeCallTimerScope( | 71 RuntimeCallTimerScope::RuntimeCallTimerScope( |
21 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) { | 72 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) { |
22 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id); | 73 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id); |
23 } | 74 } |
24 | 75 |
25 RuntimeCallTimerScope::RuntimeCallTimerScope( | 76 RuntimeCallTimerScope::RuntimeCallTimerScope( |
26 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) { | 77 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) { |
27 if (V8_UNLIKELY(FLAG_runtime_stats)) { | 78 if (V8_UNLIKELY(FLAG_runtime_stats)) { |
28 Initialize(stats, counter_id); | 79 Initialize(stats, counter_id); |
29 } | 80 } |
30 } | 81 } |
31 | 82 |
32 } // namespace internal | 83 } // namespace internal |
33 } // namespace v8 | 84 } // namespace v8 |
34 | 85 |
35 #endif // V8_COUNTERS_INL_H_ | 86 #endif // V8_COUNTERS_INL_H_ |
OLD | NEW |