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

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

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month 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/timeline_test.cc ('k') | runtime/vm/timer.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) 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) 19 Timer(bool report, const char* message) : report_(report), message_(message) {
20 : report_(report), message_(message) {
21 Reset(); 20 Reset();
22 } 21 }
23 ~Timer() {} 22 ~Timer() {}
24 23
25 // Start timer. 24 // Start timer.
26 void Start() { 25 void Start() {
27 start_ = OS::GetCurrentTimeMicros(); 26 start_ = OS::GetCurrentTimeMicros();
28 running_ = true; 27 running_ = true;
29 } 28 }
30 29
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 void Reset() { 61 void Reset() {
63 start_ = 0; 62 start_ = 0;
64 stop_ = 0; 63 stop_ = 0;
65 total_ = 0; 64 total_ = 0;
66 max_contiguous_ = 0; 65 max_contiguous_ = 0;
67 running_ = false; 66 running_ = false;
68 } 67 }
69 68
70 bool IsReset() const { 69 bool IsReset() const {
71 return (start_ == 0) && (stop_ == 0) && (total_ == 0) && 70 return (start_ == 0) && (stop_ == 0) && (total_ == 0) &&
72 (max_contiguous_ == 0) && !running_; 71 (max_contiguous_ == 0) && !running_;
73 } 72 }
74 73
75 void AddTotal(const Timer& other) { 74 void AddTotal(const Timer& other) {
76 AtomicOperations::IncrementInt64By(&total_, other.total_); 75 AtomicOperations::IncrementInt64By(&total_, other.total_);
77 } 76 }
78 77
79 // Accessors. 78 // Accessors.
80 bool report() const { return report_; } 79 bool report() const { return report_; }
81 bool running() const { return running_; } 80 bool running() const { return running_; }
82 const char* message() const { return message_; } 81 const char* message() const { return message_; }
(...skipping 21 matching lines...) Expand all
104 // It is used as follows: 103 // It is used as follows:
105 // { 104 // {
106 // TimerScope timer(FLAG_name_of_flag, timer, isolate); 105 // TimerScope timer(FLAG_name_of_flag, timer, isolate);
107 // ..... 106 // .....
108 // code that needs to be timed. 107 // code that needs to be timed.
109 // .... 108 // ....
110 // } 109 // }
111 class TimerScope : public StackResource { 110 class TimerScope : public StackResource {
112 public: 111 public:
113 TimerScope(bool flag, Timer* timer, Thread* thread = NULL) 112 TimerScope(bool flag, Timer* timer, Thread* thread = NULL)
114 : StackResource(thread), 113 : StackResource(thread), nested_(false), timer_(flag ? timer : NULL) {
115 nested_(false),
116 timer_(flag ? timer : NULL) {
117 Init(); 114 Init();
118 } 115 }
119 116
120 void Init() { 117 void Init() {
121 if (timer_ != NULL) { 118 if (timer_ != NULL) {
122 if (!timer_->running()) { 119 if (!timer_->running()) {
123 timer_->Start(); 120 timer_->Start();
124 } else { 121 } else {
125 nested_ = true; 122 nested_ = true;
126 } 123 }
(...skipping 12 matching lines...) Expand all
139 Timer* const timer_; 136 Timer* const timer_;
140 137
141 DISALLOW_ALLOCATION(); 138 DISALLOW_ALLOCATION();
142 DISALLOW_COPY_AND_ASSIGN(TimerScope); 139 DISALLOW_COPY_AND_ASSIGN(TimerScope);
143 }; 140 };
144 141
145 142
146 class PauseTimerScope : public StackResource { 143 class PauseTimerScope : public StackResource {
147 public: 144 public:
148 PauseTimerScope(bool flag, Timer* timer, Thread* thread = NULL) 145 PauseTimerScope(bool flag, Timer* timer, Thread* thread = NULL)
149 : StackResource(thread), 146 : StackResource(thread), nested_(false), timer_(flag ? timer : NULL) {
150 nested_(false),
151 timer_(flag ? timer : NULL) {
152 if (timer_) { 147 if (timer_) {
153 if (timer_->running()) { 148 if (timer_->running()) {
154 timer_->Stop(); 149 timer_->Stop();
155 } else { 150 } else {
156 nested_ = true; 151 nested_ = true;
157 } 152 }
158 } 153 }
159 } 154 }
160 ~PauseTimerScope() { 155 ~PauseTimerScope() {
161 if (timer_) { 156 if (timer_) {
162 if (!nested_) { 157 if (!nested_) {
163 timer_->Start(); 158 timer_->Start();
164 } 159 }
165 } 160 }
166 } 161 }
167 162
168 private: 163 private:
169 bool nested_; 164 bool nested_;
170 Timer* const timer_; 165 Timer* const timer_;
171 166
172 DISALLOW_ALLOCATION(); 167 DISALLOW_ALLOCATION();
173 DISALLOW_COPY_AND_ASSIGN(PauseTimerScope); 168 DISALLOW_COPY_AND_ASSIGN(PauseTimerScope);
174 }; 169 };
175 170
176 171
177
178 } // namespace dart 172 } // namespace dart
179 173
180 #endif // RUNTIME_VM_TIMER_H_ 174 #endif // RUNTIME_VM_TIMER_H_
OLDNEW
« no previous file with comments | « runtime/vm/timeline_test.cc ('k') | runtime/vm/timer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698