Chromium Code Reviews| 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 5662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5673 } | 5673 } |
| 5674 | 5674 |
| 5675 | 5675 |
| 5676 DART_EXPORT void Dart_TimelineSetRecordedStreams(int64_t stream_mask) { | 5676 DART_EXPORT void Dart_TimelineSetRecordedStreams(int64_t stream_mask) { |
| 5677 Isolate* isolate = Isolate::Current(); | 5677 Isolate* isolate = Isolate::Current(); |
| 5678 CHECK_ISOLATE(isolate); | 5678 CHECK_ISOLATE(isolate); |
| 5679 isolate->GetAPIStream()->set_enabled( | 5679 isolate->GetAPIStream()->set_enabled( |
| 5680 (stream_mask & DART_TIMELINE_STREAM_API) != 0); | 5680 (stream_mask & DART_TIMELINE_STREAM_API) != 0); |
| 5681 isolate->GetCompilerStream()->set_enabled( | 5681 isolate->GetCompilerStream()->set_enabled( |
| 5682 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0); | 5682 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0); |
| 5683 isolate->GetDartStream()->set_enabled( | |
| 5684 (stream_mask & DART_TIMELINE_STREAM_DART) != 0); | |
| 5683 isolate->GetEmbedderStream()->set_enabled( | 5685 isolate->GetEmbedderStream()->set_enabled( |
| 5684 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0); | 5686 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0); |
| 5685 isolate->GetGCStream()->set_enabled( | 5687 isolate->GetGCStream()->set_enabled( |
| 5686 (stream_mask & DART_TIMELINE_STREAM_GC) != 0); | 5688 (stream_mask & DART_TIMELINE_STREAM_GC) != 0); |
| 5687 isolate->GetIsolateStream()->set_enabled( | 5689 isolate->GetIsolateStream()->set_enabled( |
| 5688 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0); | 5690 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0); |
| 5689 } | 5691 } |
| 5690 | 5692 |
| 5691 | 5693 |
| 5692 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { | 5694 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { |
| 5693 // Per isolate overrides. | 5695 // Per isolate overrides. |
| 5694 const bool api_enabled = (stream_mask & DART_TIMELINE_STREAM_API) != 0; | 5696 const bool api_enabled = (stream_mask & DART_TIMELINE_STREAM_API) != 0; |
| 5695 const bool compiler_enabled = | 5697 const bool compiler_enabled = |
| 5696 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0; | 5698 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0; |
| 5699 const bool dart_enabled = | |
| 5700 (stream_mask & DART_TIMELINE_STREAM_DART) != 0; | |
| 5697 const bool embedder_enabled = | 5701 const bool embedder_enabled = |
| 5698 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0; | 5702 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0; |
| 5699 const bool gc_enabled = (stream_mask & DART_TIMELINE_STREAM_GC) != 0; | 5703 const bool gc_enabled = (stream_mask & DART_TIMELINE_STREAM_GC) != 0; |
| 5700 const bool isolate_enabled = | 5704 const bool isolate_enabled = |
| 5701 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0; | 5705 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0; |
| 5702 Timeline::SetStreamAPIEnabled(api_enabled); | 5706 Timeline::SetStreamAPIEnabled(api_enabled); |
| 5703 Timeline::SetStreamCompilerEnabled(compiler_enabled); | 5707 Timeline::SetStreamCompilerEnabled(compiler_enabled); |
| 5708 Timeline::SetStreamDartEnabled(dart_enabled); | |
| 5704 Timeline::SetStreamEmbedderEnabled(embedder_enabled); | 5709 Timeline::SetStreamEmbedderEnabled(embedder_enabled); |
| 5705 Timeline::SetStreamGCEnabled(gc_enabled); | 5710 Timeline::SetStreamGCEnabled(gc_enabled); |
| 5706 Timeline::SetStreamIsolateEnabled(isolate_enabled); | 5711 Timeline::SetStreamIsolateEnabled(isolate_enabled); |
| 5707 // VM wide. | 5712 // VM wide. |
| 5708 const bool vm_enabled = | 5713 const bool vm_enabled = |
| 5709 (stream_mask & DART_TIMELINE_STREAM_VM) != 0; | 5714 (stream_mask & DART_TIMELINE_STREAM_VM) != 0; |
| 5710 Timeline::GetVMStream()->set_enabled(vm_enabled); | 5715 Timeline::GetVMStream()->set_enabled(vm_enabled); |
| 5711 } | 5716 } |
| 5712 | 5717 |
| 5713 | 5718 |
| 5714 // '[' + ']' + '\0'. | 5719 // '[' + ']' + '\0'. |
| 5715 #define MINIMUM_OUTPUT_LENGTH 3 | 5720 #define MINIMUM_OUTPUT_LENGTH 3 |
| 5716 | 5721 |
| 5717 static void StreamToConsumer(Dart_StreamConsumer consumer, | 5722 // Trims the '[' and ']' characters and, depending on whether or not more events |
| 5718 void* user_data, | 5723 // will follow, adjusts the last character of the string to either a '\0' or |
| 5719 char* output, | 5724 // ','. |
| 5720 intptr_t output_length) { | 5725 static char* TrimOutput(char* output, |
| 5726 intptr_t* output_length, | |
| 5727 bool events_will_follow) { | |
| 5728 ASSERT(output != NULL); | |
| 5729 ASSERT(output_length != NULL); | |
| 5730 ASSERT(*output_length > MINIMUM_OUTPUT_LENGTH); | |
| 5731 // We expect the first character to be the opening of an array. | |
| 5732 ASSERT(output[0] == '['); | |
| 5733 // We expect the last character to be the closing of an array. | |
| 5734 ASSERT(output[*output_length - 2] == ']'); | |
| 5735 if (events_will_follow) { | |
| 5736 // Replace array closing character (']') with ','. | |
| 5737 output[*output_length - 2] = ','; | |
| 5738 } else { | |
| 5739 // Replace array closing character (']') with '\0'. | |
| 5740 output[*output_length - 2] = '\0'; | |
| 5741 } | |
| 5742 // Skip the array opening character ('['). | |
| 5743 *output_length -= 2; | |
| 5744 return &output[1]; | |
| 5745 } | |
| 5746 | |
| 5747 | |
| 5748 static void StartStreamToConsumer(Dart_StreamConsumer consumer, | |
| 5749 void* user_data, | |
| 5750 const char* stream_name) { | |
| 5751 // Start stream. | |
| 5752 consumer(Dart_StreamConsumer_kStart, | |
| 5753 stream_name, | |
| 5754 NULL, | |
| 5755 0, | |
| 5756 user_data); | |
| 5757 } | |
| 5758 | |
| 5759 | |
| 5760 static void FinishStreamToConsumer(Dart_StreamConsumer consumer, | |
| 5761 void* user_data, | |
| 5762 const char* stream_name) { | |
| 5763 // Finish stream. | |
| 5764 consumer(Dart_StreamConsumer_kFinish, | |
| 5765 stream_name, | |
| 5766 NULL, | |
| 5767 0, | |
| 5768 user_data); | |
| 5769 } | |
| 5770 | |
| 5771 | |
| 5772 static void DataStreamToConsumer(Dart_StreamConsumer consumer, | |
| 5773 void* user_data, | |
| 5774 const char* output, | |
| 5775 intptr_t output_length, | |
| 5776 const char* stream_name) { | |
| 5721 if (output == NULL) { | 5777 if (output == NULL) { |
| 5722 return; | 5778 return; |
| 5723 } | 5779 } |
| 5724 if (output_length <= MINIMUM_OUTPUT_LENGTH) { | 5780 // const intptr_t kDataSize = 64 * KB; |
|
rmacnak
2015/09/29 22:36:41
X
Cutch
2015/09/30 14:42:29
Done.
| |
| 5725 return; | 5781 const intptr_t kDataSize = 16; |
| 5726 } | 5782 intptr_t cursor = 0; |
| 5727 // We expect the first character to be the opening of an array. | 5783 intptr_t remaining = output_length; |
| 5728 ASSERT(output[0] == '['); | |
| 5729 // We expect the last character to be the closing of an array. | |
| 5730 ASSERT(output[output_length - 2] == ']'); | |
| 5731 // Start stream. | |
| 5732 const char* kStreamName = "timeline"; | |
| 5733 const intptr_t kDataSize = 64 * KB; | |
| 5734 consumer(Dart_StreamConsumer_kStart, | |
| 5735 kStreamName, | |
| 5736 NULL, | |
| 5737 0, | |
| 5738 user_data); | |
| 5739 | |
| 5740 // Stream out data. Skipping the array characters. | |
| 5741 // Replace array close with '\0'. | |
| 5742 output[output_length - 2] = '\0'; | |
| 5743 intptr_t cursor = 1; | |
| 5744 output_length -= 1; | |
| 5745 intptr_t remaining = output_length - 1; | |
| 5746 | |
| 5747 while (remaining >= kDataSize) { | 5784 while (remaining >= kDataSize) { |
| 5748 consumer(Dart_StreamConsumer_kData, | 5785 consumer(Dart_StreamConsumer_kData, |
| 5749 kStreamName, | 5786 stream_name, |
| 5750 reinterpret_cast<uint8_t*>(&output[cursor]), | 5787 reinterpret_cast<const uint8_t*>(&output[cursor]), |
| 5751 kDataSize, | 5788 kDataSize, |
| 5752 user_data); | 5789 user_data); |
| 5753 cursor += kDataSize; | 5790 cursor += kDataSize; |
| 5754 remaining -= kDataSize; | 5791 remaining -= kDataSize; |
| 5755 } | 5792 } |
| 5756 if (remaining > 0) { | 5793 if (remaining > 0) { |
| 5757 ASSERT(remaining < kDataSize); | 5794 ASSERT(remaining < kDataSize); |
| 5758 consumer(Dart_StreamConsumer_kData, | 5795 consumer(Dart_StreamConsumer_kData, |
| 5759 kStreamName, | 5796 stream_name, |
| 5760 reinterpret_cast<uint8_t*>(&output[cursor]), | 5797 reinterpret_cast<const uint8_t*>(&output[cursor]), |
| 5761 remaining, | 5798 remaining, |
| 5762 user_data); | 5799 user_data); |
| 5763 cursor += remaining; | 5800 cursor += remaining; |
| 5764 remaining -= remaining; | 5801 remaining -= remaining; |
| 5765 } | 5802 } |
| 5766 ASSERT(cursor == output_length); | 5803 ASSERT(cursor == output_length); |
| 5767 ASSERT(remaining == 0); | 5804 ASSERT(remaining == 0); |
| 5768 | |
| 5769 // Finish stream. | |
| 5770 consumer(Dart_StreamConsumer_kFinish, | |
| 5771 kStreamName, | |
| 5772 NULL, | |
| 5773 0, | |
| 5774 user_data); | |
| 5775 } | 5805 } |
| 5776 | 5806 |
| 5777 | 5807 |
| 5808 static bool StreamTraceEvents(Dart_StreamConsumer consumer, | |
| 5809 void* user_data, | |
| 5810 JSONStream* js, | |
| 5811 const char* dart_events) { | |
| 5812 ASSERT(js != NULL); | |
| 5813 // Steal output from JSONStream. | |
| 5814 char* output = NULL; | |
| 5815 intptr_t output_length = 0; | |
| 5816 js->Steal(const_cast<const char**>(&output), &output_length); | |
| 5817 | |
| 5818 const bool output_vm = output_length > MINIMUM_OUTPUT_LENGTH; | |
| 5819 const bool output_dart = dart_events != NULL; | |
| 5820 | |
| 5821 if (!output_vm && !output_dart) { | |
| 5822 // We stole the JSONStream's output buffer, free it. | |
| 5823 free(output); | |
| 5824 // Nothing will be emitted. | |
| 5825 return false; | |
| 5826 } | |
| 5827 | |
| 5828 // Start the stream. | |
| 5829 StartStreamToConsumer(consumer, user_data, "timeline"); | |
| 5830 | |
| 5831 // Send events from the VM. | |
| 5832 if (output_vm) { | |
| 5833 // Add one for the '\0' character. | |
| 5834 output_length++; | |
| 5835 char* trimmed_output = TrimOutput(output, &output_length, output_dart); | |
| 5836 DataStreamToConsumer(consumer, user_data, | |
| 5837 trimmed_output, output_length, "timeline"); | |
| 5838 } | |
| 5839 // We stole the JSONStream's output buffer, free it. | |
| 5840 free(output); | |
| 5841 | |
| 5842 // Send events from dart. | |
| 5843 if (output_dart) { | |
| 5844 const intptr_t dart_events_len = strlen(dart_events) + 1; // +1 for '\0'. | |
| 5845 DataStreamToConsumer(consumer, user_data, | |
| 5846 dart_events, dart_events_len, "timeline"); | |
| 5847 } | |
| 5848 | |
| 5849 // Finish the stream. | |
| 5850 FinishStreamToConsumer(consumer, user_data, "timeline"); | |
| 5851 return true; | |
| 5852 } | |
| 5853 | |
| 5854 | |
| 5778 DART_EXPORT bool Dart_TimelineGetTrace(Dart_StreamConsumer consumer, | 5855 DART_EXPORT bool Dart_TimelineGetTrace(Dart_StreamConsumer consumer, |
| 5779 void* user_data) { | 5856 void* user_data) { |
| 5780 Isolate* isolate = Isolate::Current(); | 5857 Isolate* isolate = Isolate::Current(); |
| 5781 CHECK_ISOLATE(isolate); | 5858 CHECK_ISOLATE(isolate); |
| 5782 if (consumer == NULL) { | 5859 if (consumer == NULL) { |
| 5783 return false; | 5860 return false; |
| 5784 } | 5861 } |
| 5785 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); | 5862 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); |
| 5786 if (timeline_recorder == NULL) { | 5863 if (timeline_recorder == NULL) { |
| 5787 // Nothing has been recorded. | 5864 // Nothing has been recorded. |
| 5788 return false; | 5865 return false; |
| 5789 } | 5866 } |
| 5867 Thread* T = Thread::Current(); | |
| 5868 StackZone zone(T); | |
| 5790 // Reclaim all blocks cached by isolate. | 5869 // Reclaim all blocks cached by isolate. |
| 5791 Timeline::ReclaimIsolateBlocks(); | 5870 Timeline::ReclaimIsolateBlocks(); |
| 5792 JSONStream js; | 5871 JSONStream js; |
| 5793 IsolateTimelineEventFilter filter(isolate); | 5872 IsolateTimelineEventFilter filter(isolate); |
| 5794 timeline_recorder->PrintTraceEvent(&js, &filter); | 5873 timeline_recorder->PrintTraceEvent(&js, &filter); |
| 5795 | 5874 const char* dart_events = |
| 5796 // Copy output. | 5875 DartTimelineEventIterator::PrintTraceEvents(timeline_recorder, |
| 5797 char* output = NULL; | 5876 zone.GetZone(), |
| 5798 intptr_t output_length = 0; | 5877 isolate); |
| 5799 js.Steal(const_cast<const char**>(&output), &output_length); | 5878 return StreamTraceEvents(consumer, user_data, &js, dart_events); |
| 5800 if (output != NULL) { | |
| 5801 // Add one for the '\0' character. | |
| 5802 output_length++; | |
| 5803 StreamToConsumer(consumer, user_data, output, output_length); | |
| 5804 // We stole the JSONStream's output buffer, free it. | |
| 5805 free(output); | |
| 5806 return output_length > MINIMUM_OUTPUT_LENGTH; | |
| 5807 } | |
| 5808 return false; | |
| 5809 } | 5879 } |
| 5810 | 5880 |
| 5811 | 5881 |
| 5812 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer, | 5882 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer, |
| 5813 void* user_data) { | 5883 void* user_data) { |
| 5814 if (consumer == NULL) { | 5884 if (consumer == NULL) { |
| 5815 return false; | 5885 return false; |
| 5816 } | 5886 } |
| 5817 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); | 5887 TimelineEventRecorder* timeline_recorder = Timeline::recorder(); |
| 5818 if (timeline_recorder == NULL) { | 5888 if (timeline_recorder == NULL) { |
| 5819 // Nothing has been recorded. | 5889 // Nothing has been recorded. |
| 5820 return false; | 5890 return false; |
| 5821 } | 5891 } |
| 5822 | 5892 Thread* T = Thread::Current(); |
| 5893 StackZone zone(T); | |
| 5823 // Reclaim all blocks cached in the system. | 5894 // Reclaim all blocks cached in the system. |
| 5824 Timeline::ReclaimAllBlocks(); | 5895 Timeline::ReclaimAllBlocks(); |
| 5825 JSONStream js; | 5896 JSONStream js; |
| 5826 TimelineEventFilter filter; | 5897 TimelineEventFilter filter; |
| 5827 timeline_recorder->PrintTraceEvent(&js, &filter); | 5898 timeline_recorder->PrintTraceEvent(&js, &filter); |
| 5828 | 5899 const char* dart_events = |
| 5829 // Copy output. | 5900 DartTimelineEventIterator::PrintTraceEvents(timeline_recorder, |
| 5830 char* output = NULL; | 5901 zone.GetZone(), |
| 5831 intptr_t output_length = 0; | 5902 NULL); |
| 5832 js.Steal(const_cast<const char**>(&output), &output_length); | 5903 return StreamTraceEvents(consumer, user_data, &js, dart_events); |
| 5833 if (output != NULL) { | |
| 5834 // Add one for the '\0' character. | |
| 5835 output_length++; | |
| 5836 StreamToConsumer(consumer, user_data, output, output_length); | |
| 5837 // We stole the JSONStream's output buffer, free it. | |
| 5838 free(output); | |
| 5839 return output_length > MINIMUM_OUTPUT_LENGTH; | |
| 5840 } | |
| 5841 return false; | |
| 5842 } | 5904 } |
| 5843 | 5905 |
| 5844 | 5906 |
| 5845 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, | 5907 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, |
| 5846 int64_t start_micros, | 5908 int64_t start_micros, |
| 5847 int64_t end_micros) { | 5909 int64_t end_micros) { |
| 5848 Isolate* isolate = Isolate::Current(); | 5910 Isolate* isolate = Isolate::Current(); |
| 5849 CHECK_ISOLATE(isolate); | 5911 CHECK_ISOLATE(isolate); |
| 5850 if (label == NULL) { | 5912 if (label == NULL) { |
| 5851 RETURN_NULL_ERROR(label); | 5913 RETURN_NULL_ERROR(label); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6004 ApiReallocate); | 6066 ApiReallocate); |
| 6005 writer.WriteFullSnapshot(); | 6067 writer.WriteFullSnapshot(); |
| 6006 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 6068 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
| 6007 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 6069 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
| 6008 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); | 6070 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); |
| 6009 | 6071 |
| 6010 return Api::Success(); | 6072 return Api::Success(); |
| 6011 } | 6073 } |
| 6012 | 6074 |
| 6013 } // namespace dart | 6075 } // namespace dart |
| OLD | NEW |