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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 1811613002: Timeline API fixes for Flutter (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/dart_api_impl_test.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "lib/stacktrace.h" 10 #include "lib/stacktrace.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (strncmp(func, "dart::", 6) == 0) { 71 if (strncmp(func, "dart::", 6) == 0) {
72 return func + 6; 72 return func + 6;
73 } else { 73 } else {
74 return func; 74 return func;
75 } 75 }
76 } 76 }
77 77
78 #ifndef PRODUCT 78 #ifndef PRODUCT
79 #define API_TIMELINE_DURATION \ 79 #define API_TIMELINE_DURATION \
80 TimelineDurationScope tds(Thread::Current(), \ 80 TimelineDurationScope tds(Thread::Current(), \
81 Timeline::GetVMApiStream(), \ 81 Timeline::GetAPIStream(), \
82 CURRENT_FUNC) 82 CURRENT_FUNC)
83 83
84 #define API_TIMELINE_BEGIN_END \ 84 #define API_TIMELINE_BEGIN_END \
85 TimelineBeginEndScope tbes(Thread::Current(), \ 85 TimelineBeginEndScope tbes(Thread::Current(), \
86 Timeline::GetVMApiStream(), \ 86 Timeline::GetAPIStream(), \
87 CURRENT_FUNC) 87 CURRENT_FUNC)
88 #else 88 #else
89 #define API_TIMELINE_DURATION do { } while (false) 89 #define API_TIMELINE_DURATION do { } while (false)
90 #define API_TIMELINE_BEGIN_END do { } while (false) 90 #define API_TIMELINE_BEGIN_END do { } while (false)
91 #endif // !PRODUCT 91 #endif // !PRODUCT
92 92
93 #if defined(DEBUG) 93 #if defined(DEBUG)
94 // An object visitor which will iterate over all the function objects in the 94 // An object visitor which will iterate over all the function objects in the
95 // heap and check if the result type and parameter types are canonicalized 95 // heap and check if the result type and parameter types are canonicalized
96 // or not. An assertion is raised if a type is not canonicalized. 96 // or not. An assertion is raised if a type is not canonicalized.
(...skipping 5671 matching lines...) Expand 10 before | Expand all | Expand 10 after
5768 return Api::Success(); 5768 return Api::Success();
5769 #endif // defined(PRODUCT) 5769 #endif // defined(PRODUCT)
5770 } 5770 }
5771 5771
5772 5772
5773 DART_EXPORT int64_t Dart_TimelineGetMicros() { 5773 DART_EXPORT int64_t Dart_TimelineGetMicros() {
5774 return OS::GetCurrentMonotonicMicros(); 5774 return OS::GetCurrentMonotonicMicros();
5775 } 5775 }
5776 5776
5777 5777
5778 DART_EXPORT void Dart_TimelineSetRecordedStreams(int64_t stream_mask) {
5779 if (!FLAG_support_timeline) {
5780 return;
5781 }
5782 Isolate* isolate = Isolate::Current();
5783 CHECK_ISOLATE(isolate);
5784 isolate->GetAPIStream()->set_enabled(
5785 (stream_mask & DART_TIMELINE_STREAM_API) != 0);
5786 isolate->GetCompilerStream()->set_enabled(
5787 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0);
5788 isolate->GetDartStream()->set_enabled(
5789 (stream_mask & DART_TIMELINE_STREAM_DART) != 0);
5790 isolate->GetDebuggerStream()->set_enabled(
5791 (stream_mask & DART_TIMELINE_STREAM_DEBUGGER) != 0);
5792 isolate->GetEmbedderStream()->set_enabled(
5793 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0);
5794 isolate->GetGCStream()->set_enabled(
5795 (stream_mask & DART_TIMELINE_STREAM_GC) != 0);
5796 isolate->GetIsolateStream()->set_enabled(
5797 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0);
5798 }
5799
5800
5801 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { 5778 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) {
5802 // Per isolate overrides.
5803 if (!FLAG_support_timeline) { 5779 if (!FLAG_support_timeline) {
5804 return; 5780 return;
5805 } 5781 }
5806 const bool api_enabled = (stream_mask & DART_TIMELINE_STREAM_API) != 0; 5782 const bool api_enabled = (stream_mask & DART_TIMELINE_STREAM_API) != 0;
5807 const bool compiler_enabled = 5783 const bool compiler_enabled =
5808 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0; 5784 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0;
5809 const bool dart_enabled = 5785 const bool dart_enabled =
5810 (stream_mask & DART_TIMELINE_STREAM_DART) != 0; 5786 (stream_mask & DART_TIMELINE_STREAM_DART) != 0;
5811 const bool debugger_enabled = 5787 const bool debugger_enabled =
5812 (stream_mask & DART_TIMELINE_STREAM_DEBUGGER) != 0; 5788 (stream_mask & DART_TIMELINE_STREAM_DEBUGGER) != 0;
5813 const bool embedder_enabled = 5789 const bool embedder_enabled =
5814 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0; 5790 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0;
5815 const bool gc_enabled = (stream_mask & DART_TIMELINE_STREAM_GC) != 0; 5791 const bool gc_enabled = (stream_mask & DART_TIMELINE_STREAM_GC) != 0;
5816 const bool isolate_enabled = 5792 const bool isolate_enabled =
5817 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0; 5793 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0;
5794 const bool vm_enabled =
5795 (stream_mask & DART_TIMELINE_STREAM_VM) != 0;
5818 Timeline::SetStreamAPIEnabled(api_enabled); 5796 Timeline::SetStreamAPIEnabled(api_enabled);
5819 Timeline::SetStreamCompilerEnabled(compiler_enabled); 5797 Timeline::SetStreamCompilerEnabled(compiler_enabled);
5820 Timeline::SetStreamDartEnabled(dart_enabled); 5798 Timeline::SetStreamDartEnabled(dart_enabled);
5821 Timeline::SetStreamDebuggerEnabled(debugger_enabled); 5799 Timeline::SetStreamDebuggerEnabled(debugger_enabled);
5822 Timeline::SetStreamEmbedderEnabled(embedder_enabled); 5800 Timeline::SetStreamEmbedderEnabled(embedder_enabled);
5823 Timeline::SetStreamGCEnabled(gc_enabled); 5801 Timeline::SetStreamGCEnabled(gc_enabled);
5824 Timeline::SetStreamIsolateEnabled(isolate_enabled); 5802 Timeline::SetStreamIsolateEnabled(isolate_enabled);
5825 // VM wide. 5803 Timeline::SetStreamVMEnabled(vm_enabled);
5826 const bool vm_enabled =
5827 (stream_mask & DART_TIMELINE_STREAM_VM) != 0;
5828 Timeline::GetVMStream()->set_enabled(vm_enabled);
5829 } 5804 }
5830 5805
5831 5806
5832 static void StartStreamToConsumer(Dart_StreamConsumer consumer, 5807 static void StartStreamToConsumer(Dart_StreamConsumer consumer,
5833 void* user_data, 5808 void* user_data,
5834 const char* stream_name) { 5809 const char* stream_name) {
5835 // Start stream. 5810 // Start stream.
5836 consumer(Dart_StreamConsumer_kStart, 5811 consumer(Dart_StreamConsumer_kStart,
5837 stream_name, 5812 stream_name,
5838 NULL, 5813 NULL,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
5917 output_length, 5892 output_length,
5918 "timeline"); 5893 "timeline");
5919 5894
5920 // We stole the JSONStream's output buffer, free it. 5895 // We stole the JSONStream's output buffer, free it.
5921 free(output); 5896 free(output);
5922 5897
5923 return true; 5898 return true;
5924 } 5899 }
5925 5900
5926 5901
5927 DART_EXPORT bool Dart_TimelineGetTrace(Dart_StreamConsumer consumer,
5928 void* user_data) {
5929 if (!FLAG_support_timeline) {
5930 return false;
5931 }
5932 Isolate* isolate = Isolate::Current();
5933 CHECK_ISOLATE(isolate);
5934 if (consumer == NULL) {
5935 return false;
5936 }
5937 TimelineEventRecorder* timeline_recorder = Timeline::recorder();
5938 if (timeline_recorder == NULL) {
5939 // Nothing has been recorded.
5940 return false;
5941 }
5942 Thread* T = Thread::Current();
5943 StackZone zone(T);
5944 Timeline::ReclaimCachedBlocksFromThreads();
5945 JSONStream js;
5946 IsolateTimelineEventFilter filter(isolate->main_port());
5947 timeline_recorder->PrintTraceEvent(&js, &filter);
5948 StartStreamToConsumer(consumer, user_data, "timeline");
5949 bool success = StreamTraceEvents(consumer, user_data, &js);
5950 FinishStreamToConsumer(consumer, user_data, "timeline");
5951 return success;
5952 }
5953
5954
5955 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( 5902 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks(
5956 Dart_EmbedderTimelineStartRecording start_recording, 5903 Dart_EmbedderTimelineStartRecording start_recording,
5957 Dart_EmbedderTimelineStopRecording stop_recording, 5904 Dart_EmbedderTimelineStopRecording stop_recording) {
5958 Dart_EmbedderTimelineGetTimeline get_timeline) {
5959 if (!FLAG_support_timeline) { 5905 if (!FLAG_support_timeline) {
5960 return; 5906 return;
5961 } 5907 }
5962 Timeline::set_start_recording_cb(start_recording); 5908 Timeline::set_start_recording_cb(start_recording);
5963 Timeline::set_stop_recording_cb(stop_recording); 5909 Timeline::set_stop_recording_cb(stop_recording);
5964 Timeline::set_get_timeline_cb(get_timeline);
5965 } 5910 }
5966 5911
5967 5912
5968 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer, 5913 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer,
5969 void* user_data) { 5914 void* user_data) {
5970 if (!FLAG_support_timeline) { 5915 if (!FLAG_support_timeline) {
5971 return false; 5916 return false;
5972 } 5917 }
5973 // To support various embedders, it must be possible to call this function 5918 // To support various embedders, it must be possible to call this function
5974 // from a thread for which we have not entered an Isolate and set up a Thread 5919 // from a thread for which we have not entered an Isolate and set up a Thread
(...skipping 14 matching lines...) Expand all
5989 timeline_recorder->PrintTraceEvent(&js, &filter); 5934 timeline_recorder->PrintTraceEvent(&js, &filter);
5990 StartStreamToConsumer(consumer, user_data, "timeline"); 5935 StartStreamToConsumer(consumer, user_data, "timeline");
5991 if (StreamTraceEvents(consumer, user_data, &js)) { 5936 if (StreamTraceEvents(consumer, user_data, &js)) {
5992 success = true; 5937 success = true;
5993 } 5938 }
5994 FinishStreamToConsumer(consumer, user_data, "timeline"); 5939 FinishStreamToConsumer(consumer, user_data, "timeline");
5995 return success; 5940 return success;
5996 } 5941 }
5997 5942
5998 5943
5999 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, 5944 DART_EXPORT void Dart_TimelineEvent(const char* label,
6000 int64_t start_micros, 5945 int64_t timestamp0,
6001 int64_t end_micros) { 5946 int64_t timestamp1,
5947 Dart_Timeline_Event_Type type,
5948 intptr_t argument_count,
5949 const char** argument_names,
5950 const char** argument_values) {
6002 if (!FLAG_support_timeline) { 5951 if (!FLAG_support_timeline) {
6003 return Api::Success(); 5952 return;
6004 } 5953 }
6005 Isolate* isolate = Isolate::Current(); 5954 if (type < Dart_Timeline_Event_Begin) {
6006 CHECK_ISOLATE(isolate); 5955 return;
6007 if (label == NULL) { 5956 }
6008 RETURN_NULL_ERROR(label); 5957 if (type > Dart_Timeline_Event_Duration) {
5958 return;
5959 }
5960 TimelineStream* stream = Timeline::GetEmbedderStream();
5961 ASSERT(stream != NULL);
5962 TimelineEvent* event = stream->StartEvent();
5963 if (event == NULL) {
5964 return;
5965 }
5966 switch (type) {
5967 case Dart_Timeline_Event_Begin:
5968 event->Begin(label, timestamp0);
5969 break;
5970 case Dart_Timeline_Event_End:
5971 event->End(label, timestamp0);
5972 break;
5973 case Dart_Timeline_Event_Instant:
5974 event->Instant(label, timestamp0);
5975 break;
5976 case Dart_Timeline_Event_Duration:
5977 event->Duration(label, timestamp0, timestamp1);
5978 break;
5979 default:
5980 FATAL("Unknown Dart_Timeline_Event_Type");
5981 }
5982 event->SetNumArguments(argument_count);
5983 for (intptr_t i = 0; i < argument_count; i++) {
5984 event->CopyArgument(i, argument_names[i], argument_values[i]);
5985 }
5986 event->Complete();
5987 }
5988
5989
5990 DART_EXPORT void Dart_TimelineDuration(const char* label,
5991 int64_t start_micros,
5992 int64_t end_micros) {
5993 if (!FLAG_support_timeline) {
5994 return;
6009 } 5995 }
6010 if (start_micros > end_micros) { 5996 if (start_micros > end_micros) {
6011 const char* msg = "%s: start_micros must be <= end_micros"; 5997 FATAL1("%s: start_micros must be <= end_micros", CURRENT_FUNC);
6012 return Api::NewError(msg, CURRENT_FUNC);
6013 } 5998 }
6014 TimelineStream* stream = isolate->GetEmbedderStream(); 5999 if (label == NULL) {
6000 return;
6001 }
6002 TimelineStream* stream = Timeline::GetEmbedderStream();
6015 ASSERT(stream != NULL); 6003 ASSERT(stream != NULL);
6016 TimelineEvent* event = stream->StartEvent(); 6004 TimelineEvent* event = stream->StartEvent();
6017 if (event != NULL) { 6005 if (event != NULL) {
6018 event->Duration(label, start_micros, end_micros); 6006 event->Duration(label, start_micros, end_micros);
6019 event->Complete(); 6007 event->Complete();
6020 } 6008 }
6021 return Api::Success();
6022 } 6009 }
6023 6010
6024 6011
6025 DART_EXPORT Dart_Handle Dart_TimelineInstant(const char* label) { 6012 DART_EXPORT void Dart_TimelineInstant(const char* label) {
6026 if (!FLAG_support_timeline) { 6013 if (!FLAG_support_timeline) {
6027 return Api::Success(); 6014 return;
6028 } 6015 }
6029 Isolate* isolate = Isolate::Current();
6030 CHECK_ISOLATE(isolate);
6031 if (label == NULL) { 6016 if (label == NULL) {
6032 RETURN_NULL_ERROR(label); 6017 return;
6033 } 6018 }
6034 TimelineStream* stream = isolate->GetEmbedderStream(); 6019 TimelineStream* stream = Timeline::GetEmbedderStream();
6035 ASSERT(stream != NULL); 6020 ASSERT(stream != NULL);
6036 TimelineEvent* event = stream->StartEvent(); 6021 TimelineEvent* event = stream->StartEvent();
6037 if (event != NULL) { 6022 if (event != NULL) {
6038 event->Instant(label); 6023 event->Instant(label);
6039 event->Complete(); 6024 event->Complete();
6040 } 6025 }
6041 return Api::Success(); 6026 return;
6042 } 6027 }
6043 6028
6044 6029
6045 DART_EXPORT Dart_Handle Dart_TimelineAsyncBegin(const char* label, 6030 DART_EXPORT void Dart_TimelineAsyncBegin(const char* label,
6046 int64_t* async_id) { 6031 int64_t* async_id) {
6047 if (!FLAG_support_timeline) { 6032 if (!FLAG_support_timeline) {
6048 return Api::Success(); 6033 return;
6049 } 6034 }
6050 Isolate* isolate = Isolate::Current();
6051 CHECK_ISOLATE(isolate);
6052 if (label == NULL) { 6035 if (label == NULL) {
6053 RETURN_NULL_ERROR(label); 6036 return;
6054 } 6037 }
6055 if (async_id == NULL) { 6038 if (async_id == NULL) {
6056 RETURN_NULL_ERROR(async_id); 6039 return;
6057 } 6040 }
6058 *async_id = -1; 6041 *async_id = -1;
6059 TimelineStream* stream = isolate->GetEmbedderStream(); 6042 TimelineStream* stream = Timeline::GetEmbedderStream();
6060 ASSERT(stream != NULL); 6043 ASSERT(stream != NULL);
6061 TimelineEvent* event = stream->StartEvent(); 6044 TimelineEvent* event = stream->StartEvent();
6062 if (event != NULL) { 6045 if (event != NULL) {
6063 TimelineEventRecorder* recorder = Timeline::recorder(); 6046 TimelineEventRecorder* recorder = Timeline::recorder();
6064 ASSERT(recorder != NULL); 6047 ASSERT(recorder != NULL);
6065 *async_id = recorder->GetNextAsyncId(); 6048 *async_id = recorder->GetNextAsyncId();
6066 event->AsyncBegin(label, *async_id); 6049 event->AsyncBegin(label, *async_id);
6067 event->Complete(); 6050 event->Complete();
6068 } 6051 }
6069 return Api::Success(); 6052 return;
6070 } 6053 }
6071 6054
6072 6055
6073 DART_EXPORT Dart_Handle Dart_TimelineAsyncInstant(const char* label, 6056 DART_EXPORT void Dart_TimelineAsyncInstant(const char* label,
6074 int64_t async_id) { 6057 int64_t async_id) {
6075 if (!FLAG_support_timeline) { 6058 if (!FLAG_support_timeline) {
6076 return Api::Success(); 6059 return;
6077 } 6060 }
6078 if (async_id < 0) { 6061 if (async_id < 0) {
6079 return Api::Success(); 6062 return;
6080 } 6063 }
6081 Isolate* isolate = Isolate::Current();
6082 CHECK_ISOLATE(isolate);
6083 if (label == NULL) { 6064 if (label == NULL) {
6084 RETURN_NULL_ERROR(label); 6065 return;
6085 } 6066 }
6086 TimelineStream* stream = isolate->GetEmbedderStream(); 6067 TimelineStream* stream = Timeline::GetEmbedderStream();
6087 ASSERT(stream != NULL); 6068 ASSERT(stream != NULL);
6088 TimelineEvent* event = stream->StartEvent(); 6069 TimelineEvent* event = stream->StartEvent();
6089 if (event != NULL) { 6070 if (event != NULL) {
6090 event->AsyncInstant(label, async_id); 6071 event->AsyncInstant(label, async_id);
6091 event->Complete(); 6072 event->Complete();
6092 } 6073 }
6093 return Api::Success(); 6074 return;
6094 } 6075 }
6095 6076
6096 6077
6097 DART_EXPORT Dart_Handle Dart_TimelineAsyncEnd(const char* label, 6078 DART_EXPORT void Dart_TimelineAsyncEnd(const char* label,
6098 int64_t async_id) { 6079 int64_t async_id) {
6099 if (!FLAG_support_timeline) { 6080 if (!FLAG_support_timeline) {
6100 return Api::Success(); 6081 return;
6101 } 6082 }
6102 if (async_id < 0) { 6083 if (async_id < 0) {
6103 return Api::Success(); 6084 return;
6104 } 6085 }
6105 Isolate* isolate = Isolate::Current();
6106 CHECK_ISOLATE(isolate);
6107 if (label == NULL) { 6086 if (label == NULL) {
6108 RETURN_NULL_ERROR(label); 6087 return;
6109 } 6088 }
6110 TimelineStream* stream = isolate->GetEmbedderStream(); 6089 TimelineStream* stream = Timeline::GetEmbedderStream();
6111 ASSERT(stream != NULL); 6090 ASSERT(stream != NULL);
6112 TimelineEvent* event = stream->StartEvent(); 6091 TimelineEvent* event = stream->StartEvent();
6113 if (event != NULL) { 6092 if (event != NULL) {
6114 event->AsyncEnd(label, async_id); 6093 event->AsyncEnd(label, async_id);
6115 event->Complete(); 6094 event->Complete();
6116 } 6095 }
6117 return Api::Success(); 6096 return;
6118 } 6097 }
6119 6098
6120 // The precompiler is included in dart_bootstrap and dart_noopt, and 6099 // The precompiler is included in dart_bootstrap and dart_noopt, and
6121 // excluded from dart and dart_precompiled_runtime. 6100 // excluded from dart and dart_precompiled_runtime.
6122 #if !defined(DART_PRECOMPILER) 6101 #if !defined(DART_PRECOMPILER)
6123 6102
6124 DART_EXPORT Dart_Handle Dart_Precompile( 6103 DART_EXPORT Dart_Handle Dart_Precompile(
6125 Dart_QualifiedFunctionName entry_points[], 6104 Dart_QualifiedFunctionName entry_points[],
6126 bool reset_fields) { 6105 bool reset_fields) {
6127 UNREACHABLE(); 6106 UNREACHABLE();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
6215 return Api::Success(); 6194 return Api::Success();
6216 } 6195 }
6217 #endif // DART_PRECOMPILER 6196 #endif // DART_PRECOMPILER
6218 6197
6219 6198
6220 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { 6199 DART_EXPORT bool Dart_IsRunningPrecompiledCode() {
6221 return Dart::IsRunningPrecompiledCode(); 6200 return Dart::IsRunningPrecompiledCode();
6222 } 6201 }
6223 6202
6224 } // namespace dart 6203 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698