OLD | NEW |
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 5872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5883 cursor += remaining; | 5883 cursor += remaining; |
5884 remaining -= remaining; | 5884 remaining -= remaining; |
5885 } | 5885 } |
5886 ASSERT(cursor == output_length); | 5886 ASSERT(cursor == output_length); |
5887 ASSERT(remaining == 0); | 5887 ASSERT(remaining == 0); |
5888 } | 5888 } |
5889 | 5889 |
5890 | 5890 |
5891 static bool StreamTraceEvents(Dart_StreamConsumer consumer, | 5891 static bool StreamTraceEvents(Dart_StreamConsumer consumer, |
5892 void* user_data, | 5892 void* user_data, |
5893 JSONStream* js) { | 5893 JSONStream* js, |
| 5894 bool insert_comma) { |
5894 ASSERT(js != NULL); | 5895 ASSERT(js != NULL); |
5895 // Steal output from JSONStream. | 5896 // Steal output from JSONStream. |
5896 char* output = NULL; | 5897 char* output = NULL; |
5897 intptr_t output_length = 0; | 5898 intptr_t output_length = 0; |
5898 js->Steal(const_cast<const char**>(&output), &output_length); | 5899 js->Steal(const_cast<const char**>(&output), &output_length); |
5899 if (output_length < 3) { | 5900 if (output_length < 3) { |
5900 // Empty JSON array. | 5901 // Empty JSON array. |
5901 free(output); | 5902 free(output); |
5902 return false; | 5903 return false; |
5903 } | 5904 } |
5904 // We want to send the JSON array without the leading '[' or trailing ']' | 5905 // We want to send the JSON array without the leading '[' or trailing ']' |
5905 // characters. | 5906 // characters. |
5906 ASSERT(output[0] == '['); | 5907 ASSERT(output[0] == '['); |
5907 ASSERT(output[output_length - 1] == ']'); | 5908 ASSERT(output[output_length - 1] == ']'); |
5908 // Replace the ']' with the null character. | 5909 // Replace the ']' with the null character. |
5909 output[output_length - 1] = '\0'; | 5910 output[output_length - 1] = '\0'; |
5910 // We are skipping the '['. | 5911 char* start = &output[1]; |
5911 output_length -= 1; | 5912 if (insert_comma) { |
5912 | 5913 output[0] = ','; |
5913 // Start the stream. | 5914 start = &output[0]; |
5914 StartStreamToConsumer(consumer, user_data, "timeline"); | 5915 } else { |
| 5916 // We are skipping the '['. |
| 5917 output_length -= 1; |
| 5918 } |
5915 | 5919 |
5916 DataStreamToConsumer(consumer, | 5920 DataStreamToConsumer(consumer, |
5917 user_data, | 5921 user_data, |
5918 &output[1], | 5922 start, |
5919 output_length, | 5923 output_length, |
5920 "timeline"); | 5924 "timeline"); |
5921 | 5925 |
5922 // We stole the JSONStream's output buffer, free it. | 5926 // We stole the JSONStream's output buffer, free it. |
5923 free(output); | 5927 free(output); |
5924 | 5928 |
5925 // Finish the stream. | |
5926 FinishStreamToConsumer(consumer, user_data, "timeline"); | |
5927 return true; | 5929 return true; |
5928 } | 5930 } |
5929 | 5931 |
5930 | 5932 |
5931 DART_EXPORT bool Dart_TimelineGetTrace(Dart_StreamConsumer consumer, | 5933 DART_EXPORT bool Dart_TimelineGetTrace(Dart_StreamConsumer consumer, |
5932 void* user_data) { | 5934 void* user_data) { |
5933 if (!FLAG_support_timeline) { | 5935 if (!FLAG_support_timeline) { |
5934 return false; | 5936 return false; |
5935 } | 5937 } |
5936 Isolate* isolate = Isolate::Current(); | 5938 Isolate* isolate = Isolate::Current(); |
5937 CHECK_ISOLATE(isolate); | 5939 CHECK_ISOLATE(isolate); |
5938 if (consumer == NULL) { | 5940 if (consumer == NULL) { |
5939 return false; | 5941 return false; |
5940 } | 5942 } |
5941 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); | 5943 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); |
5942 if (timeline_recorder == NULL) { | 5944 if (timeline_recorder == NULL) { |
5943 // Nothing has been recorded. | 5945 // Nothing has been recorded. |
5944 return false; | 5946 return false; |
5945 } | 5947 } |
5946 Thread* T = Thread::Current(); | 5948 Thread* T = Thread::Current(); |
5947 StackZone zone(T); | 5949 StackZone zone(T); |
5948 Timeline::ReclaimCachedBlocksFromThreads(); | 5950 Timeline::ReclaimCachedBlocksFromThreads(); |
5949 JSONStream js; | 5951 JSONStream js; |
5950 IsolateTimelineEventFilter filter(isolate->main_port()); | 5952 IsolateTimelineEventFilter filter(isolate->main_port()); |
5951 timeline_recorder->PrintTraceEvent(&js, &filter); | 5953 timeline_recorder->PrintTraceEvent(&js, &filter); |
5952 return StreamTraceEvents(consumer, user_data, &js); | 5954 StartStreamToConsumer(consumer, user_data, "timeline"); |
| 5955 bool success = StreamTraceEvents(consumer, user_data, &js, false); |
| 5956 FinishStreamToConsumer(consumer, user_data, "timeline"); |
| 5957 return success; |
5953 } | 5958 } |
5954 | 5959 |
5955 | 5960 |
| 5961 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( |
| 5962 Dart_EmbedderTimelineStartRecording start_recording, |
| 5963 Dart_EmbedderTimelineStopRecording stop_recording, |
| 5964 Dart_EmbedderTimelineGetTimeline get_timeline) { |
| 5965 Timeline::set_start_recording_cb(start_recording); |
| 5966 Timeline::set_stop_recording_cb(stop_recording); |
| 5967 Timeline::set_get_timeline_cb(get_timeline); |
| 5968 } |
| 5969 |
| 5970 |
5956 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer, | 5971 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer, |
5957 void* user_data) { | 5972 void* user_data) { |
5958 if (!FLAG_support_timeline) { | 5973 if (!FLAG_support_timeline) { |
5959 return false; | 5974 return false; |
5960 } | 5975 } |
5961 // To support various embedders, it must be possible to call this function | 5976 // To support various embedders, it must be possible to call this function |
5962 // from a thread for which we have not entered an Isolate and set up a Thread | 5977 // from a thread for which we have not entered an Isolate and set up a Thread |
5963 // TLS object. Therefore, a Zone may not be available, a StackZone cannot be | 5978 // TLS object. Therefore, a Zone may not be available, a StackZone cannot be |
5964 // created, and no ZoneAllocated objects can be allocated. | 5979 // created, and no ZoneAllocated objects can be allocated. |
5965 if (consumer == NULL) { | 5980 if (consumer == NULL) { |
5966 return false; | 5981 return false; |
5967 } | 5982 } |
5968 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); | 5983 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); |
5969 if (timeline_recorder == NULL) { | 5984 if (timeline_recorder == NULL) { |
5970 // Nothing has been recorded. | 5985 // Nothing has been recorded. |
5971 return false; | 5986 return false; |
5972 } | 5987 } |
5973 Timeline::ReclaimCachedBlocksFromThreads(); | 5988 Timeline::ReclaimCachedBlocksFromThreads(); |
5974 JSONStream js; | 5989 JSONStream js; |
5975 TimelineEventFilter filter; | 5990 TimelineEventFilter filter; |
5976 timeline_recorder->PrintTraceEvent(&js, &filter); | 5991 timeline_recorder->PrintTraceEvent(&js, &filter); |
5977 return StreamTraceEvents(consumer, user_data, &js); | 5992 StartStreamToConsumer(consumer, user_data, "timeline"); |
| 5993 bool success = false; |
| 5994 if (Timeline::get_get_timeline_cb() != NULL) { |
| 5995 if (Timeline::get_get_timeline_cb()(consumer, user_data)) { |
| 5996 success = true; |
| 5997 } |
| 5998 } |
| 5999 if (StreamTraceEvents(consumer, user_data, &js, success)) { |
| 6000 success = true; |
| 6001 } |
| 6002 FinishStreamToConsumer(consumer, user_data, "timeline"); |
| 6003 return success; |
5978 } | 6004 } |
5979 | 6005 |
5980 | 6006 |
5981 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, | 6007 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, |
5982 int64_t start_micros, | 6008 int64_t start_micros, |
5983 int64_t end_micros) { | 6009 int64_t end_micros) { |
5984 if (!FLAG_support_timeline) { | 6010 if (!FLAG_support_timeline) { |
5985 return Api::Success(); | 6011 return Api::Success(); |
5986 } | 6012 } |
5987 Isolate* isolate = Isolate::Current(); | 6013 Isolate* isolate = Isolate::Current(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6092 TimelineStream* stream = isolate->GetEmbedderStream(); | 6118 TimelineStream* stream = isolate->GetEmbedderStream(); |
6093 ASSERT(stream != NULL); | 6119 ASSERT(stream != NULL); |
6094 TimelineEvent* event = stream->StartEvent(); | 6120 TimelineEvent* event = stream->StartEvent(); |
6095 if (event != NULL) { | 6121 if (event != NULL) { |
6096 event->AsyncEnd(label, async_id); | 6122 event->AsyncEnd(label, async_id); |
6097 event->Complete(); | 6123 event->Complete(); |
6098 } | 6124 } |
6099 return Api::Success(); | 6125 return Api::Success(); |
6100 } | 6126 } |
6101 | 6127 |
6102 | |
6103 // The precompiler is included in dart_bootstrap and dart_noopt, and | 6128 // The precompiler is included in dart_bootstrap and dart_noopt, and |
6104 // excluded from dart and dart_precompiled_runtime. | 6129 // excluded from dart and dart_precompiled_runtime. |
6105 #if !defined(DART_PRECOMPILER) | 6130 #if !defined(DART_PRECOMPILER) |
6106 | 6131 |
6107 DART_EXPORT Dart_Handle Dart_Precompile( | 6132 DART_EXPORT Dart_Handle Dart_Precompile( |
6108 Dart_QualifiedFunctionName entry_points[], | 6133 Dart_QualifiedFunctionName entry_points[], |
6109 bool reset_fields) { | 6134 bool reset_fields) { |
6110 UNREACHABLE(); | 6135 UNREACHABLE(); |
6111 return 0; | 6136 return 0; |
6112 } | 6137 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6198 return Api::Success(); | 6223 return Api::Success(); |
6199 } | 6224 } |
6200 #endif // DART_PRECOMPILER | 6225 #endif // DART_PRECOMPILER |
6201 | 6226 |
6202 | 6227 |
6203 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { | 6228 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { |
6204 return Dart::IsRunningPrecompiledCode(); | 6229 return Dart::IsRunningPrecompiledCode(); |
6205 } | 6230 } |
6206 | 6231 |
6207 } // namespace dart | 6232 } // namespace dart |
OLD | NEW |