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

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

Issue 1287543003: Refactor Dart_TimelineGetTrace to use a StreamConsumer callback (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
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 5767 matching lines...) Expand 10 before | Expand all | Expand 10 after
5778 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0); 5778 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0);
5779 isolate->GetEmbedderStream()->set_enabled( 5779 isolate->GetEmbedderStream()->set_enabled(
5780 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0); 5780 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0);
5781 isolate->GetGCStream()->set_enabled( 5781 isolate->GetGCStream()->set_enabled(
5782 (stream_mask & DART_TIMELINE_STREAM_GC) != 0); 5782 (stream_mask & DART_TIMELINE_STREAM_GC) != 0);
5783 isolate->GetIsolateStream()->set_enabled( 5783 isolate->GetIsolateStream()->set_enabled(
5784 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0); 5784 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0);
5785 } 5785 }
5786 5786
5787 5787
5788 DART_EXPORT bool Dart_TimelineGetTrace(const char** output, 5788 DART_EXPORT bool Dart_TimelineGetTrace(Dart_StreamConsumer consumer,
5789 intptr_t* output_length) { 5789 void* user_data) {
5790 Isolate* isolate = Isolate::Current(); 5790 Isolate* isolate = Isolate::Current();
5791 CHECK_ISOLATE(isolate); 5791 CHECK_ISOLATE(isolate);
5792 if (output == NULL) { 5792 if (consumer == NULL) {
5793 return false;
5794 }
5795 if (output_length == NULL) {
5796 return false; 5793 return false;
5797 } 5794 }
5798 TimelineEventRecorder* timeline_recorder = isolate->timeline_event_recorder(); 5795 TimelineEventRecorder* timeline_recorder = isolate->timeline_event_recorder();
5799 if (timeline_recorder == NULL) { 5796 if (timeline_recorder == NULL) {
5800 // Nothing has been recorded. 5797 // Nothing has been recorded.
5801 return false; 5798 return false;
5802 } 5799 }
5803 // Suspend execution of other threads while serializing to JSON. 5800 // Suspend execution of other threads while serializing to JSON.
5804 isolate->thread_registry()->SafepointThreads(); 5801 isolate->thread_registry()->SafepointThreads();
5805 JSONStream js; 5802 JSONStream js;
5806 timeline_recorder->PrintJSON(&js); 5803 timeline_recorder->PrintJSON(&js);
5807 js.Steal(output, output_length); 5804 // Resume execution of other threads.
5808 isolate->thread_registry()->ResumeAllThreads(); 5805 isolate->thread_registry()->ResumeAllThreads();
5806
5807 // Copy output.
5808 char* output = NULL;
5809 intptr_t output_length = 0;
5810 js.Steal(const_cast<const char**>(&output), &output_length);
5811 if (output != NULL) {
5812 // Add one for the '\0' character.
5813 output_length++;
5814 }
5815 // Start stream.
5816 const char* kStreamName = "timeline";
5817 const intptr_t kDataSize = 64 * KB;
5818 consumer(DART_STREAM_CONSUMER_STATE_START,
5819 kStreamName,
5820 NULL,
5821 0,
5822 user_data);
5823
5824 // Stream out data.
5825 intptr_t cursor = 0;
5826 intptr_t remaining = output_length - cursor;
siva 2015/08/11 16:54:33 intptr_t remaining = output_length;
Cutch 2015/08/11 17:08:56 Done.
5827 while (remaining >= kDataSize) {
5828 consumer(DART_STREAM_CONSUMER_STATE_DATA,
5829 kStreamName,
5830 reinterpret_cast<uint8_t*>(&output[cursor]),
5831 kDataSize,
5832 user_data);
5833 cursor += kDataSize;
5834 remaining -= kDataSize;
5835 }
5836 if (remaining > 0) {
5837 ASSERT(remaining < kDataSize);
5838 consumer(DART_STREAM_CONSUMER_STATE_DATA,
5839 kStreamName,
5840 reinterpret_cast<uint8_t*>(&output[cursor]),
5841 remaining,
5842 user_data);
5843 cursor += remaining;
5844 remaining -= remaining;
5845 }
5846 ASSERT(cursor == output_length);
5847 ASSERT(remaining == 0);
5848
5849 // Finish stream.
5850 consumer(DART_STREAM_CONSUMER_STATE_FINISH,
5851 kStreamName,
5852 NULL,
5853 0,
5854 user_data);
siva 2015/08/11 16:54:33 Why does start and end have to have a NULL buffer
Cutch 2015/08/11 17:08:56 I find this API simpler to work with.
5809 return true; 5855 return true;
5810 } 5856 }
5811 5857
5812 5858
5813 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, 5859 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label,
5814 int64_t start_micros, 5860 int64_t start_micros,
5815 int64_t end_micros) { 5861 int64_t end_micros) {
5816 Isolate* isolate = Isolate::Current(); 5862 Isolate* isolate = Isolate::Current();
5817 CHECK_ISOLATE(isolate); 5863 CHECK_ISOLATE(isolate);
5818 if (label == NULL) { 5864 if (label == NULL) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
5907 ASSERT(stream != NULL); 5953 ASSERT(stream != NULL);
5908 TimelineEvent* event = stream->StartEvent(); 5954 TimelineEvent* event = stream->StartEvent();
5909 if (event != NULL) { 5955 if (event != NULL) {
5910 event->AsyncEnd(label, async_id); 5956 event->AsyncEnd(label, async_id);
5911 event->Complete(); 5957 event->Complete();
5912 } 5958 }
5913 return Api::Success(); 5959 return Api::Success();
5914 } 5960 }
5915 5961
5916 } // namespace dart 5962 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698