Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: runtime/vm/scope_timer.h

Issue 2582543003: Update GC stats, ThreadPool, Timer and ScopedTimer to use monotonic time. (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/scavenger.cc ('k') | runtime/vm/thread_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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_SCOPE_TIMER_H_ 5 #ifndef RUNTIME_VM_SCOPE_TIMER_H_
6 #define RUNTIME_VM_SCOPE_TIMER_H_ 6 #define RUNTIME_VM_SCOPE_TIMER_H_
7 7
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 9
10 namespace dart { 10 namespace dart {
11 11
12 // Simple utility class for timing a block of code. 12 // Simple utility class for timing a block of code.
13 class ScopeTimer : public ValueObject { 13 class ScopeTimer : public ValueObject {
14 public: 14 public:
15 explicit ScopeTimer(const char* name, bool enabled = true) 15 explicit ScopeTimer(const char* name, bool enabled = true)
16 : enabled_(enabled), name_(name), start_(0) { 16 : enabled_(enabled), name_(name), start_(0) {
17 if (!enabled_) { 17 if (!enabled_) {
18 return; 18 return;
19 } 19 }
20 start_ = OS::GetCurrentTimeMicros(); 20 start_ = OS::GetCurrentMonotonicMicros();
21 } 21 }
22 22
23 int64_t GetElapsed() const { 23 int64_t GetElapsed() const {
24 int64_t end = OS::GetCurrentTimeMicros(); 24 int64_t end = OS::GetCurrentMonotonicMicros();
25 ASSERT(end >= start_); 25 ASSERT(end >= start_);
26 return end - start_; 26 return end - start_;
27 } 27 }
28 28
29 ~ScopeTimer() { 29 ~ScopeTimer() {
30 if (!enabled_) { 30 if (!enabled_) {
31 return; 31 return;
32 } 32 }
33 int64_t elapsed = GetElapsed(); 33 int64_t elapsed = GetElapsed();
34 double seconds = MicrosecondsToSeconds(elapsed); 34 double seconds = MicrosecondsToSeconds(elapsed);
35 OS::Print("%s: %f seconds (%" Pd64 " \u00B5s)\n", name_, seconds, elapsed); 35 OS::Print("%s: %f seconds (%" Pd64 " \u00B5s)\n", name_, seconds, elapsed);
36 } 36 }
37 37
38 private: 38 private:
39 const bool enabled_; 39 const bool enabled_;
40 const char* name_; 40 const char* name_;
41 int64_t start_; 41 int64_t start_;
42 }; 42 };
43 43
44 } // namespace dart 44 } // namespace dart
45 45
46 #endif // RUNTIME_VM_SCOPE_TIMER_H_ 46 #endif // RUNTIME_VM_SCOPE_TIMER_H_
OLDNEW
« no previous file with comments | « runtime/vm/scavenger.cc ('k') | runtime/vm/thread_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698