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

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

Issue 965593002: Improved profiler view and inclusive 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/symbols.h » ('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 #include "platform/globals.h"
9
8 namespace dart { 10 namespace dart {
9 11
10 // Simple utility class for timing a block of code. 12 // Simple utility class for timing a block of code.
11 class ScopeTimer : public ValueObject { 13 class ScopeTimer : public ValueObject {
12 public: 14 public:
13 explicit ScopeTimer(const char* name, bool enabled = true) 15 explicit ScopeTimer(const char* name, bool enabled = true)
14 : enabled_(enabled), 16 : enabled_(enabled),
15 name_(name), 17 name_(name),
16 start_(0) { 18 start_(0) {
17 if (!enabled_) { 19 if (!enabled_) {
18 return; 20 return;
19 } 21 }
20 start_ = OS::GetCurrentTimeMicros(); 22 start_ = OS::GetCurrentTimeMicros();
21 } 23 }
22 24
23 int64_t GetElapsed() const { 25 int64_t GetElapsed() const {
24 int64_t end = OS::GetCurrentTimeMicros(); 26 int64_t end = OS::GetCurrentTimeMicros();
25 ASSERT(end >= start_); 27 ASSERT(end >= start_);
26 return end - start_; 28 return end - start_;
27 } 29 }
28 30
29 ~ScopeTimer() { 31 ~ScopeTimer() {
30 if (!enabled_) { 32 if (!enabled_) {
31 return; 33 return;
32 } 34 }
33 int64_t elapsed = GetElapsed(); 35 int64_t elapsed = GetElapsed();
34 OS::Print("%s took %" Pd64 " micros.\n", name_, elapsed); 36 double seconds = MicrosecondsToSeconds(elapsed);
37 OS::Print("%s: %f seconds (%" Pd64 " \u00B5s)\n", name_, seconds, elapsed);
35 } 38 }
36 39
37 private: 40 private:
38 const bool enabled_; 41 const bool enabled_;
39 const char* name_; 42 const char* name_;
40 int64_t start_; 43 int64_t start_;
41 }; 44 };
42 45
43 } // namespace dart 46 } // namespace dart
44 47
45 #endif // VM_SCOPE_TIMER_H_ 48 #endif // VM_SCOPE_TIMER_H_
OLDNEW
« no previous file with comments | « runtime/vm/profiler_service.cc ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698