Index: runtime/vm/dart_api_impl.h |
=================================================================== |
--- runtime/vm/dart_api_impl.h (revision 32362) |
+++ runtime/vm/dart_api_impl.h (working copy) |
@@ -8,6 +8,7 @@ |
#include "vm/allocation.h" |
#include "vm/native_arguments.h" |
#include "vm/object.h" |
+#include "vm/timer.h" |
namespace dart { |
@@ -65,7 +66,8 @@ |
FATAL1("%s expects to find a current scope. Did you forget to call " \ |
"Dart_EnterScope?", CURRENT_FUNC); \ |
} \ |
- } while (0) |
+ } while (0); \ |
+ NativeToVmTimerScope __temp_isolate_timer__(isolate); |
#define DARTSCOPE(isolate) \ |
Isolate* __temp_isolate__ = (isolate); \ |
@@ -260,6 +262,56 @@ |
DISALLOW_COPY_AND_ASSIGN(IsolateSaver); |
}; |
+class VmToNativeTimerScope : public ValueObject { |
+ public: |
+ explicit VmToNativeTimerScope(Isolate* isolate) { |
+ native_timer_ = &(isolate->timer_list().time_native_execution()); |
+ native_timer_->Start(); |
+ } |
+ ~VmToNativeTimerScope() { |
+ native_timer_->Stop(); |
+ } |
+ |
+ private: |
+ Timer* native_timer_; |
+ DISALLOW_COPY_AND_ASSIGN(VmToNativeTimerScope); |
+}; |
+ |
+class NativeToVmTimerScope : public ValueObject { |
+ public: |
+ explicit NativeToVmTimerScope(Isolate* isolate) |
+ : dart_running_(false), |
+ timer_list_(&(isolate->timer_list())) { |
+ Timer* dart_timer = &(timer_list_->time_dart_execution()); |
+ Timer* native_timer = &(timer_list_->time_native_execution()); |
+ // Currently when a native function is setup without the auto scope |
+ // setup parameter (leaf function) we would have the dart timer still |
+ // running as we have not done any transitioning. If for some reason |
+ // such a native function makes API call backs we should account for |
+ // that. |
+ if (dart_timer->running()) { |
+ dart_running_ = true; |
+ dart_timer->Stop(); |
+ } else if (native_timer->running()) { |
+ native_timer->Stop(); |
+ } |
turnidge
2014/02/11 21:24:33
Is it ever the case that neither timer is running
siva
2014/02/19 22:38:30
Changed the code to have just
if (dart_timer->runn
|
+ } |
+ ~NativeToVmTimerScope() { |
+ if (dart_running_) { |
+ Timer* dart_timer = &(timer_list_->time_dart_execution()); |
+ dart_timer->Start(); |
+ } else { |
+ Timer* native_timer = &(timer_list_->time_native_execution()); |
+ native_timer->Start(); |
+ } |
+ } |
+ |
+ private: |
+ bool dart_running_; |
+ TimerList* timer_list_; |
+ DISALLOW_COPY_AND_ASSIGN(NativeToVmTimerScope); |
+}; |
+ |
// Start a scope in which no Dart API call backs are allowed. |
#define START_NO_CALLBACK_SCOPE(isolate) \ |
isolate->IncrementNoCallbackScopeDepth() |