OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // given counter without calling the runtime system. | 162 // given counter without calling the runtime system. |
163 int* GetInternalPointer() { | 163 int* GetInternalPointer() { |
164 int* loc = GetPtr(); | 164 int* loc = GetPtr(); |
165 ASSERT(loc != NULL); | 165 ASSERT(loc != NULL); |
166 return loc; | 166 return loc; |
167 } | 167 } |
168 | 168 |
169 protected: | 169 protected: |
170 // Returns the cached address of this counter location. | 170 // Returns the cached address of this counter location. |
171 int* GetPtr() { | 171 int* GetPtr() { |
172 if (lookup_done_) | 172 if (lookup_done_) return ptr_; |
173 return ptr_; | |
174 lookup_done_ = true; | 173 lookup_done_ = true; |
175 ptr_ = FindLocationInStatsTable(); | 174 ptr_ = FindLocationInStatsTable(); |
176 return ptr_; | 175 return ptr_; |
177 } | 176 } |
178 | 177 |
179 private: | 178 private: |
180 int* FindLocationInStatsTable() const; | 179 int* FindLocationInStatsTable() const; |
181 }; | 180 }; |
182 | 181 |
183 // StatsCounterTimer t = { { L"t:foo", NULL, false }, 0, 0 }; | 182 // StatsCounterTimer t = { { L"t:foo", NULL, false }, 0, 0 }; |
184 struct StatsCounterTimer { | 183 struct StatsCounterTimer { |
185 StatsCounter counter_; | 184 StatsCounter counter_; |
186 | 185 |
187 int64_t start_time_; | 186 int64_t start_time_; |
188 int64_t stop_time_; | 187 int64_t stop_time_; |
189 | 188 |
190 // Start the timer. | 189 // Start the timer. |
191 void Start(); | 190 void Start(); |
192 | 191 |
193 // Stop the timer and record the results. | 192 // Stop the timer and record the results. |
194 void Stop(); | 193 void Stop(); |
195 | 194 |
196 // Returns true if the timer is running. | 195 // Returns true if the timer is running. |
197 bool Running() { | 196 bool Running() { |
198 return counter_.Enabled() && start_time_ != 0 && stop_time_ == 0; | 197 return counter_.Enabled() && start_time_ != 0 && stop_time_ == 0; |
199 } | 198 } |
200 }; | 199 }; |
201 | 200 |
202 // A HistogramTimer allows distributions of results to be created | 201 // A Histogram represents a dynamically created histogram in the StatsTable. |
203 // HistogramTimer t = { L"foo", NULL, false, 0, 0 }; | 202 // |
204 struct HistogramTimer { | 203 // This class is designed to be POD initialized. It will be registered with |
| 204 // the histogram system on first use. For example: |
| 205 // Histogram h = { "myhist", 0, 10000, 50, NULL, false }; |
| 206 struct Histogram { |
205 const char* name_; | 207 const char* name_; |
| 208 int min_; |
| 209 int max_; |
| 210 int num_buckets_; |
206 void* histogram_; | 211 void* histogram_; |
207 bool lookup_done_; | 212 bool lookup_done_; |
208 | 213 |
209 int64_t start_time_; | 214 // Add a single sample to this histogram. |
210 int64_t stop_time_; | 215 void AddSample(int sample); |
211 | 216 |
212 // Start the timer. | 217 // Returns true if this histogram is enabled. |
213 void Start(); | 218 bool Enabled() { |
214 | 219 return GetHistogram() != NULL; |
215 // Stop the timer and record the results. | |
216 void Stop(); | |
217 | |
218 // Returns true if the timer is running. | |
219 bool Running() { | |
220 return (histogram_ != NULL) && (start_time_ != 0) && (stop_time_ == 0); | |
221 } | 220 } |
222 | 221 |
223 protected: | 222 protected: |
224 // Returns the handle to the histogram. | 223 // Returns the handle to the histogram. |
225 void* GetHistogram() { | 224 void* GetHistogram() { |
226 if (!lookup_done_) { | 225 if (!lookup_done_) { |
227 lookup_done_ = true; | 226 lookup_done_ = true; |
228 histogram_ = CreateHistogram(); | 227 histogram_ = CreateHistogram(); |
229 } | 228 } |
230 return histogram_; | 229 return histogram_; |
231 } | 230 } |
232 | 231 |
233 private: | 232 private: |
234 void* CreateHistogram() const; | 233 void* CreateHistogram() const; |
235 }; | 234 }; |
236 | 235 |
| 236 // A HistogramTimer allows distributions of results to be created |
| 237 // HistogramTimer t = { {L"foo", 0, 10000, 50, NULL, false}, 0, 0 }; |
| 238 struct HistogramTimer { |
| 239 Histogram histogram_; |
| 240 |
| 241 int64_t start_time_; |
| 242 int64_t stop_time_; |
| 243 |
| 244 // Start the timer. |
| 245 void Start(); |
| 246 |
| 247 // Stop the timer and record the results. |
| 248 void Stop(); |
| 249 |
| 250 // Returns true if the timer is running. |
| 251 bool Running() { |
| 252 return histogram_.Enabled() && (start_time_ != 0) && (stop_time_ == 0); |
| 253 } |
| 254 }; |
| 255 |
237 // Helper class for scoping a HistogramTimer. | 256 // Helper class for scoping a HistogramTimer. |
238 class HistogramTimerScope BASE_EMBEDDED { | 257 class HistogramTimerScope BASE_EMBEDDED { |
239 public: | 258 public: |
240 explicit HistogramTimerScope(HistogramTimer* timer) : | 259 explicit HistogramTimerScope(HistogramTimer* timer) : |
241 timer_(timer) { | 260 timer_(timer) { |
242 timer_->Start(); | 261 timer_->Start(); |
243 } | 262 } |
244 ~HistogramTimerScope() { | 263 ~HistogramTimerScope() { |
245 timer_->Stop(); | 264 timer_->Stop(); |
246 } | 265 } |
247 private: | 266 private: |
248 HistogramTimer* timer_; | 267 HistogramTimer* timer_; |
249 }; | 268 }; |
250 | 269 |
251 | 270 |
252 } } // namespace v8::internal | 271 } } // namespace v8::internal |
253 | 272 |
254 #endif // V8_COUNTERS_H_ | 273 #endif // V8_COUNTERS_H_ |
OLD | NEW |