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

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

Issue 928833003: Add Function based profile tree (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/profiler_service.cc ('k') | runtime/vm/service.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 VM_SCOPE_TIMER_H_ 5 #ifndef VM_SCOPE_TIMER_H_
6 #define VM_SCOPE_TIMER_H_ 6 #define VM_SCOPE_TIMER_H_
7 7
8 namespace dart { 8 namespace dart {
9 9
10 // Simple utility class for timing a block of code. 10 // Simple utility class for timing a block of code.
11 class ScopeTimer : public ValueObject { 11 class ScopeTimer : public ValueObject {
12 public: 12 public:
13 explicit ScopeTimer(const char* name, bool enabled = true) 13 explicit ScopeTimer(const char* name, bool enabled = true)
14 : enabled_(enabled), 14 : enabled_(enabled),
15 name_(name) { 15 name_(name),
16 start_(0) {
16 if (!enabled_) { 17 if (!enabled_) {
17 return; 18 return;
18 } 19 }
19 start_ = OS::GetCurrentTimeMicros(); 20 start_ = OS::GetCurrentTimeMicros();
20 } 21 }
21 22
22 int64_t GetElapsed() const { 23 int64_t GetElapsed() const {
23 int64_t end = OS::GetCurrentTimeMicros(); 24 int64_t end = OS::GetCurrentTimeMicros();
24 ASSERT(end >= start_); 25 ASSERT(end >= start_);
25 return end - start_; 26 return end - start_;
26 } 27 }
27 28
28 ~ScopeTimer() { 29 ~ScopeTimer() {
29 if (!enabled_) { 30 if (!enabled_) {
30 return; 31 return;
31 } 32 }
32 int64_t elapsed = GetElapsed(); 33 int64_t elapsed = GetElapsed();
33 OS::Print("%s took %" Pd64 " micros.\n", name_, elapsed); 34 OS::Print("%s took %" Pd64 " micros.\n", name_, elapsed);
34 } 35 }
35 36
36 private: 37 private:
37 const bool enabled_; 38 const bool enabled_;
38 const char* name_; 39 const char* name_;
39 int64_t start_; 40 int64_t start_;
40 }; 41 };
41 42
42 } // namespace dart 43 } // namespace dart
43 44
44 #endif // VM_SCOPE_TIMER_H_ 45 #endif // VM_SCOPE_TIMER_H_
OLDNEW
« no previous file with comments | « runtime/vm/profiler_service.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698