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

Side by Side Diff: src/counters.cc

Issue 2906063002: Move StatsTable into the Counters class. (Closed)
Patch Set: Fix nits. Created 3 years, 6 months 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.h ('k') | src/isolate.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #include "src/counters.h" 5 #include "src/counters.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 8
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/builtins/builtins-definitions.h" 10 #include "src/builtins/builtins-definitions.h"
11 #include "src/isolate.h" 11 #include "src/isolate.h"
12 #include "src/log-inl.h" 12 #include "src/log-inl.h"
13 #include "src/log.h" 13 #include "src/log.h"
14 14
15 namespace v8 { 15 namespace v8 {
16 namespace internal { 16 namespace internal {
17 17
18 StatsTable::StatsTable() 18 StatsTable::StatsTable(Counters* counters)
19 : lookup_function_(NULL), 19 : counters_(counters),
20 lookup_function_(NULL),
20 create_histogram_function_(NULL), 21 create_histogram_function_(NULL),
21 add_histogram_sample_function_(NULL) {} 22 add_histogram_sample_function_(NULL) {}
22 23
23 void StatsTable::SetCounterFunction(CounterLookupCallback f, Isolate* isolate) { 24 void StatsTable::SetCounterFunction(CounterLookupCallback f) {
24 lookup_function_ = f; 25 lookup_function_ = f;
25 if (!isolate->InitializeCounters()) isolate->counters()->ResetCounters(); 26 counters_->ResetCounters();
26 } 27 }
27 28
28 int* StatsCounterBase::FindLocationInStatsTable() const { 29 int* StatsCounterBase::FindLocationInStatsTable() const {
29 return isolate_->stats_table()->FindLocation(name_); 30 return counters_->stats_table()->FindLocation(name_);
30 } 31 }
31 32
32 StatsCounterThreadSafe::StatsCounterThreadSafe(Isolate* isolate, 33 StatsCounterThreadSafe::StatsCounterThreadSafe(Counters* counters,
33 const char* name) 34 const char* name)
34 : StatsCounterBase(isolate, name) { 35 : StatsCounterBase(counters, name) {
35 GetPtr(); 36 GetPtr();
36 } 37 }
37 38
38 void StatsCounterThreadSafe::Set(int Value) { 39 void StatsCounterThreadSafe::Set(int Value) {
39 if (ptr_) { 40 if (ptr_) {
40 base::LockGuard<base::Mutex> Guard(&mutex_); 41 base::LockGuard<base::Mutex> Guard(&mutex_);
41 SetLoc(ptr_, Value); 42 SetLoc(ptr_, Value);
42 } 43 }
43 } 44 }
44 45
(...skipping 26 matching lines...) Expand all
71 } 72 }
72 73
73 int* StatsCounterThreadSafe::GetPtr() { 74 int* StatsCounterThreadSafe::GetPtr() {
74 base::LockGuard<base::Mutex> Guard(&mutex_); 75 base::LockGuard<base::Mutex> Guard(&mutex_);
75 ptr_ = FindLocationInStatsTable(); 76 ptr_ = FindLocationInStatsTable();
76 return ptr_; 77 return ptr_;
77 } 78 }
78 79
79 void Histogram::AddSample(int sample) { 80 void Histogram::AddSample(int sample) {
80 if (Enabled()) { 81 if (Enabled()) {
81 isolate()->stats_table()->AddHistogramSample(histogram_, sample); 82 counters_->stats_table()->AddHistogramSample(histogram_, sample);
82 } 83 }
83 } 84 }
84 85
85 void* Histogram::CreateHistogram() const { 86 void* Histogram::CreateHistogram() const {
86 return isolate()->stats_table()-> 87 return counters_->stats_table()->CreateHistogram(name_, min_, max_,
87 CreateHistogram(name_, min_, max_, num_buckets_); 88 num_buckets_);
88 } 89 }
89 90
90 91
91 // Start the timer. 92 // Start the timer.
92 void HistogramTimer::Start() { 93 void HistogramTimer::Start() {
93 if (Enabled()) { 94 if (Enabled()) {
94 timer_.Start(); 95 timer_.Start();
95 } 96 }
96 Logger::CallEventLogger(isolate(), name(), Logger::START, true); 97 Logger::CallEventLogger(counters()->isolate(), name(), Logger::START, true);
97 } 98 }
98 99
99 100
100 // Stop the timer and record the results. 101 // Stop the timer and record the results.
101 void HistogramTimer::Stop() { 102 void HistogramTimer::Stop() {
102 if (Enabled()) { 103 if (Enabled()) {
103 int64_t sample = resolution_ == MICROSECOND 104 int64_t sample = resolution_ == MICROSECOND
104 ? timer_.Elapsed().InMicroseconds() 105 ? timer_.Elapsed().InMicroseconds()
105 : timer_.Elapsed().InMilliseconds(); 106 : timer_.Elapsed().InMilliseconds();
106 // Compute the delta between start and stop, in microseconds. 107 // Compute the delta between start and stop, in microseconds.
107 AddSample(static_cast<int>(sample)); 108 AddSample(static_cast<int>(sample));
108 timer_.Stop(); 109 timer_.Stop();
109 } 110 }
110 Logger::CallEventLogger(isolate(), name(), Logger::END, true); 111 Logger::CallEventLogger(counters()->isolate(), name(), Logger::END, true);
111 } 112 }
112 113
113 Counters::Counters(Isolate* isolate) 114 Counters::Counters(Isolate* isolate)
114 : 115 : isolate_(isolate),
116 stats_table_(this),
115 // clang format off 117 // clang format off
116 #define SC(name, caption) name##_(isolate, "c:" #caption), 118 #define SC(name, caption) name##_(this, "c:" #caption),
117 STATS_COUNTER_TS_LIST(SC) 119 STATS_COUNTER_TS_LIST(SC)
118 #undef SC 120 #undef SC
119 // clang format on 121 // clang format on
120 runtime_call_stats_() { 122 runtime_call_stats_() {
121 static const struct { 123 static const struct {
122 Histogram Counters::*member; 124 Histogram Counters::*member;
123 const char* caption; 125 const char* caption;
124 int min; 126 int min;
125 int max; 127 int max;
126 int num_buckets; 128 int num_buckets;
127 } kHistograms[] = { 129 } kHistograms[] = {
128 #define HR(name, caption, min, max, num_buckets) \ 130 #define HR(name, caption, min, max, num_buckets) \
129 {&Counters::name##_, #caption, min, max, num_buckets}, 131 {&Counters::name##_, #caption, min, max, num_buckets},
130 HISTOGRAM_RANGE_LIST(HR) 132 HISTOGRAM_RANGE_LIST(HR)
131 #undef HR 133 #undef HR
132 }; 134 };
133 for (const auto& histogram : kHistograms) { 135 for (const auto& histogram : kHistograms) {
134 this->*histogram.member = 136 this->*histogram.member =
135 Histogram(histogram.caption, histogram.min, histogram.max, 137 Histogram(histogram.caption, histogram.min, histogram.max,
136 histogram.num_buckets, isolate); 138 histogram.num_buckets, this);
137 } 139 }
138 140
139 static const struct { 141 static const struct {
140 HistogramTimer Counters::*member; 142 HistogramTimer Counters::*member;
141 const char* caption; 143 const char* caption;
142 int max; 144 int max;
143 HistogramTimer::Resolution res; 145 HistogramTimer::Resolution res;
144 } kHistogramTimers[] = { 146 } kHistogramTimers[] = {
145 #define HT(name, caption, max, res) \ 147 #define HT(name, caption, max, res) \
146 {&Counters::name##_, #caption, max, HistogramTimer::res}, 148 {&Counters::name##_, #caption, max, HistogramTimer::res},
147 HISTOGRAM_TIMER_LIST(HT) 149 HISTOGRAM_TIMER_LIST(HT)
148 #undef HT 150 #undef HT
149 }; 151 };
150 for (const auto& timer : kHistogramTimers) { 152 for (const auto& timer : kHistogramTimers) {
151 this->*timer.member = 153 this->*timer.member =
152 HistogramTimer(timer.caption, 0, timer.max, timer.res, 50, isolate); 154 HistogramTimer(timer.caption, 0, timer.max, timer.res, 50, this);
153 } 155 }
154 156
155 static const struct { 157 static const struct {
156 AggregatableHistogramTimer Counters::*member; 158 AggregatableHistogramTimer Counters::*member;
157 const char* caption; 159 const char* caption;
158 } kAggregatableHistogramTimers[] = { 160 } kAggregatableHistogramTimers[] = {
159 #define AHT(name, caption) {&Counters::name##_, #caption}, 161 #define AHT(name, caption) {&Counters::name##_, #caption},
160 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) 162 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
161 #undef AHT 163 #undef AHT
162 }; 164 };
163 for (const auto& aht : kAggregatableHistogramTimers) { 165 for (const auto& aht : kAggregatableHistogramTimers) {
164 this->*aht.member = 166 this->*aht.member =
165 AggregatableHistogramTimer(aht.caption, 0, 10000000, 50, isolate); 167 AggregatableHistogramTimer(aht.caption, 0, 10000000, 50, this);
166 } 168 }
167 169
168 static const struct { 170 static const struct {
169 Histogram Counters::*member; 171 Histogram Counters::*member;
170 const char* caption; 172 const char* caption;
171 } kHistogramPercentages[] = { 173 } kHistogramPercentages[] = {
172 #define HP(name, caption) {&Counters::name##_, #caption}, 174 #define HP(name, caption) {&Counters::name##_, #caption},
173 HISTOGRAM_PERCENTAGE_LIST(HP) 175 HISTOGRAM_PERCENTAGE_LIST(HP)
174 #undef HP 176 #undef HP
175 }; 177 };
176 for (const auto& percentage : kHistogramPercentages) { 178 for (const auto& percentage : kHistogramPercentages) {
177 this->*percentage.member = 179 this->*percentage.member = Histogram(percentage.caption, 0, 101, 100, this);
178 Histogram(percentage.caption, 0, 101, 100, isolate);
179 } 180 }
180 181
181 // Exponential histogram assigns bucket limits to points 182 // Exponential histogram assigns bucket limits to points
182 // p[1], p[2], ... p[n] such that p[i+1] / p[i] = constant. 183 // p[1], p[2], ... p[n] such that p[i+1] / p[i] = constant.
183 // The constant factor is equal to the n-th root of (high / low), 184 // The constant factor is equal to the n-th root of (high / low),
184 // where the n is the number of buckets, the low is the lower limit, 185 // where the n is the number of buckets, the low is the lower limit,
185 // the high is the upper limit. 186 // the high is the upper limit.
186 // For n = 50, low = 1000, high = 500000: the factor = 1.13. 187 // For n = 50, low = 1000, high = 500000: the factor = 1.13.
187 static const struct { 188 static const struct {
188 Histogram Counters::*member; 189 Histogram Counters::*member;
189 const char* caption; 190 const char* caption;
190 } kLegacyMemoryHistograms[] = { 191 } kLegacyMemoryHistograms[] = {
191 #define HM(name, caption) {&Counters::name##_, #caption}, 192 #define HM(name, caption) {&Counters::name##_, #caption},
192 HISTOGRAM_LEGACY_MEMORY_LIST(HM) 193 HISTOGRAM_LEGACY_MEMORY_LIST(HM)
193 #undef HM 194 #undef HM
194 }; 195 };
195 for (const auto& histogram : kLegacyMemoryHistograms) { 196 for (const auto& histogram : kLegacyMemoryHistograms) {
196 this->*histogram.member = 197 this->*histogram.member =
197 Histogram(histogram.caption, 1000, 500000, 50, isolate); 198 Histogram(histogram.caption, 1000, 500000, 50, this);
198 } 199 }
199 200
200 // For n = 100, low = 4000, high = 2000000: the factor = 1.06. 201 // For n = 100, low = 4000, high = 2000000: the factor = 1.06.
201 static const struct { 202 static const struct {
202 Histogram Counters::*member; 203 Histogram Counters::*member;
203 AggregatedMemoryHistogram<Histogram> Counters::*aggregated; 204 AggregatedMemoryHistogram<Histogram> Counters::*aggregated;
204 const char* caption; 205 const char* caption;
205 } kMemoryHistograms[] = { 206 } kMemoryHistograms[] = {
206 #define HM(name, caption) \ 207 #define HM(name, caption) \
207 {&Counters::name##_, &Counters::aggregated_##name##_, #caption}, 208 {&Counters::name##_, &Counters::aggregated_##name##_, #caption},
208 HISTOGRAM_MEMORY_LIST(HM) 209 HISTOGRAM_MEMORY_LIST(HM)
209 #undef HM 210 #undef HM
210 }; 211 };
211 for (const auto& histogram : kMemoryHistograms) { 212 for (const auto& histogram : kMemoryHistograms) {
212 this->*histogram.member = 213 this->*histogram.member =
213 Histogram(histogram.caption, 4000, 2000000, 100, isolate); 214 Histogram(histogram.caption, 4000, 2000000, 100, this);
214 this->*histogram.aggregated = 215 this->*histogram.aggregated =
215 AggregatedMemoryHistogram<Histogram>(&(this->*histogram.member)); 216 AggregatedMemoryHistogram<Histogram>(&(this->*histogram.member));
216 } 217 }
217 218
218 // clang-format off 219 // clang-format off
219 static const struct { 220 static const struct {
220 StatsCounter Counters::*member; 221 StatsCounter Counters::*member;
221 const char* caption; 222 const char* caption;
222 } kStatsCounters[] = { 223 } kStatsCounters[] = {
223 #define SC(name, caption) {&Counters::name##_, "c:" #caption}, 224 #define SC(name, caption) {&Counters::name##_, "c:" #caption},
(...skipping 21 matching lines...) Expand all
245 #define SC(name) \ 246 #define SC(name) \
246 {&Counters::count_of_CODE_AGE_##name##_, \ 247 {&Counters::count_of_CODE_AGE_##name##_, \
247 "c:" "V8.CountOf_CODE_AGE-" #name}, \ 248 "c:" "V8.CountOf_CODE_AGE-" #name}, \
248 {&Counters::size_of_CODE_AGE_##name##_, \ 249 {&Counters::size_of_CODE_AGE_##name##_, \
249 "c:" "V8.SizeOf_CODE_AGE-" #name}, 250 "c:" "V8.SizeOf_CODE_AGE-" #name},
250 CODE_AGE_LIST_COMPLETE(SC) 251 CODE_AGE_LIST_COMPLETE(SC)
251 #undef SC 252 #undef SC
252 }; 253 };
253 // clang-format on 254 // clang-format on
254 for (const auto& counter : kStatsCounters) { 255 for (const auto& counter : kStatsCounters) {
255 this->*counter.member = StatsCounter(isolate, counter.caption); 256 this->*counter.member = StatsCounter(this, counter.caption);
256 } 257 }
257 } 258 }
258 259
259 void Counters::ResetCounters() { 260 void Counters::ResetCounters() {
260 #define SC(name, caption) name##_.Reset(); 261 #define SC(name, caption) name##_.Reset();
261 STATS_COUNTER_LIST_1(SC) 262 STATS_COUNTER_LIST_1(SC)
262 STATS_COUNTER_LIST_2(SC) 263 STATS_COUNTER_LIST_2(SC)
263 #undef SC 264 #undef SC
264 265
265 #define SC(name, caption) name##_.Reset(); 266 #define SC(name, caption) name##_.Reset();
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 RuntimeCallStats::counters) { 585 RuntimeCallStats::counters) {
585 RuntimeCallCounter* counter = &(this->*counter_id); 586 RuntimeCallCounter* counter = &(this->*counter_id);
586 if (counter->count() > 0) counter->Dump(value); 587 if (counter->count() > 0) counter->Dump(value);
587 } 588 }
588 589
589 in_use_ = false; 590 in_use_ = false;
590 } 591 }
591 592
592 } // namespace internal 593 } // namespace internal
593 } // namespace v8 594 } // namespace v8
OLDNEW
« no previous file with comments | « src/counters.h ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698