Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #ifndef VM_SCOPE_TIMER_H_ | |
| 6 #define VM_SCOPE_TIMER_H_ | |
| 7 | |
| 8 namespace dart { | |
| 9 | |
| 10 // Simple utility class for timing a block of code. | |
| 11 class ScopeTimer : public ValueObject { | |
| 12 public: | |
| 13 explicit ScopeTimer(const char* name, bool enabled = true) | |
|
siva
2015/02/09 23:19:59
constructor has two params, is 'explicit' still ne
Cutch
2015/02/09 23:22:07
Acknowledged.
| |
| 14 : enabled_(enabled), | |
| 15 name_(name) { | |
| 16 if (!enabled_) { | |
| 17 return; | |
| 18 } | |
| 19 start_ = OS::GetCurrentTimeMicros(); | |
| 20 } | |
| 21 | |
| 22 int64_t GetElapsed() const { | |
| 23 int64_t end = OS::GetCurrentTimeMicros(); | |
| 24 ASSERT(end >= start_); | |
| 25 return end - start_; | |
| 26 } | |
| 27 | |
| 28 ~ScopeTimer() { | |
| 29 if (!enabled_) { | |
| 30 return; | |
| 31 } | |
| 32 int64_t elapsed = GetElapsed(); | |
| 33 OS::Print("%s took %" Pd64 " micros.\n", name_, elapsed); | |
| 34 } | |
| 35 | |
| 36 private: | |
| 37 const bool enabled_; | |
| 38 const char* name_; | |
| 39 int64_t start_; | |
|
siva
2015/02/09 23:19:59
Missing the boiler plate DISALLOW stuff.
Cutch
2015/02/09 23:22:07
Acknowledged.
| |
| 40 }; | |
| 41 | |
| 42 } // namespace dart | |
| 43 | |
| 44 #endif // VM_SCOPE_TIMER_H_ | |
| OLD | NEW |