OLD | NEW |
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(Counters* counters) | 18 StatsTable::StatsTable(Counters* counters) |
19 : counters_(counters), | 19 : lookup_function_(NULL), |
20 lookup_function_(NULL), | |
21 create_histogram_function_(NULL), | 20 create_histogram_function_(NULL), |
22 add_histogram_sample_function_(NULL) {} | 21 add_histogram_sample_function_(NULL) {} |
23 | 22 |
24 void StatsTable::SetCounterFunction(CounterLookupCallback f) { | 23 void StatsTable::SetCounterFunction(CounterLookupCallback f) { |
25 lookup_function_ = f; | 24 lookup_function_ = f; |
26 counters_->ResetCounters(); | |
27 } | 25 } |
28 | 26 |
29 int* StatsCounterBase::FindLocationInStatsTable() const { | 27 int* StatsCounterBase::FindLocationInStatsTable() const { |
30 return counters_->stats_table()->FindLocation(name_); | 28 return counters_->FindLocation(name_); |
31 } | 29 } |
32 | 30 |
33 StatsCounterThreadSafe::StatsCounterThreadSafe(Counters* counters, | 31 StatsCounterThreadSafe::StatsCounterThreadSafe(Counters* counters, |
34 const char* name) | 32 const char* name) |
35 : StatsCounterBase(counters, name) { | 33 : StatsCounterBase(counters, name) {} |
36 GetPtr(); | |
37 } | |
38 | 34 |
39 void StatsCounterThreadSafe::Set(int Value) { | 35 void StatsCounterThreadSafe::Set(int Value) { |
40 if (ptr_) { | 36 if (ptr_) { |
41 base::LockGuard<base::Mutex> Guard(&mutex_); | 37 base::LockGuard<base::Mutex> Guard(&mutex_); |
42 SetLoc(ptr_, Value); | 38 SetLoc(ptr_, Value); |
43 } | 39 } |
44 } | 40 } |
45 | 41 |
46 void StatsCounterThreadSafe::Increment() { | 42 void StatsCounterThreadSafe::Increment() { |
47 if (ptr_) { | 43 if (ptr_) { |
(...skipping 16 matching lines...) Expand all Loading... |
64 } | 60 } |
65 } | 61 } |
66 | 62 |
67 void StatsCounterThreadSafe::Decrement(int value) { | 63 void StatsCounterThreadSafe::Decrement(int value) { |
68 if (ptr_) { | 64 if (ptr_) { |
69 base::LockGuard<base::Mutex> Guard(&mutex_); | 65 base::LockGuard<base::Mutex> Guard(&mutex_); |
70 DecrementLoc(ptr_, value); | 66 DecrementLoc(ptr_, value); |
71 } | 67 } |
72 } | 68 } |
73 | 69 |
74 int* StatsCounterThreadSafe::GetPtr() { | |
75 base::LockGuard<base::Mutex> Guard(&mutex_); | |
76 ptr_ = FindLocationInStatsTable(); | |
77 return ptr_; | |
78 } | |
79 | |
80 void Histogram::AddSample(int sample) { | 70 void Histogram::AddSample(int sample) { |
81 if (Enabled()) { | 71 if (Enabled()) { |
82 counters_->stats_table()->AddHistogramSample(histogram_, sample); | 72 counters_->AddHistogramSample(histogram_, sample); |
83 } | 73 } |
84 } | 74 } |
85 | 75 |
86 void* Histogram::CreateHistogram() const { | 76 void* Histogram::CreateHistogram() const { |
87 return counters_->stats_table()->CreateHistogram(name_, min_, max_, | 77 return counters_->CreateHistogram(name_, min_, max_, num_buckets_); |
88 num_buckets_); | |
89 } | 78 } |
90 | 79 |
91 | 80 |
92 // Start the timer. | 81 // Start the timer. |
93 void HistogramTimer::Start() { | 82 void HistogramTimer::Start() { |
94 if (Enabled()) { | 83 if (Enabled()) { |
95 timer_.Start(); | 84 timer_.Start(); |
96 } | 85 } |
97 Logger::CallEventLogger(counters()->isolate(), name(), Logger::START, true); | 86 Logger::CallEventLogger(counters()->isolate(), name(), Logger::START, true); |
98 } | 87 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 "c:" "V8.SizeOf_CODE_AGE-" #name}, | 239 "c:" "V8.SizeOf_CODE_AGE-" #name}, |
251 CODE_AGE_LIST_COMPLETE(SC) | 240 CODE_AGE_LIST_COMPLETE(SC) |
252 #undef SC | 241 #undef SC |
253 }; | 242 }; |
254 // clang-format on | 243 // clang-format on |
255 for (const auto& counter : kStatsCounters) { | 244 for (const auto& counter : kStatsCounters) { |
256 this->*counter.member = StatsCounter(this, counter.caption); | 245 this->*counter.member = StatsCounter(this, counter.caption); |
257 } | 246 } |
258 } | 247 } |
259 | 248 |
260 void Counters::ResetCounters() { | 249 void Counters::ResetCounterFunction(CounterLookupCallback f) { |
| 250 stats_table_.SetCounterFunction(f); |
| 251 |
261 #define SC(name, caption) name##_.Reset(); | 252 #define SC(name, caption) name##_.Reset(); |
262 STATS_COUNTER_LIST_1(SC) | 253 STATS_COUNTER_LIST_1(SC) |
263 STATS_COUNTER_LIST_2(SC) | 254 STATS_COUNTER_LIST_2(SC) |
264 #undef SC | 255 #undef SC |
265 | 256 |
266 #define SC(name, caption) name##_.Reset(); | 257 #define SC(name, caption) name##_.Reset(); |
267 STATS_COUNTER_TS_LIST(SC) | 258 STATS_COUNTER_TS_LIST(SC) |
268 #undef SC | 259 #undef SC |
269 | 260 |
270 #define SC(name) \ | 261 #define SC(name) \ |
(...skipping 14 matching lines...) Expand all Loading... |
285 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) | 276 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) |
286 #undef SC | 277 #undef SC |
287 | 278 |
288 #define SC(name) \ | 279 #define SC(name) \ |
289 count_of_CODE_AGE_##name##_.Reset(); \ | 280 count_of_CODE_AGE_##name##_.Reset(); \ |
290 size_of_CODE_AGE_##name##_.Reset(); | 281 size_of_CODE_AGE_##name##_.Reset(); |
291 CODE_AGE_LIST_COMPLETE(SC) | 282 CODE_AGE_LIST_COMPLETE(SC) |
292 #undef SC | 283 #undef SC |
293 } | 284 } |
294 | 285 |
| 286 void Counters::ResetCreateHistogramFunction(CreateHistogramCallback f) { |
| 287 stats_table_.SetCreateHistogramFunction(f); |
295 | 288 |
296 void Counters::ResetHistograms() { | |
297 #define HR(name, caption, min, max, num_buckets) name##_.Reset(); | 289 #define HR(name, caption, min, max, num_buckets) name##_.Reset(); |
298 HISTOGRAM_RANGE_LIST(HR) | 290 HISTOGRAM_RANGE_LIST(HR) |
299 #undef HR | 291 #undef HR |
300 | 292 |
301 #define HT(name, caption, max, res) name##_.Reset(); | 293 #define HT(name, caption, max, res) name##_.Reset(); |
302 HISTOGRAM_TIMER_LIST(HT) | 294 HISTOGRAM_TIMER_LIST(HT) |
303 #undef HT | 295 #undef HT |
304 | 296 |
305 #define AHT(name, caption) name##_.Reset(); | 297 #define AHT(name, caption) name##_.Reset(); |
306 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) | 298 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) |
307 #undef AHT | 299 #undef AHT |
308 | 300 |
309 #define HP(name, caption) name##_.Reset(); | 301 #define HP(name, caption) name##_.Reset(); |
310 HISTOGRAM_PERCENTAGE_LIST(HP) | 302 HISTOGRAM_PERCENTAGE_LIST(HP) |
311 #undef HP | 303 #undef HP |
312 | 304 |
313 #define HM(name, caption) name##_.Reset(); | 305 #define HM(name, caption) name##_.Reset(); |
314 HISTOGRAM_LEGACY_MEMORY_LIST(HM) | 306 HISTOGRAM_LEGACY_MEMORY_LIST(HM) |
315 HISTOGRAM_MEMORY_LIST(HM) | 307 HISTOGRAM_MEMORY_LIST(HM) |
316 #undef HM | 308 #undef HM |
317 } | 309 } |
318 | 310 |
319 void Counters::InitializeHistograms() { | |
320 #define HR(name, caption, min, max, num_buckets) name##_.Enabled(); | |
321 HISTOGRAM_RANGE_LIST(HR) | |
322 #undef HR | |
323 | |
324 #define HT(name, caption, max, res) name##_.Enabled(); | |
325 HISTOGRAM_TIMER_LIST(HT) | |
326 #undef HT | |
327 | |
328 #define AHT(name, caption) name##_.Enabled(); | |
329 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) | |
330 #undef AHT | |
331 | |
332 #define HP(name, caption) name##_.Enabled(); | |
333 HISTOGRAM_PERCENTAGE_LIST(HP) | |
334 #undef HP | |
335 | |
336 #define HM(name, caption) name##_.Enabled(); | |
337 HISTOGRAM_LEGACY_MEMORY_LIST(HM) | |
338 HISTOGRAM_MEMORY_LIST(HM) | |
339 #undef HM | |
340 } | |
341 | |
342 class RuntimeCallStatEntries { | 311 class RuntimeCallStatEntries { |
343 public: | 312 public: |
344 void Print(std::ostream& os) { | 313 void Print(std::ostream& os) { |
345 if (total_call_count == 0) return; | 314 if (total_call_count == 0) return; |
346 std::sort(entries.rbegin(), entries.rend()); | 315 std::sort(entries.rbegin(), entries.rend()); |
347 os << std::setw(50) << "Runtime Function/C++ Builtin" << std::setw(12) | 316 os << std::setw(50) << "Runtime Function/C++ Builtin" << std::setw(12) |
348 << "Time" << std::setw(18) << "Count" << std::endl | 317 << "Time" << std::setw(18) << "Count" << std::endl |
349 << std::string(88, '=') << std::endl; | 318 << std::string(88, '=') << std::endl; |
350 for (Entry& entry : entries) { | 319 for (Entry& entry : entries) { |
351 entry.SetTotal(total_time, total_call_count); | 320 entry.SetTotal(total_time, total_call_count); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 RuntimeCallStats::counters) { | 554 RuntimeCallStats::counters) { |
586 RuntimeCallCounter* counter = &(this->*counter_id); | 555 RuntimeCallCounter* counter = &(this->*counter_id); |
587 if (counter->count() > 0) counter->Dump(value); | 556 if (counter->count() > 0) counter->Dump(value); |
588 } | 557 } |
589 | 558 |
590 in_use_ = false; | 559 in_use_ = false; |
591 } | 560 } |
592 | 561 |
593 } // namespace internal | 562 } // namespace internal |
594 } // namespace v8 | 563 } // namespace v8 |
OLD | NEW |