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 : counters_(counters), |
20 lookup_function_(NULL), | 20 lookup_function_(NULL), |
21 create_histogram_function_(NULL), | 21 create_histogram_function_(NULL), |
22 add_histogram_sample_function_(NULL) {} | 22 add_histogram_sample_function_(NULL) {} |
23 | 23 |
24 void StatsTable::SetCounterFunction(CounterLookupCallback f) { | 24 void StatsTable::SetCounterFunction(CounterLookupCallback f) { |
25 lookup_function_ = f; | 25 lookup_function_ = f; |
26 counters_->ResetCounters(); | 26 counters_->ResetCounters(); |
27 } | 27 } |
28 | 28 |
29 void StatsTable::SetCreateHistogramFunction(CreateHistogramCallback f) { | |
Mircea Trofin
2017/06/05 15:57:49
It's a bit surprising setting the callback (which
kschimpf
2017/06/05 17:38:52
Ok. However, the current name matches the "include
| |
30 create_histogram_function_ = f; | |
31 counters_->ResetHistograms(); | |
32 } | |
33 | |
29 int* StatsCounterBase::FindLocationInStatsTable() const { | 34 int* StatsCounterBase::FindLocationInStatsTable() const { |
30 return counters_->stats_table()->FindLocation(name_); | 35 return counters_->stats_table()->FindLocation(name_); |
31 } | 36 } |
32 | 37 |
33 StatsCounterThreadSafe::StatsCounterThreadSafe(Counters* counters, | 38 StatsCounterThreadSafe::StatsCounterThreadSafe(Counters* counters, |
34 const char* name) | 39 const char* name) |
35 : StatsCounterBase(counters, name) { | 40 : StatsCounterBase(counters, name) {} |
36 GetPtr(); | |
37 } | |
38 | 41 |
39 void StatsCounterThreadSafe::Set(int Value) { | 42 void StatsCounterThreadSafe::Set(int Value) { |
40 if (ptr_) { | 43 if (ptr_) { |
41 base::LockGuard<base::Mutex> Guard(&mutex_); | 44 base::LockGuard<base::Mutex> Guard(&mutex_); |
42 SetLoc(ptr_, Value); | 45 SetLoc(ptr_, Value); |
43 } | 46 } |
44 } | 47 } |
45 | 48 |
46 void StatsCounterThreadSafe::Increment() { | 49 void StatsCounterThreadSafe::Increment() { |
47 if (ptr_) { | 50 if (ptr_) { |
(...skipping 17 matching lines...) Expand all Loading... | |
65 } | 68 } |
66 | 69 |
67 void StatsCounterThreadSafe::Decrement(int value) { | 70 void StatsCounterThreadSafe::Decrement(int value) { |
68 if (ptr_) { | 71 if (ptr_) { |
69 base::LockGuard<base::Mutex> Guard(&mutex_); | 72 base::LockGuard<base::Mutex> Guard(&mutex_); |
70 DecrementLoc(ptr_, value); | 73 DecrementLoc(ptr_, value); |
71 } | 74 } |
72 } | 75 } |
73 | 76 |
74 int* StatsCounterThreadSafe::GetPtr() { | 77 int* StatsCounterThreadSafe::GetPtr() { |
75 base::LockGuard<base::Mutex> Guard(&mutex_); | |
76 ptr_ = FindLocationInStatsTable(); | 78 ptr_ = FindLocationInStatsTable(); |
77 return ptr_; | 79 return ptr_; |
78 } | 80 } |
79 | 81 |
80 void Histogram::AddSample(int sample) { | 82 void Histogram::AddSample(int sample) { |
81 if (Enabled()) { | 83 if (Enabled()) { |
82 counters_->stats_table()->AddHistogramSample(histogram_, sample); | 84 counters_->stats_table()->AddHistogramSample(histogram_, sample); |
83 } | 85 } |
84 } | 86 } |
85 | 87 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 #define HP(name, caption) name##_.Reset(); | 311 #define HP(name, caption) name##_.Reset(); |
310 HISTOGRAM_PERCENTAGE_LIST(HP) | 312 HISTOGRAM_PERCENTAGE_LIST(HP) |
311 #undef HP | 313 #undef HP |
312 | 314 |
313 #define HM(name, caption) name##_.Reset(); | 315 #define HM(name, caption) name##_.Reset(); |
314 HISTOGRAM_LEGACY_MEMORY_LIST(HM) | 316 HISTOGRAM_LEGACY_MEMORY_LIST(HM) |
315 HISTOGRAM_MEMORY_LIST(HM) | 317 HISTOGRAM_MEMORY_LIST(HM) |
316 #undef HM | 318 #undef HM |
317 } | 319 } |
318 | 320 |
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 { | 321 class RuntimeCallStatEntries { |
343 public: | 322 public: |
344 void Print(std::ostream& os) { | 323 void Print(std::ostream& os) { |
345 if (total_call_count == 0) return; | 324 if (total_call_count == 0) return; |
346 std::sort(entries.rbegin(), entries.rend()); | 325 std::sort(entries.rbegin(), entries.rend()); |
347 os << std::setw(50) << "Runtime Function/C++ Builtin" << std::setw(12) | 326 os << std::setw(50) << "Runtime Function/C++ Builtin" << std::setw(12) |
348 << "Time" << std::setw(18) << "Count" << std::endl | 327 << "Time" << std::setw(18) << "Count" << std::endl |
349 << std::string(88, '=') << std::endl; | 328 << std::string(88, '=') << std::endl; |
350 for (Entry& entry : entries) { | 329 for (Entry& entry : entries) { |
351 entry.SetTotal(total_time, total_call_count); | 330 entry.SetTotal(total_time, total_call_count); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 RuntimeCallStats::counters) { | 564 RuntimeCallStats::counters) { |
586 RuntimeCallCounter* counter = &(this->*counter_id); | 565 RuntimeCallCounter* counter = &(this->*counter_id); |
587 if (counter->count() > 0) counter->Dump(value); | 566 if (counter->count() > 0) counter->Dump(value); |
588 } | 567 } |
589 | 568 |
590 in_use_ = false; | 569 in_use_ = false; |
591 } | 570 } |
592 | 571 |
593 } // namespace internal | 572 } // namespace internal |
594 } // namespace v8 | 573 } // namespace v8 |
OLD | NEW |