| 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 "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 5721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5732 Timeline::SetStreamEmbedderEnabled(embedder_enabled); | 5732 Timeline::SetStreamEmbedderEnabled(embedder_enabled); |
| 5733 Timeline::SetStreamGCEnabled(gc_enabled); | 5733 Timeline::SetStreamGCEnabled(gc_enabled); |
| 5734 Timeline::SetStreamIsolateEnabled(isolate_enabled); | 5734 Timeline::SetStreamIsolateEnabled(isolate_enabled); |
| 5735 // VM wide. | 5735 // VM wide. |
| 5736 const bool vm_enabled = | 5736 const bool vm_enabled = |
| 5737 (stream_mask & DART_TIMELINE_STREAM_VM) != 0; | 5737 (stream_mask & DART_TIMELINE_STREAM_VM) != 0; |
| 5738 Timeline::GetVMStream()->set_enabled(vm_enabled); | 5738 Timeline::GetVMStream()->set_enabled(vm_enabled); |
| 5739 } | 5739 } |
| 5740 | 5740 |
| 5741 | 5741 |
| 5742 // '[' + ']' + '\0'. | |
| 5743 #define MINIMUM_OUTPUT_LENGTH 3 | |
| 5744 | |
| 5745 // Trims the '[' and ']' characters and, depending on whether or not more events | |
| 5746 // will follow, adjusts the last character of the string to either a '\0' or | |
| 5747 // ','. | |
| 5748 static char* TrimOutput(char* output, | |
| 5749 intptr_t* output_length, | |
| 5750 bool events_will_follow) { | |
| 5751 ASSERT(output != NULL); | |
| 5752 ASSERT(output_length != NULL); | |
| 5753 ASSERT(*output_length > MINIMUM_OUTPUT_LENGTH); | |
| 5754 // We expect the first character to be the opening of an array. | |
| 5755 ASSERT(output[0] == '['); | |
| 5756 // We expect the last character to be the closing of an array. | |
| 5757 ASSERT(output[*output_length - 2] == ']'); | |
| 5758 if (events_will_follow) { | |
| 5759 // Replace array closing character (']') with ','. | |
| 5760 output[*output_length - 2] = ','; | |
| 5761 } else { | |
| 5762 // Replace array closing character (']') with '\0'. | |
| 5763 output[*output_length - 2] = '\0'; | |
| 5764 } | |
| 5765 // Skip the array opening character ('['). | |
| 5766 *output_length -= 2; | |
| 5767 return &output[1]; | |
| 5768 } | |
| 5769 | |
| 5770 | |
| 5771 static void StartStreamToConsumer(Dart_StreamConsumer consumer, | 5742 static void StartStreamToConsumer(Dart_StreamConsumer consumer, |
| 5772 void* user_data, | 5743 void* user_data, |
| 5773 const char* stream_name) { | 5744 const char* stream_name) { |
| 5774 // Start stream. | 5745 // Start stream. |
| 5775 consumer(Dart_StreamConsumer_kStart, | 5746 consumer(Dart_StreamConsumer_kStart, |
| 5776 stream_name, | 5747 stream_name, |
| 5777 NULL, | 5748 NULL, |
| 5778 0, | 5749 0, |
| 5779 user_data); | 5750 user_data); |
| 5780 } | 5751 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5822 cursor += remaining; | 5793 cursor += remaining; |
| 5823 remaining -= remaining; | 5794 remaining -= remaining; |
| 5824 } | 5795 } |
| 5825 ASSERT(cursor == output_length); | 5796 ASSERT(cursor == output_length); |
| 5826 ASSERT(remaining == 0); | 5797 ASSERT(remaining == 0); |
| 5827 } | 5798 } |
| 5828 | 5799 |
| 5829 | 5800 |
| 5830 static bool StreamTraceEvents(Dart_StreamConsumer consumer, | 5801 static bool StreamTraceEvents(Dart_StreamConsumer consumer, |
| 5831 void* user_data, | 5802 void* user_data, |
| 5832 JSONStream* js, | 5803 JSONStream* js) { |
| 5833 const char* dart_events) { | |
| 5834 ASSERT(js != NULL); | 5804 ASSERT(js != NULL); |
| 5835 // Steal output from JSONStream. | 5805 // Steal output from JSONStream. |
| 5836 char* output = NULL; | 5806 char* output = NULL; |
| 5837 intptr_t output_length = 0; | 5807 intptr_t output_length = 0; |
| 5838 js->Steal(const_cast<const char**>(&output), &output_length); | 5808 js->Steal(const_cast<const char**>(&output), &output_length); |
| 5839 | 5809 |
| 5840 const bool output_vm = output_length > MINIMUM_OUTPUT_LENGTH; | |
| 5841 const bool output_dart = dart_events != NULL; | |
| 5842 | |
| 5843 if (!output_vm && !output_dart) { | |
| 5844 // We stole the JSONStream's output buffer, free it. | |
| 5845 free(output); | |
| 5846 // Nothing will be emitted. | |
| 5847 return false; | |
| 5848 } | |
| 5849 | |
| 5850 // Start the stream. | 5810 // Start the stream. |
| 5851 StartStreamToConsumer(consumer, user_data, "timeline"); | 5811 StartStreamToConsumer(consumer, user_data, "timeline"); |
| 5852 | 5812 |
| 5853 // Send events from the VM. | 5813 DataStreamToConsumer(consumer, |
| 5854 if (output_vm) { | 5814 user_data, |
| 5855 // Add one for the '\0' character. | 5815 output, |
| 5856 output_length++; | 5816 output_length, |
| 5857 char* trimmed_output = TrimOutput(output, &output_length, output_dart); | 5817 "timeline"); |
| 5858 DataStreamToConsumer(consumer, user_data, | 5818 |
| 5859 trimmed_output, output_length, "timeline"); | |
| 5860 } | |
| 5861 // We stole the JSONStream's output buffer, free it. | 5819 // We stole the JSONStream's output buffer, free it. |
| 5862 free(output); | 5820 free(output); |
| 5863 | 5821 |
| 5864 // Send events from dart. | |
| 5865 if (output_dart) { | |
| 5866 const intptr_t dart_events_len = strlen(dart_events) + 1; // +1 for '\0'. | |
| 5867 DataStreamToConsumer(consumer, user_data, | |
| 5868 dart_events, dart_events_len, "timeline"); | |
| 5869 } | |
| 5870 | |
| 5871 // Finish the stream. | 5822 // Finish the stream. |
| 5872 FinishStreamToConsumer(consumer, user_data, "timeline"); | 5823 FinishStreamToConsumer(consumer, user_data, "timeline"); |
| 5873 return true; | 5824 return true; |
| 5874 } | 5825 } |
| 5875 | 5826 |
| 5876 | 5827 |
| 5877 DART_EXPORT bool Dart_TimelineGetTrace(Dart_StreamConsumer consumer, | 5828 DART_EXPORT bool Dart_TimelineGetTrace(Dart_StreamConsumer consumer, |
| 5878 void* user_data) { | 5829 void* user_data) { |
| 5879 Isolate* isolate = Isolate::Current(); | 5830 Isolate* isolate = Isolate::Current(); |
| 5880 CHECK_ISOLATE(isolate); | 5831 CHECK_ISOLATE(isolate); |
| 5881 if (consumer == NULL) { | 5832 if (consumer == NULL) { |
| 5882 return false; | 5833 return false; |
| 5883 } | 5834 } |
| 5884 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); | 5835 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); |
| 5885 if (timeline_recorder == NULL) { | 5836 if (timeline_recorder == NULL) { |
| 5886 // Nothing has been recorded. | 5837 // Nothing has been recorded. |
| 5887 return false; | 5838 return false; |
| 5888 } | 5839 } |
| 5889 Thread* T = Thread::Current(); | 5840 Thread* T = Thread::Current(); |
| 5890 StackZone zone(T); | 5841 StackZone zone(T); |
| 5891 Timeline::ReclaimCachedBlocksFromThreads(); | 5842 Timeline::ReclaimCachedBlocksFromThreads(); |
| 5892 JSONStream js; | 5843 JSONStream js; |
| 5893 IsolateTimelineEventFilter filter(isolate); | 5844 IsolateTimelineEventFilter filter(isolate->main_port()); |
| 5894 timeline_recorder->PrintTraceEvent(&js, &filter); | 5845 timeline_recorder->PrintTraceEvent(&js, &filter); |
| 5895 const char* dart_events = | 5846 return StreamTraceEvents(consumer, user_data, &js); |
| 5896 DartTimelineEventIterator::PrintTraceEvents(timeline_recorder, | |
| 5897 zone.GetZone(), | |
| 5898 isolate); | |
| 5899 return StreamTraceEvents(consumer, user_data, &js, dart_events); | |
| 5900 } | 5847 } |
| 5901 | 5848 |
| 5902 | 5849 |
| 5903 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer, | 5850 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer, |
| 5904 void* user_data) { | 5851 void* user_data) { |
| 5905 if (consumer == NULL) { | 5852 if (consumer == NULL) { |
| 5906 return false; | 5853 return false; |
| 5907 } | 5854 } |
| 5908 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); | 5855 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); |
| 5909 if (timeline_recorder == NULL) { | 5856 if (timeline_recorder == NULL) { |
| 5910 // Nothing has been recorded. | 5857 // Nothing has been recorded. |
| 5911 return false; | 5858 return false; |
| 5912 } | 5859 } |
| 5913 Thread* T = Thread::Current(); | 5860 Thread* T = Thread::Current(); |
| 5914 StackZone zone(T); | 5861 StackZone zone(T); |
| 5915 Timeline::ReclaimCachedBlocksFromThreads(); | 5862 Timeline::ReclaimCachedBlocksFromThreads(); |
| 5916 JSONStream js; | 5863 JSONStream js; |
| 5917 TimelineEventFilter filter; | 5864 TimelineEventFilter filter; |
| 5918 timeline_recorder->PrintTraceEvent(&js, &filter); | 5865 timeline_recorder->PrintTraceEvent(&js, &filter); |
| 5919 const char* dart_events = | 5866 return StreamTraceEvents(consumer, user_data, &js); |
| 5920 DartTimelineEventIterator::PrintTraceEvents(timeline_recorder, | |
| 5921 zone.GetZone(), | |
| 5922 NULL); | |
| 5923 return StreamTraceEvents(consumer, user_data, &js, dart_events); | |
| 5924 } | 5867 } |
| 5925 | 5868 |
| 5926 | 5869 |
| 5927 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, | 5870 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, |
| 5928 int64_t start_micros, | 5871 int64_t start_micros, |
| 5929 int64_t end_micros) { | 5872 int64_t end_micros) { |
| 5930 Isolate* isolate = Isolate::Current(); | 5873 Isolate* isolate = Isolate::Current(); |
| 5931 CHECK_ISOLATE(isolate); | 5874 CHECK_ISOLATE(isolate); |
| 5932 if (label == NULL) { | 5875 if (label == NULL) { |
| 5933 RETURN_NULL_ERROR(label); | 5876 RETURN_NULL_ERROR(label); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6088 ApiReallocate); | 6031 ApiReallocate); |
| 6089 writer.WriteFullSnapshot(); | 6032 writer.WriteFullSnapshot(); |
| 6090 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 6033 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
| 6091 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 6034 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
| 6092 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); | 6035 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); |
| 6093 | 6036 |
| 6094 return Api::Success(); | 6037 return Api::Success(); |
| 6095 } | 6038 } |
| 6096 | 6039 |
| 6097 } // namespace dart | 6040 } // namespace dart |
| OLD | NEW |