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

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

Issue 1276903004: Add timeline stream control and trace retrieval to the dart embedder api. (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 18 matching lines...) Expand all
29 #include "vm/port.h" 29 #include "vm/port.h"
30 #include "vm/profiler.h" 30 #include "vm/profiler.h"
31 #include "vm/resolver.h" 31 #include "vm/resolver.h"
32 #include "vm/reusable_handles.h" 32 #include "vm/reusable_handles.h"
33 #include "vm/service_event.h" 33 #include "vm/service_event.h"
34 #include "vm/service_isolate.h" 34 #include "vm/service_isolate.h"
35 #include "vm/service.h" 35 #include "vm/service.h"
36 #include "vm/stack_frame.h" 36 #include "vm/stack_frame.h"
37 #include "vm/symbols.h" 37 #include "vm/symbols.h"
38 #include "vm/tags.h" 38 #include "vm/tags.h"
39 #include "vm/thread_registry.h"
39 #include "vm/timeline.h" 40 #include "vm/timeline.h"
40 #include "vm/timer.h" 41 #include "vm/timer.h"
41 #include "vm/unicode.h" 42 #include "vm/unicode.h"
42 #include "vm/verifier.h" 43 #include "vm/verifier.h"
43 #include "vm/version.h" 44 #include "vm/version.h"
44 45
45 namespace dart { 46 namespace dart {
46 47
47 DECLARE_FLAG(bool, load_deferred_eagerly); 48 DECLARE_FLAG(bool, load_deferred_eagerly);
48 DECLARE_FLAG(bool, print_class_table); 49 DECLARE_FLAG(bool, print_class_table);
(...skipping 5712 matching lines...) Expand 10 before | Expand all | Expand 10 after
5761 if (bytes_length < 0) { 5762 if (bytes_length < 0) {
5762 return Api::NewError("%s expects argument 'bytes_length' to be >= 0.", 5763 return Api::NewError("%s expects argument 'bytes_length' to be >= 0.",
5763 CURRENT_FUNC); 5764 CURRENT_FUNC);
5764 } 5765 }
5765 Service::SendEmbedderEvent(isolate, stream_id, event_kind, 5766 Service::SendEmbedderEvent(isolate, stream_id, event_kind,
5766 bytes, bytes_length); 5767 bytes, bytes_length);
5767 return Api::Success(); 5768 return Api::Success();
5768 } 5769 }
5769 5770
5770 5771
5772 DART_EXPORT void Dart_TimelineSetRecordedStreams(int64_t stream_mask) {
5773 Isolate* isolate = Isolate::Current();
5774 CHECK_ISOLATE(isolate);
5775 isolate->GetAPIStream()->set_enabled(
5776 (stream_mask & DART_TIMELINE_STREAM_API) != 0);
5777 isolate->GetCompilerStream()->set_enabled(
5778 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0);
5779 isolate->GetEmbedderStream()->set_enabled(
5780 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0);
5781 isolate->GetGCStream()->set_enabled(
5782 (stream_mask & DART_TIMELINE_STREAM_GC) != 0);
5783 isolate->GetIsolateStream()->set_enabled(
5784 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0);
5785 }
5786
5787
5788 DART_EXPORT bool Dart_TimelineGetTrace(const char** output,
5789 intptr_t* output_length) {
5790 Isolate* isolate = Isolate::Current();
5791 CHECK_ISOLATE(isolate);
5792 if (output == NULL) {
5793 return false;
5794 }
5795 if (output_length == NULL) {
5796 return false;
5797 }
5798 TimelineEventRecorder* timeline_recorder = isolate->timeline_event_recorder();
5799 if (timeline_recorder == NULL) {
5800 // Nothing has been recorded.
5801 return false;
5802 }
5803 // Suspend execution of other threads while serializing to JSON.
5804 isolate->thread_registry()->SafepointThreads();
5805 JSONStream js;
5806 timeline_recorder->PrintJSON(&js);
5807 js.Steal(output, output_length);
5808 isolate->thread_registry()->ResumeAllThreads();
5809 return true;
5810 }
5811
5812
5771 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label, 5813 DART_EXPORT Dart_Handle Dart_TimelineDuration(const char* label,
5772 int64_t start_micros, 5814 int64_t start_micros,
5773 int64_t end_micros) { 5815 int64_t end_micros) {
5774 Isolate* isolate = Isolate::Current(); 5816 Isolate* isolate = Isolate::Current();
5775 CHECK_ISOLATE(isolate); 5817 CHECK_ISOLATE(isolate);
5776 if (label == NULL) { 5818 if (label == NULL) {
5777 RETURN_NULL_ERROR(label); 5819 RETURN_NULL_ERROR(label);
5778 } 5820 }
5779 if (start_micros > end_micros) { 5821 if (start_micros > end_micros) {
5780 const char* msg = "%s: start_micros must be <= end_micros"; 5822 const char* msg = "%s: start_micros must be <= end_micros";
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
5865 ASSERT(stream != NULL); 5907 ASSERT(stream != NULL);
5866 TimelineEvent* event = stream->StartEvent(); 5908 TimelineEvent* event = stream->StartEvent();
5867 if (event != NULL) { 5909 if (event != NULL) {
5868 event->AsyncEnd(label, async_id); 5910 event->AsyncEnd(label, async_id);
5869 event->Complete(); 5911 event->Complete();
5870 } 5912 }
5871 return Api::Success(); 5913 return Api::Success();
5872 } 5914 }
5873 5915
5874 } // namespace dart 5916 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698