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 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.
| |
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_.Subtract(delta); | |
42 } | |
43 | |
44 void RuntimeCallTimer::Snapshot() { | |
45 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.
| |
46 RuntimeCallTimer* timer = this; | |
47 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...
| |
48 | |
49 while (timer) { | |
50 timer->Subtract(delta); | |
51 delta = timer->timer_.Restart(now); | |
Igor Sheludko
2016/11/20 23:47:16
... move this up before Subtract().
| |
52 timer->counter_->time += delta; | |
53 timer = timer->parent(); | |
54 } | |
55 } | |
56 | |
13 RuntimeCallTimerScope::RuntimeCallTimerScope( | 57 RuntimeCallTimerScope::RuntimeCallTimerScope( |
14 Isolate* isolate, RuntimeCallStats::CounterId counter_id) { | 58 Isolate* isolate, RuntimeCallStats::CounterId counter_id) { |
15 if (V8_UNLIKELY(FLAG_runtime_stats)) { | 59 if (V8_UNLIKELY(FLAG_runtime_stats)) { |
16 Initialize(isolate->counters()->runtime_call_stats(), counter_id); | 60 Initialize(isolate->counters()->runtime_call_stats(), counter_id); |
17 } | 61 } |
18 } | 62 } |
19 | 63 |
20 RuntimeCallTimerScope::RuntimeCallTimerScope( | 64 RuntimeCallTimerScope::RuntimeCallTimerScope( |
21 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) { | 65 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) { |
22 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id); | 66 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id); |
23 } | 67 } |
24 | 68 |
25 RuntimeCallTimerScope::RuntimeCallTimerScope( | 69 RuntimeCallTimerScope::RuntimeCallTimerScope( |
26 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) { | 70 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) { |
27 if (V8_UNLIKELY(FLAG_runtime_stats)) { | 71 if (V8_UNLIKELY(FLAG_runtime_stats)) { |
28 Initialize(stats, counter_id); | 72 Initialize(stats, counter_id); |
29 } | 73 } |
30 } | 74 } |
31 | 75 |
32 } // namespace internal | 76 } // namespace internal |
33 } // namespace v8 | 77 } // namespace v8 |
34 | 78 |
35 #endif // V8_COUNTERS_INL_H_ | 79 #endif // V8_COUNTERS_INL_H_ |
OLD | NEW |