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 inline 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 inline 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); | |
Camillo Bruni
2016/11/17 14:02:00
newly added Subtract
| |
32 } | |
33 return parent(); | |
34 } | |
35 | |
36 inline 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 the counter of an active | |
Igor Sheludko
2016/11/18 09:55:45
.. can easily [change?] the counter of ...
| |
39 // 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_.AdjustBy(-delta); | |
42 } | |
43 | |
44 inline void RuntimeCallTimer::Elapsed() { | |
45 base::TimeDelta delta = timer_.Elapsed(); | |
46 counter_->time += delta; | |
47 if (parent()) { | |
48 parent()->counter_->time -= delta; | |
49 parent()->Elapsed(); | |
50 } | |
51 timer_.Restart(); | |
52 } | |
53 | |
13 RuntimeCallTimerScope::RuntimeCallTimerScope( | 54 RuntimeCallTimerScope::RuntimeCallTimerScope( |
14 Isolate* isolate, RuntimeCallStats::CounterId counter_id) { | 55 Isolate* isolate, RuntimeCallStats::CounterId counter_id) { |
15 if (V8_UNLIKELY(FLAG_runtime_stats)) { | 56 if (V8_UNLIKELY(FLAG_runtime_stats)) { |
16 Initialize(isolate->counters()->runtime_call_stats(), counter_id); | 57 Initialize(isolate->counters()->runtime_call_stats(), counter_id); |
17 } | 58 } |
18 } | 59 } |
19 | 60 |
20 RuntimeCallTimerScope::RuntimeCallTimerScope( | 61 RuntimeCallTimerScope::RuntimeCallTimerScope( |
21 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) { | 62 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) { |
22 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id); | 63 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id); |
23 } | 64 } |
24 | 65 |
25 RuntimeCallTimerScope::RuntimeCallTimerScope( | 66 RuntimeCallTimerScope::RuntimeCallTimerScope( |
26 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) { | 67 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) { |
27 if (V8_UNLIKELY(FLAG_runtime_stats)) { | 68 if (V8_UNLIKELY(FLAG_runtime_stats)) { |
28 Initialize(stats, counter_id); | 69 Initialize(stats, counter_id); |
29 } | 70 } |
30 } | 71 } |
31 | 72 |
32 } // namespace internal | 73 } // namespace internal |
33 } // namespace v8 | 74 } // namespace v8 |
34 | 75 |
35 #endif // V8_COUNTERS_INL_H_ | 76 #endif // V8_COUNTERS_INL_H_ |
OLD | NEW |