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" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 void Histogram::AddSample(int sample) { | 70 void Histogram::AddSample(int sample) { |
71 if (Enabled()) { | 71 if (Enabled()) { |
72 counters_->AddHistogramSample(histogram_, sample); | 72 counters_->AddHistogramSample(histogram_, sample); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 void* Histogram::CreateHistogram() const { | 76 void* Histogram::CreateHistogram() const { |
77 return counters_->CreateHistogram(name_, min_, max_, num_buckets_); | 77 return counters_->CreateHistogram(name_, min_, max_, num_buckets_); |
78 } | 78 } |
79 | 79 |
80 | 80 void TimedHistogram::Start(base::ElapsedTimer* timer, Isolate* isolate) { |
81 // Start the timer. | 81 if (Enabled()) timer->Start(); |
82 void HistogramTimer::Start() { | 82 if (isolate) Logger::CallEventLogger(isolate, name(), Logger::START, true); |
83 if (Enabled()) { | |
84 timer_.Start(); | |
85 } | |
86 Logger::CallEventLogger(counters()->isolate(), name(), Logger::START, true); | |
87 } | 83 } |
88 | 84 |
89 | 85 void TimedHistogram::Stop(base::ElapsedTimer* timer, Isolate* isolate) { |
90 // Stop the timer and record the results. | |
91 void HistogramTimer::Stop() { | |
92 if (Enabled()) { | 86 if (Enabled()) { |
93 int64_t sample = resolution_ == MICROSECOND | |
94 ? timer_.Elapsed().InMicroseconds() | |
95 : timer_.Elapsed().InMilliseconds(); | |
96 // Compute the delta between start and stop, in microseconds. | 87 // Compute the delta between start and stop, in microseconds. |
| 88 int64_t sample = resolution_ == HistogramTimerResolution::MICROSECOND |
| 89 ? timer->Elapsed().InMicroseconds() |
| 90 : timer->Elapsed().InMilliseconds(); |
| 91 timer->Stop(); |
97 AddSample(static_cast<int>(sample)); | 92 AddSample(static_cast<int>(sample)); |
98 timer_.Stop(); | |
99 } | 93 } |
100 Logger::CallEventLogger(counters()->isolate(), name(), Logger::END, true); | 94 if (isolate != nullptr) { |
| 95 Logger::CallEventLogger(isolate, name(), Logger::END, true); |
| 96 } |
101 } | 97 } |
102 | 98 |
103 Counters::Counters(Isolate* isolate) | 99 Counters::Counters(Isolate* isolate) |
104 : isolate_(isolate), | 100 : isolate_(isolate), |
105 stats_table_(this), | 101 stats_table_(this), |
106 // clang format off | 102 // clang format off |
107 #define SC(name, caption) name##_(this, "c:" #caption), | 103 #define SC(name, caption) name##_(this, "c:" #caption), |
108 STATS_COUNTER_TS_LIST(SC) | 104 STATS_COUNTER_TS_LIST(SC) |
109 #undef SC | 105 #undef SC |
110 // clang format on | 106 // clang format on |
111 runtime_call_stats_() { | 107 runtime_call_stats_() { |
112 static const struct { | 108 static const struct { |
113 Histogram Counters::*member; | 109 Histogram Counters::*member; |
114 const char* caption; | 110 const char* caption; |
115 int min; | 111 int min; |
116 int max; | 112 int max; |
117 int num_buckets; | 113 int num_buckets; |
118 } kHistograms[] = { | 114 } kHistograms[] = { |
119 #define HR(name, caption, min, max, num_buckets) \ | 115 #define HR(name, caption, min, max, num_buckets) \ |
120 {&Counters::name##_, #caption, min, max, num_buckets}, | 116 {&Counters::name##_, #caption, min, max, num_buckets}, |
121 HISTOGRAM_RANGE_LIST(HR) | 117 HISTOGRAM_RANGE_LIST(HR) |
122 #undef HR | 118 #undef HR |
123 }; | 119 }; |
124 for (const auto& histogram : kHistograms) { | 120 for (const auto& histogram : kHistograms) { |
125 this->*histogram.member = | 121 this->*histogram.member = |
126 Histogram(histogram.caption, histogram.min, histogram.max, | 122 Histogram(histogram.caption, histogram.min, histogram.max, |
127 histogram.num_buckets, this); | 123 histogram.num_buckets, this); |
128 } | 124 } |
129 | 125 |
| 126 const int DefaultTimedHistogramNumBuckets = 50; |
| 127 |
130 static const struct { | 128 static const struct { |
131 HistogramTimer Counters::*member; | 129 HistogramTimer Counters::*member; |
132 const char* caption; | 130 const char* caption; |
133 int max; | 131 int max; |
134 HistogramTimer::Resolution res; | 132 HistogramTimerResolution res; |
135 } kHistogramTimers[] = { | 133 } kHistogramTimers[] = { |
136 #define HT(name, caption, max, res) \ | 134 #define HT(name, caption, max, res) \ |
137 {&Counters::name##_, #caption, max, HistogramTimer::res}, | 135 {&Counters::name##_, #caption, max, HistogramTimerResolution::res}, |
138 HISTOGRAM_TIMER_LIST(HT) | 136 HISTOGRAM_TIMER_LIST(HT) |
139 #undef HT | 137 #undef HT |
140 }; | 138 }; |
141 for (const auto& timer : kHistogramTimers) { | 139 for (const auto& timer : kHistogramTimers) { |
142 this->*timer.member = | 140 this->*timer.member = HistogramTimer(timer.caption, 0, timer.max, timer.res, |
143 HistogramTimer(timer.caption, 0, timer.max, timer.res, 50, this); | 141 DefaultTimedHistogramNumBuckets, this); |
144 } | 142 } |
145 | 143 |
146 static const struct { | 144 static const struct { |
| 145 TimedHistogram Counters::*member; |
| 146 const char* caption; |
| 147 int max; |
| 148 HistogramTimerResolution res; |
| 149 } kTimedHistograms[] = { |
| 150 #define HT(name, caption, max, res) \ |
| 151 {&Counters::name##_, #caption, max, HistogramTimerResolution::res}, |
| 152 TIMED_HISTOGRAM_LIST(HT) |
| 153 #undef HT |
| 154 }; |
| 155 for (const auto& timer : kTimedHistograms) { |
| 156 this->*timer.member = TimedHistogram(timer.caption, 0, timer.max, timer.res, |
| 157 DefaultTimedHistogramNumBuckets, this); |
| 158 } |
| 159 |
| 160 static const struct { |
147 AggregatableHistogramTimer Counters::*member; | 161 AggregatableHistogramTimer Counters::*member; |
148 const char* caption; | 162 const char* caption; |
149 } kAggregatableHistogramTimers[] = { | 163 } kAggregatableHistogramTimers[] = { |
150 #define AHT(name, caption) {&Counters::name##_, #caption}, | 164 #define AHT(name, caption) {&Counters::name##_, #caption}, |
151 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) | 165 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) |
152 #undef AHT | 166 #undef AHT |
153 }; | 167 }; |
154 for (const auto& aht : kAggregatableHistogramTimers) { | 168 for (const auto& aht : kAggregatableHistogramTimers) { |
155 this->*aht.member = | 169 this->*aht.member = AggregatableHistogramTimer( |
156 AggregatableHistogramTimer(aht.caption, 0, 10000000, 50, this); | 170 aht.caption, 0, 10000000, DefaultTimedHistogramNumBuckets, this); |
157 } | 171 } |
158 | 172 |
159 static const struct { | 173 static const struct { |
160 Histogram Counters::*member; | 174 Histogram Counters::*member; |
161 const char* caption; | 175 const char* caption; |
162 } kHistogramPercentages[] = { | 176 } kHistogramPercentages[] = { |
163 #define HP(name, caption) {&Counters::name##_, #caption}, | 177 #define HP(name, caption) {&Counters::name##_, #caption}, |
164 HISTOGRAM_PERCENTAGE_LIST(HP) | 178 HISTOGRAM_PERCENTAGE_LIST(HP) |
165 #undef HP | 179 #undef HP |
166 }; | 180 }; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 stats_table_.SetCreateHistogramFunction(f); | 301 stats_table_.SetCreateHistogramFunction(f); |
288 | 302 |
289 #define HR(name, caption, min, max, num_buckets) name##_.Reset(); | 303 #define HR(name, caption, min, max, num_buckets) name##_.Reset(); |
290 HISTOGRAM_RANGE_LIST(HR) | 304 HISTOGRAM_RANGE_LIST(HR) |
291 #undef HR | 305 #undef HR |
292 | 306 |
293 #define HT(name, caption, max, res) name##_.Reset(); | 307 #define HT(name, caption, max, res) name##_.Reset(); |
294 HISTOGRAM_TIMER_LIST(HT) | 308 HISTOGRAM_TIMER_LIST(HT) |
295 #undef HT | 309 #undef HT |
296 | 310 |
| 311 #define HT(name, caption, max, res) name##_.Reset(); |
| 312 TIMED_HISTOGRAM_LIST(HT) |
| 313 #undef HT |
| 314 |
297 #define AHT(name, caption) name##_.Reset(); | 315 #define AHT(name, caption) name##_.Reset(); |
298 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) | 316 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) |
299 #undef AHT | 317 #undef AHT |
300 | 318 |
301 #define HP(name, caption) name##_.Reset(); | 319 #define HP(name, caption) name##_.Reset(); |
302 HISTOGRAM_PERCENTAGE_LIST(HP) | 320 HISTOGRAM_PERCENTAGE_LIST(HP) |
303 #undef HP | 321 #undef HP |
304 | 322 |
305 #define HM(name, caption) name##_.Reset(); | 323 #define HM(name, caption) name##_.Reset(); |
306 HISTOGRAM_LEGACY_MEMORY_LIST(HM) | 324 HISTOGRAM_LEGACY_MEMORY_LIST(HM) |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 RuntimeCallStats::counters) { | 572 RuntimeCallStats::counters) { |
555 RuntimeCallCounter* counter = &(this->*counter_id); | 573 RuntimeCallCounter* counter = &(this->*counter_id); |
556 if (counter->count() > 0) counter->Dump(value); | 574 if (counter->count() > 0) counter->Dump(value); |
557 } | 575 } |
558 | 576 |
559 in_use_ = false; | 577 in_use_ = false; |
560 } | 578 } |
561 | 579 |
562 } // namespace internal | 580 } // namespace internal |
563 } // namespace v8 | 581 } // namespace v8 |
OLD | NEW |