Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: src/counters-inl.h

Issue 2511093002: [counters] RuntimeStats: fix wrong bookkeeping when dynamically changing counters. (Closed)
Patch Set: formatting Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/base/platform/elapsed-timer.h ('K') | « src/counters.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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,
Igor Sheludko 2016/11/18 09:55:45 Remove inline here and below.
Camillo Bruni 2016/11/18 16:36:48 done.
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);
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
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();
Igor Sheludko 2016/11/18 09:55:45 Maybe it's better to just call a Restart() here in
Camillo Bruni 2016/11/18 16:36:48 good point, implemented this way.
46 counter_->time += delta;
47 if (parent()) {
48 parent()->counter_->time -= delta;
Igor Sheludko 2016/11/18 09:55:45 Anyway parent()->Subtract(delta); to avoid multi
Camillo Bruni 2016/11/18 16:36:48 done
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_
OLDNEW
« src/base/platform/elapsed-timer.h ('K') | « src/counters.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698