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

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

Issue 2519073002: Revert of [counters] RuntimeStats: fix wrong bookkeeping when dynamically changing counters. (Closed)
Patch Set: 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
« no previous file with comments | « src/counters.cc ('k') | test/unittests/counters-unittest.cc » ('j') | 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 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 change the counter of an
39 // active 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();
46 RuntimeCallTimer* timer = this;
47 base::TimeDelta delta = base::TimeDelta::FromMicroseconds(0);
48 // Walk up the timer chain until the the timer doesn't have a parent.
49 while (timer != nullptr) {
50 // Iteration 1: subtract 0 from the current timer (this).
51 // Iteration n+1: subtract subtimer's time (delta) from the the current
52 // timer.
53 timer->Subtract(delta);
54 delta = timer->timer_.Restart(now);
55 timer->counter_->time += delta;
56 timer = timer->parent();
57 }
58 }
59
60 RuntimeCallTimerScope::RuntimeCallTimerScope( 13 RuntimeCallTimerScope::RuntimeCallTimerScope(
61 Isolate* isolate, RuntimeCallStats::CounterId counter_id) { 14 Isolate* isolate, RuntimeCallStats::CounterId counter_id) {
62 if (V8_UNLIKELY(FLAG_runtime_stats)) { 15 if (V8_UNLIKELY(FLAG_runtime_stats)) {
63 Initialize(isolate->counters()->runtime_call_stats(), counter_id); 16 Initialize(isolate->counters()->runtime_call_stats(), counter_id);
64 } 17 }
65 } 18 }
66 19
67 RuntimeCallTimerScope::RuntimeCallTimerScope( 20 RuntimeCallTimerScope::RuntimeCallTimerScope(
68 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) { 21 HeapObject* heap_object, RuntimeCallStats::CounterId counter_id) {
69 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id); 22 RuntimeCallTimerScope(heap_object->GetIsolate(), counter_id);
70 } 23 }
71 24
72 RuntimeCallTimerScope::RuntimeCallTimerScope( 25 RuntimeCallTimerScope::RuntimeCallTimerScope(
73 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) { 26 RuntimeCallStats* stats, RuntimeCallStats::CounterId counter_id) {
74 if (V8_UNLIKELY(FLAG_runtime_stats)) { 27 if (V8_UNLIKELY(FLAG_runtime_stats)) {
75 Initialize(stats, counter_id); 28 Initialize(stats, counter_id);
76 } 29 }
77 } 30 }
78 31
79 } // namespace internal 32 } // namespace internal
80 } // namespace v8 33 } // namespace v8
81 34
82 #endif // V8_COUNTERS_INL_H_ 35 #endif // V8_COUNTERS_INL_H_
OLDNEW
« no previous file with comments | « src/counters.cc ('k') | test/unittests/counters-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698