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

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

Issue 1360813002: Add API to get the VM global timeline (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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/include/dart_tools_api.h ('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 "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 5696 matching lines...) Expand 10 before | Expand all | Expand 10 after
5707 Timeline::SetStreamEmbedderEnabled(embedder_enabled); 5707 Timeline::SetStreamEmbedderEnabled(embedder_enabled);
5708 Timeline::SetStreamGCEnabled(gc_enabled); 5708 Timeline::SetStreamGCEnabled(gc_enabled);
5709 Timeline::SetStreamIsolateEnabled(isolate_enabled); 5709 Timeline::SetStreamIsolateEnabled(isolate_enabled);
5710 // VM wide. 5710 // VM wide.
5711 const bool vm_enabled = 5711 const bool vm_enabled =
5712 (stream_mask & DART_TIMELINE_STREAM_VM) != 0; 5712 (stream_mask & DART_TIMELINE_STREAM_VM) != 0;
5713 Timeline::GetVMStream()->set_enabled(vm_enabled); 5713 Timeline::GetVMStream()->set_enabled(vm_enabled);
5714 } 5714 }
5715 5715
5716 5716
5717 DART_EXPORT bool Dart_TimelineGetTrace(Dart_StreamConsumer consumer, 5717 static void StreamToConsumer(Dart_StreamConsumer consumer,
5718 void* user_data) { 5718 void* user_data,
5719 Isolate* isolate = Isolate::Current(); 5719 char* output,
5720 CHECK_ISOLATE(isolate); 5720 intptr_t output_length) {
5721 if (consumer == NULL) {
5722 return false;
5723 }
5724 TimelineEventRecorder* timeline_recorder = Timeline::recorder();
5725 if (timeline_recorder == NULL) {
5726 // Nothing has been recorded.
5727 return false;
5728 }
5729 // Suspend execution of other threads while serializing to JSON.
5730 isolate->thread_registry()->SafepointThreads();
5731 JSONStream js;
5732 IsolateTimelineEventFilter filter(isolate);
5733 timeline_recorder->PrintJSON(&js, &filter);
5734 // Resume execution of other threads.
5735 isolate->thread_registry()->ResumeAllThreads();
5736
5737 // Copy output.
5738 char* output = NULL;
5739 intptr_t output_length = 0;
5740 js.Steal(const_cast<const char**>(&output), &output_length);
5741 if (output != NULL) {
5742 // Add one for the '\0' character.
5743 output_length++;
5744 }
5745 // Start stream. 5721 // Start stream.
5746 const char* kStreamName = "timeline"; 5722 const char* kStreamName = "timeline";
5747 const intptr_t kDataSize = 64 * KB; 5723 const intptr_t kDataSize = 64 * KB;
5748 consumer(Dart_StreamConsumer_kStart, 5724 consumer(Dart_StreamConsumer_kStart,
5749 kStreamName, 5725 kStreamName,
5750 NULL, 5726 NULL,
5751 0, 5727 0,
5752 user_data); 5728 user_data);
5753 5729
5754 // Stream out data. 5730 // Stream out data.
(...skipping 13 matching lines...) Expand all
5768 consumer(Dart_StreamConsumer_kData, 5744 consumer(Dart_StreamConsumer_kData,
5769 kStreamName, 5745 kStreamName,
5770 reinterpret_cast<uint8_t*>(&output[cursor]), 5746 reinterpret_cast<uint8_t*>(&output[cursor]),
5771 remaining, 5747 remaining,
5772 user_data); 5748 user_data);
5773 cursor += remaining; 5749 cursor += remaining;
5774 remaining -= remaining; 5750 remaining -= remaining;
5775 } 5751 }
5776 ASSERT(cursor == output_length); 5752 ASSERT(cursor == output_length);
5777 ASSERT(remaining == 0); 5753 ASSERT(remaining == 0);
5778 // We stole the JSONStream's output buffer, free it.
5779 free(output);
5780 5754
5781 // Finish stream. 5755 // Finish stream.
5782 consumer(Dart_StreamConsumer_kFinish, 5756 consumer(Dart_StreamConsumer_kFinish,
5783 kStreamName, 5757 kStreamName,
5784 NULL, 5758 NULL,
5785 0, 5759 0,
5786 user_data); 5760 user_data);
5761 }
5762
5763
5764 DART_EXPORT bool Dart_TimelineGetTrace(Dart_StreamConsumer consumer,
5765 void* user_data) {
5766 Isolate* isolate = Isolate::Current();
5767 CHECK_ISOLATE(isolate);
5768 if (consumer == NULL) {
5769 return false;
5770 }
5771 TimelineEventRecorder* timeline_recorder = Timeline::recorder();
5772 if (timeline_recorder == NULL) {
5773 // Nothing has been recorded.
5774 return false;
5775 }
5776 // Suspend execution of other threads while serializing to JSON.
5777 isolate->thread_registry()->SafepointThreads();
5778 // TODO(johnmccutchan): Reclaim open blocks from isolate so we have a complete
5779 // timeline.
5780 JSONStream js;
5781 IsolateTimelineEventFilter filter(isolate);
5782 timeline_recorder->PrintJSON(&js, &filter);
5783 // Resume execution of other threads.
5784 isolate->thread_registry()->ResumeAllThreads();
5785
5786 // Copy output.
5787 char* output = NULL;
5788 intptr_t output_length = 0;
5789 js.Steal(const_cast<const char**>(&output), &output_length);
5790 if (output != NULL) {
5791 // Add one for the '\0' character.
5792 output_length++;
5793 }
5794 StreamToConsumer(consumer, user_data, output, output_length);
5795
5796 // We stole the JSONStream's output buffer, free it.
5797 free(output);
5787 return true; 5798 return true;
5788 } 5799 }
5789 5800
5801
5802 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer,
5803 void* user_data) {
5804 if (consumer == NULL) {
5805 return false;
5806 }
5807 TimelineEventRecorder* timeline_recorder = Timeline::recorder();
5808 if (timeline_recorder == NULL) {
5809 // Nothing has been recorded.
5810 return false;
5811 }
5812
5813 // TODO(johnmccutchan): Reclaim all open blocks from the system so we have
5814 // a complete timeline.
5815 JSONStream js;
5816 TimelineEventFilter filter;
5817 timeline_recorder->PrintJSON(&js, &filter);
5818
5819 // Copy output.
5820 char* output = NULL;
5821 intptr_t output_length = 0;
5822 js.Steal(const_cast<const char**>(&output), &output_length);
5823 if (output != NULL) {
5824 // Add one for the '\0' character.
5825 output_length++;
5826 }
5827 StreamToConsumer(consumer, user_data, output, output_length);
5828
5829 // We stole the JSONStream's output buffer, free it.
5830 free(output);
5831 return true;
5832 }
5833
5790 5834
5791 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, 5835 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label,
5792 int64_t start_micros, 5836 int64_t start_micros,
5793 int64_t end_micros) { 5837 int64_t end_micros) {
5794 Isolate* isolate = Isolate::Current(); 5838 Isolate* isolate = Isolate::Current();
5795 CHECK_ISOLATE(isolate); 5839 CHECK_ISOLATE(isolate);
5796 if (label == NULL) { 5840 if (label == NULL) {
5797 RETURN_NULL_ERROR(label); 5841 RETURN_NULL_ERROR(label);
5798 } 5842 }
5799 if (start_micros > end_micros) { 5843 if (start_micros > end_micros) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
5957 ApiReallocate); 6001 ApiReallocate);
5958 writer.WriteFullSnapshot(); 6002 writer.WriteFullSnapshot();
5959 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 6003 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
5960 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 6004 *isolate_snapshot_size = writer.IsolateSnapshotSize();
5961 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); 6005 *instructions_snapshot_size = writer.InstructionsSnapshotSize();
5962 6006
5963 return Api::Success(); 6007 return Api::Success();
5964 } 6008 }
5965 6009
5966 } // namespace dart 6010 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_tools_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698