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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 void Start(); | 252 void Start(); |
253 | 253 |
254 // Stop the timer and record the results. | 254 // Stop the timer and record the results. |
255 void Stop(); | 255 void Stop(); |
256 | 256 |
257 // Returns true if the timer is running. | 257 // Returns true if the timer is running. |
258 bool Running() { | 258 bool Running() { |
259 return Enabled() && timer_.IsStarted(); | 259 return Enabled() && timer_.IsStarted(); |
260 } | 260 } |
261 | 261 |
| 262 // TODO(bmeurer): Remove this when HistogramTimerScope is fixed. |
| 263 #ifdef DEBUG |
| 264 ElapsedTimer* timer() { return &timer_; } |
| 265 #endif |
| 266 |
262 private: | 267 private: |
263 ElapsedTimer timer_; | 268 ElapsedTimer timer_; |
264 }; | 269 }; |
265 | 270 |
266 // Helper class for scoping a HistogramTimer. | 271 // Helper class for scoping a HistogramTimer. |
| 272 // TODO(bmeurer): The ifdeffery is an ugly hack around the fact that the |
| 273 // Parser is currently reentrant (when it throws an error, we call back |
| 274 // into JavaScript and all bets are off), but ElapsedTimer is not |
| 275 // reentry-safe. Fix this properly and remove |allow_nesting|. |
267 class HistogramTimerScope BASE_EMBEDDED { | 276 class HistogramTimerScope BASE_EMBEDDED { |
268 public: | 277 public: |
269 explicit HistogramTimerScope(HistogramTimer* timer) : | 278 explicit HistogramTimerScope(HistogramTimer* timer, |
270 timer_(timer) { | 279 bool allow_nesting = false) |
| 280 #ifdef DEBUG |
| 281 : timer_(timer), |
| 282 skipped_timer_start_(false) { |
| 283 if (timer_->timer()->IsStarted() && allow_nesting) { |
| 284 skipped_timer_start_ = true; |
| 285 } else { |
| 286 timer_->Start(); |
| 287 } |
| 288 #else |
| 289 : timer_(timer) { |
271 timer_->Start(); | 290 timer_->Start(); |
| 291 #endif |
272 } | 292 } |
273 ~HistogramTimerScope() { | 293 ~HistogramTimerScope() { |
| 294 #ifdef DEBUG |
| 295 if (!skipped_timer_start_) { |
| 296 timer_->Stop(); |
| 297 } |
| 298 #else |
274 timer_->Stop(); | 299 timer_->Stop(); |
| 300 #endif |
275 } | 301 } |
276 private: | 302 private: |
277 HistogramTimer* timer_; | 303 HistogramTimer* timer_; |
| 304 #ifdef DEBUG |
| 305 bool skipped_timer_start_; |
| 306 #endif |
278 }; | 307 }; |
279 | 308 |
280 | 309 |
281 } } // namespace v8::internal | 310 } } // namespace v8::internal |
282 | 311 |
283 #endif // V8_COUNTERS_H_ | 312 #endif // V8_COUNTERS_H_ |
OLD | NEW |