| OLD | NEW |
| 1 // Copyright 2012 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 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 bool lookup_done_; | 212 bool lookup_done_; |
| 213 | 213 |
| 214 // Add a single sample to this histogram. | 214 // Add a single sample to this histogram. |
| 215 void AddSample(int sample); | 215 void AddSample(int sample); |
| 216 | 216 |
| 217 // Returns true if this histogram is enabled. | 217 // Returns true if this histogram is enabled. |
| 218 bool Enabled() { | 218 bool Enabled() { |
| 219 return GetHistogram() != NULL; | 219 return GetHistogram() != NULL; |
| 220 } | 220 } |
| 221 | 221 |
| 222 // Reset the cached internal pointer. |
| 223 void Reset() { |
| 224 lookup_done_ = false; |
| 225 } |
| 226 |
| 222 protected: | 227 protected: |
| 223 // Returns the handle to the histogram. | 228 // Returns the handle to the histogram. |
| 224 void* GetHistogram() { | 229 void* GetHistogram() { |
| 225 if (!lookup_done_) { | 230 if (!lookup_done_) { |
| 226 lookup_done_ = true; | 231 lookup_done_ = true; |
| 227 histogram_ = CreateHistogram(); | 232 histogram_ = CreateHistogram(); |
| 228 } | 233 } |
| 229 return histogram_; | 234 return histogram_; |
| 230 } | 235 } |
| 231 | 236 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 244 // Start the timer. | 249 // Start the timer. |
| 245 void Start(); | 250 void Start(); |
| 246 | 251 |
| 247 // Stop the timer and record the results. | 252 // Stop the timer and record the results. |
| 248 void Stop(); | 253 void Stop(); |
| 249 | 254 |
| 250 // Returns true if the timer is running. | 255 // Returns true if the timer is running. |
| 251 bool Running() { | 256 bool Running() { |
| 252 return histogram_.Enabled() && (start_time_ != 0) && (stop_time_ == 0); | 257 return histogram_.Enabled() && (start_time_ != 0) && (stop_time_ == 0); |
| 253 } | 258 } |
| 259 |
| 260 void Reset() { |
| 261 histogram_.Reset(); |
| 262 } |
| 254 }; | 263 }; |
| 255 | 264 |
| 256 // Helper class for scoping a HistogramTimer. | 265 // Helper class for scoping a HistogramTimer. |
| 257 class HistogramTimerScope BASE_EMBEDDED { | 266 class HistogramTimerScope BASE_EMBEDDED { |
| 258 public: | 267 public: |
| 259 explicit HistogramTimerScope(HistogramTimer* timer) : | 268 explicit HistogramTimerScope(HistogramTimer* timer) : |
| 260 timer_(timer) { | 269 timer_(timer) { |
| 261 timer_->Start(); | 270 timer_->Start(); |
| 262 } | 271 } |
| 263 ~HistogramTimerScope() { | 272 ~HistogramTimerScope() { |
| 264 timer_->Stop(); | 273 timer_->Stop(); |
| 265 } | 274 } |
| 266 private: | 275 private: |
| 267 HistogramTimer* timer_; | 276 HistogramTimer* timer_; |
| 268 }; | 277 }; |
| 269 | 278 |
| 270 | 279 |
| 271 } } // namespace v8::internal | 280 } } // namespace v8::internal |
| 272 | 281 |
| 273 #endif // V8_COUNTERS_H_ | 282 #endif // V8_COUNTERS_H_ |
| OLD | NEW |