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) { | |
5895 ASSERT(js != NULL); | 5894 ASSERT(js != NULL); |
5896 // Steal output from JSONStream. | 5895 // Steal output from JSONStream. |
5897 char* output = NULL; | 5896 char* output = NULL; |
5898 intptr_t output_length = 0; | 5897 intptr_t output_length = 0; |
5899 js->Steal(const_cast<const char**>(&output), &output_length); | 5898 js->Steal(const_cast<const char**>(&output), &output_length); |
5900 if (output_length < 3) { | 5899 if (output_length < 3) { |
5901 // Empty JSON array. | 5900 // Empty JSON array. |
5902 free(output); | 5901 free(output); |
5903 return false; | 5902 return false; |
5904 } | 5903 } |
5905 // We want to send the JSON array without the leading '[' or trailing ']' | 5904 // We want to send the JSON array without the leading '[' or trailing ']' |
5906 // characters. | 5905 // characters. |
5907 ASSERT(output[0] == '['); | 5906 ASSERT(output[0] == '['); |
5908 ASSERT(output[output_length - 1] == ']'); | 5907 ASSERT(output[output_length - 1] == ']'); |
5909 // Replace the ']' with the null character. | 5908 // Replace the ']' with the null character. |
5910 output[output_length - 1] = '\0'; | 5909 output[output_length - 1] = '\0'; |
5911 char* start = &output[1]; | 5910 char* start = &output[1]; |
5912 if (insert_comma) { | 5911 // We are skipping the '['. |
5913 output[0] = ','; | 5912 output_length -= 1; |
5914 start = &output[0]; | |
5915 } else { | |
5916 // We are skipping the '['. | |
5917 output_length -= 1; | |
5918 } | |
5919 | 5913 |
5920 DataStreamToConsumer(consumer, | 5914 DataStreamToConsumer(consumer, |
5921 user_data, | 5915 user_data, |
5922 start, | 5916 start, |
5923 output_length, | 5917 output_length, |
5924 "timeline"); | 5918 "timeline"); |
5925 | 5919 |
5926 // We stole the JSONStream's output buffer, free it. | 5920 // We stole the JSONStream's output buffer, free it. |
5927 free(output); | 5921 free(output); |
5928 | 5922 |
(...skipping 16 matching lines...) Expand all Loading... |
5945 // Nothing has been recorded. | 5939 // Nothing has been recorded. |
5946 return false; | 5940 return false; |
5947 } | 5941 } |
5948 Thread* T = Thread::Current(); | 5942 Thread* T = Thread::Current(); |
5949 StackZone zone(T); | 5943 StackZone zone(T); |
5950 Timeline::ReclaimCachedBlocksFromThreads(); | 5944 Timeline::ReclaimCachedBlocksFromThreads(); |
5951 JSONStream js; | 5945 JSONStream js; |
5952 IsolateTimelineEventFilter filter(isolate->main_port()); | 5946 IsolateTimelineEventFilter filter(isolate->main_port()); |
5953 timeline_recorder->PrintTraceEvent(&js, &filter); | 5947 timeline_recorder->PrintTraceEvent(&js, &filter); |
5954 StartStreamToConsumer(consumer, user_data, "timeline"); | 5948 StartStreamToConsumer(consumer, user_data, "timeline"); |
5955 bool success = StreamTraceEvents(consumer, user_data, &js, false); | 5949 bool success = StreamTraceEvents(consumer, user_data, &js); |
5956 FinishStreamToConsumer(consumer, user_data, "timeline"); | 5950 FinishStreamToConsumer(consumer, user_data, "timeline"); |
5957 return success; | 5951 return success; |
5958 } | 5952 } |
5959 | 5953 |
5960 | 5954 |
5961 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( | 5955 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( |
5962 Dart_EmbedderTimelineStartRecording start_recording, | 5956 Dart_EmbedderTimelineStartRecording start_recording, |
5963 Dart_EmbedderTimelineStopRecording stop_recording, | 5957 Dart_EmbedderTimelineStopRecording stop_recording, |
5964 Dart_EmbedderTimelineGetTimeline get_timeline) { | 5958 Dart_EmbedderTimelineGetTimeline get_timeline) { |
5965 if (!FLAG_support_timeline) { | 5959 if (!FLAG_support_timeline) { |
(...skipping 16 matching lines...) Expand all Loading... |
5982 // created, and no ZoneAllocated objects can be allocated. | 5976 // created, and no ZoneAllocated objects can be allocated. |
5983 if (consumer == NULL) { | 5977 if (consumer == NULL) { |
5984 return false; | 5978 return false; |
5985 } | 5979 } |
5986 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); | 5980 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); |
5987 if (timeline_recorder == NULL) { | 5981 if (timeline_recorder == NULL) { |
5988 // Nothing has been recorded. | 5982 // Nothing has been recorded. |
5989 return false; | 5983 return false; |
5990 } | 5984 } |
5991 Timeline::ReclaimCachedBlocksFromThreads(); | 5985 Timeline::ReclaimCachedBlocksFromThreads(); |
| 5986 bool success = false; |
5992 JSONStream js; | 5987 JSONStream js; |
5993 TimelineEventFilter filter; | 5988 TimelineEventFilter filter; |
5994 timeline_recorder->PrintTraceEvent(&js, &filter); | 5989 timeline_recorder->PrintTraceEvent(&js, &filter); |
5995 StartStreamToConsumer(consumer, user_data, "timeline"); | 5990 StartStreamToConsumer(consumer, user_data, "timeline"); |
5996 bool success = false; | 5991 if (StreamTraceEvents(consumer, user_data, &js)) { |
5997 if (Timeline::get_get_timeline_cb() != NULL) { | |
5998 if (Timeline::get_get_timeline_cb()(consumer, user_data)) { | |
5999 success = true; | |
6000 } | |
6001 } | |
6002 if (StreamTraceEvents(consumer, user_data, &js, success)) { | |
6003 success = true; | 5992 success = true; |
6004 } | 5993 } |
6005 FinishStreamToConsumer(consumer, user_data, "timeline"); | 5994 FinishStreamToConsumer(consumer, user_data, "timeline"); |
6006 return success; | 5995 return success; |
6007 } | 5996 } |
6008 | 5997 |
6009 | 5998 |
6010 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, | 5999 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, |
6011 int64_t start_micros, | 6000 int64_t start_micros, |
6012 int64_t end_micros) { | 6001 int64_t end_micros) { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6226 return Api::Success(); | 6215 return Api::Success(); |
6227 } | 6216 } |
6228 #endif // DART_PRECOMPILER | 6217 #endif // DART_PRECOMPILER |
6229 | 6218 |
6230 | 6219 |
6231 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { | 6220 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { |
6232 return Dart::IsRunningPrecompiledCode(); | 6221 return Dart::IsRunningPrecompiledCode(); |
6233 } | 6222 } |
6234 | 6223 |
6235 } // namespace dart | 6224 } // namespace dart |
OLD | NEW |