| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef RUNTIME_VM_TIMER_H_ | 5 #ifndef RUNTIME_VM_TIMER_H_ |
| 6 #define RUNTIME_VM_TIMER_H_ | 6 #define RUNTIME_VM_TIMER_H_ |
| 7 | 7 |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/atomic.h" | 10 #include "vm/atomic.h" |
| 11 #include "vm/flags.h" | 11 #include "vm/flags.h" |
| 12 #include "vm/os.h" | 12 #include "vm/os.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 // Timer class allows timing of specific operations in the VM. | 16 // Timer class allows timing of specific operations in the VM. |
| 17 class Timer : public ValueObject { | 17 class Timer : public ValueObject { |
| 18 public: | 18 public: |
| 19 Timer(bool report, const char* message) : report_(report), message_(message) { | 19 Timer(bool report, const char* message) : report_(report), message_(message) { |
| 20 Reset(); | 20 Reset(); |
| 21 } | 21 } |
| 22 ~Timer() {} | 22 ~Timer() {} |
| 23 | 23 |
| 24 // Start timer. | 24 // Start timer. |
| 25 void Start() { | 25 void Start() { |
| 26 start_ = OS::GetCurrentTimeMicros(); | 26 start_ = OS::GetCurrentMonotonicMicros(); |
| 27 running_ = true; | 27 running_ = true; |
| 28 } | 28 } |
| 29 | 29 |
| 30 // Stop timer. | 30 // Stop timer. |
| 31 void Stop() { | 31 void Stop() { |
| 32 ASSERT(start_ != 0); | 32 ASSERT(start_ != 0); |
| 33 ASSERT(running()); | 33 ASSERT(running()); |
| 34 stop_ = OS::GetCurrentTimeMicros(); | 34 stop_ = OS::GetCurrentMonotonicMicros(); |
| 35 int64_t elapsed = ElapsedMicros(); | 35 int64_t elapsed = ElapsedMicros(); |
| 36 max_contiguous_ = Utils::Maximum(max_contiguous_, elapsed); | 36 max_contiguous_ = Utils::Maximum(max_contiguous_, elapsed); |
| 37 // Make increment atomic in case it occurs in parallel with aggregation. | 37 // Make increment atomic in case it occurs in parallel with aggregation. |
| 38 AtomicOperations::IncrementInt64By(&total_, elapsed); | 38 AtomicOperations::IncrementInt64By(&total_, elapsed); |
| 39 running_ = false; | 39 running_ = false; |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Get total cummulative elapsed time in micros. | 42 // Get total cummulative elapsed time in micros. |
| 43 int64_t TotalElapsedTime() const { | 43 int64_t TotalElapsedTime() const { |
| 44 int64_t result = total_; | 44 int64_t result = total_; |
| 45 if (running_) { | 45 if (running_) { |
| 46 int64_t now = OS::GetCurrentTimeMicros(); | 46 int64_t now = OS::GetCurrentMonotonicMicros(); |
| 47 result += (now - start_); | 47 result += (now - start_); |
| 48 } | 48 } |
| 49 return result; | 49 return result; |
| 50 } | 50 } |
| 51 | 51 |
| 52 int64_t MaxContiguous() const { | 52 int64_t MaxContiguous() const { |
| 53 int64_t result = max_contiguous_; | 53 int64_t result = max_contiguous_; |
| 54 if (running_) { | 54 if (running_) { |
| 55 int64_t now = OS::GetCurrentTimeMicros(); | 55 int64_t now = OS::GetCurrentMonotonicMicros(); |
| 56 result = Utils::Maximum(result, now - start_); | 56 result = Utils::Maximum(result, now - start_); |
| 57 } | 57 } |
| 58 return result; | 58 return result; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void Reset() { | 61 void Reset() { |
| 62 start_ = 0; | 62 start_ = 0; |
| 63 stop_ = 0; | 63 stop_ = 0; |
| 64 total_ = 0; | 64 total_ = 0; |
| 65 max_contiguous_ = 0; | 65 max_contiguous_ = 0; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 Timer* const timer_; | 165 Timer* const timer_; |
| 166 | 166 |
| 167 DISALLOW_ALLOCATION(); | 167 DISALLOW_ALLOCATION(); |
| 168 DISALLOW_COPY_AND_ASSIGN(PauseTimerScope); | 168 DISALLOW_COPY_AND_ASSIGN(PauseTimerScope); |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 | 171 |
| 172 } // namespace dart | 172 } // namespace dart |
| 173 | 173 |
| 174 #endif // RUNTIME_VM_TIMER_H_ | 174 #endif // RUNTIME_VM_TIMER_H_ |
| OLD | NEW |