| 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 VM_TIMER_H_ | 5 #ifndef VM_TIMER_H_ |
| 6 #define VM_TIMER_H_ | 6 #define VM_TIMER_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
| 10 #include "vm/os.h" | 10 #include "vm/os.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 // List of per isolate timers. | 78 // List of per isolate timers. |
| 79 #define TIMER_LIST(V) \ | 79 #define TIMER_LIST(V) \ |
| 80 V(time_script_loading, "Script Loading") \ | 80 V(time_script_loading, "Script Loading") \ |
| 81 V(time_creating_snapshot, "Snapshot Creation") \ | 81 V(time_creating_snapshot, "Snapshot Creation") \ |
| 82 V(time_isolate_initialization, "Isolate initialization") \ | 82 V(time_isolate_initialization, "Isolate initialization") \ |
| 83 V(time_compilation, "Function compilation") \ | 83 V(time_compilation, "Function compilation") \ |
| 84 V(time_bootstrap, "Bootstrap of core classes") \ | 84 V(time_bootstrap, "Bootstrap of core classes") \ |
| 85 V(time_dart_execution, "Dart execution") \ | 85 V(time_dart_execution, "Dart execution") \ |
| 86 V(time_native_execution, "Native code execution") \ |
| 86 V(time_total_runtime, "Total runtime for isolate") \ | 87 V(time_total_runtime, "Total runtime for isolate") \ |
| 87 | 88 |
| 88 // Maintains a list of timers per isolate. | 89 // Maintains a list of timers per isolate. |
| 89 class TimerList : public ValueObject { | 90 class TimerList : public ValueObject { |
| 90 public: | 91 public: |
| 91 TimerList(); | 92 TimerList(); |
| 92 ~TimerList() {} | 93 ~TimerList() {} |
| 93 | 94 |
| 94 // Accessors. | 95 // Accessors. |
| 95 #define TIMER_FIELD_ACCESSOR(name, msg) \ | 96 #define TIMER_FIELD_ACCESSOR(name, msg) \ |
| 96 Timer& name() { return name##_; } | 97 Timer& name() { return name##_; } |
| 97 TIMER_LIST(TIMER_FIELD_ACCESSOR) | 98 TIMER_LIST(TIMER_FIELD_ACCESSOR) |
| 98 #undef TIMER_FIELD_ACCESSOR | 99 #undef TIMER_FIELD_ACCESSOR |
| 99 | 100 |
| 100 void ReportTimers(); | 101 void ReportTimers(); |
| 102 void ReportTimerState(const char* prefix); |
| 101 | 103 |
| 102 void PrintTimersToJSONProperty(JSONObject* jsobj); | 104 void PrintTimersToJSONProperty(JSONObject* jsobj); |
| 103 | 105 |
| 104 private: | 106 private: |
| 105 #define TIMER_FIELD(name, msg) Timer name##_; | 107 #define TIMER_FIELD(name, msg) Timer name##_; |
| 106 TIMER_LIST(TIMER_FIELD) | 108 TIMER_LIST(TIMER_FIELD) |
| 107 #undef TIMER_FIELD | 109 #undef TIMER_FIELD |
| 108 bool padding_; | 110 bool padding_; |
| 109 DISALLOW_COPY_AND_ASSIGN(TimerList); | 111 DISALLOW_COPY_AND_ASSIGN(TimerList); |
| 110 }; | 112 }; |
| 111 | 113 |
| 112 // Timer Usage. | 114 // Timer Usage. |
| 113 #define START_TIMER(name) \ | 115 #define START_TIMER(isolate, name) \ |
| 114 Isolate::Current()->timer_list().name().Start(); | 116 isolate->timer_list().name().Start(); |
| 115 | 117 |
| 116 #define STOP_TIMER(name) \ | 118 #define STOP_TIMER(isolate, name) \ |
| 117 Isolate::Current()->timer_list().name().Stop(); | 119 isolate->timer_list().name().Stop(); |
| 120 |
| 121 #define TIMER_STATE(isolate, prefix) \ |
| 122 isolate->timer_list().ReportTimerState(prefix); |
| 118 | 123 |
| 119 // The class TimerScope is used to start and stop a timer within a scope. | 124 // The class TimerScope is used to start and stop a timer within a scope. |
| 120 // It is used as follows: | 125 // It is used as follows: |
| 121 // { | 126 // { |
| 122 // TIMERSCOPE(name_of_timer); | 127 // TIMERSCOPE(name_of_timer); |
| 123 // .... | 128 // .... |
| 124 // ..... | 129 // ..... |
| 125 // code that needs to be timed. | 130 // code that needs to be timed. |
| 126 // .... | 131 // .... |
| 127 // } | 132 // } |
| 128 class TimerScope : public StackResource { | 133 class TimerScope : public StackResource { |
| 129 public: | 134 public: |
| 130 TimerScope(bool flag, Timer* timer, BaseIsolate* isolate = NULL) | 135 TimerScope(bool flag, Timer* timer, BaseIsolate* isolate) |
| 131 : StackResource(isolate), flag_(flag), nested_(false), timer_(timer) { | 136 : StackResource(isolate), flag_(flag), nested_(false), timer_(timer) { |
| 132 if (flag_) { | 137 if (flag_) { |
| 133 if (!timer_->running()) { | 138 if (!timer_->running()) { |
| 134 timer_->Start(); | 139 timer_->Start(); |
| 135 } else { | 140 } else { |
| 136 nested_ = true; | 141 nested_ = true; |
| 137 } | 142 } |
| 138 } | 143 } |
| 139 } | 144 } |
| 140 ~TimerScope() { | 145 ~TimerScope() { |
| 141 if (flag_) { | 146 if (flag_) { |
| 142 if (!nested_) { | 147 if (!nested_) { |
| 143 timer_->Stop(); | 148 timer_->Stop(); |
| 144 } | 149 } |
| 145 } | 150 } |
| 146 } | 151 } |
| 147 | 152 |
| 148 private: | 153 private: |
| 149 bool flag_; | 154 bool flag_; |
| 150 bool nested_; | 155 bool nested_; |
| 151 Timer* timer_; | 156 Timer* timer_; |
| 152 DISALLOW_COPY_AND_ASSIGN(TimerScope); | 157 DISALLOW_COPY_AND_ASSIGN(TimerScope); |
| 153 }; | 158 }; |
| 154 | 159 |
| 155 #define TIMERSCOPE(name) \ | 160 #define TIMERSCOPE(isolate, name) \ |
| 156 TimerScope vm_internal_timer_(true, \ | 161 TimerScope vm_internal_timer_(true, &(isolate->timer_list().name()), isolate) |
| 157 &(Isolate::Current()->timer_list().name())) | |
| 158 | 162 |
| 159 } // namespace dart | 163 } // namespace dart |
| 160 | 164 |
| 161 #endif // VM_TIMER_H_ | 165 #endif // VM_TIMER_H_ |
| OLD | NEW |