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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 1783953002: Add ability for embedder to provide private timeline trace data (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index 4f2499449116cce4006c9a958932f38254397023..498130474c0a56c38a2a90e755c8bd4ba7d5bf5d 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -5890,7 +5890,8 @@ static void DataStreamToConsumer(Dart_StreamConsumer consumer,
static bool StreamTraceEvents(Dart_StreamConsumer consumer,
void* user_data,
- JSONStream* js) {
+ JSONStream* js,
+ bool insert_comma) {
ASSERT(js != NULL);
// Steal output from JSONStream.
char* output = NULL;
@@ -5907,23 +5908,24 @@ static bool StreamTraceEvents(Dart_StreamConsumer consumer,
ASSERT(output[output_length - 1] == ']');
// Replace the ']' with the null character.
output[output_length - 1] = '\0';
- // We are skipping the '['.
- output_length -= 1;
-
- // Start the stream.
- StartStreamToConsumer(consumer, user_data, "timeline");
+ char* start = &output[1];
+ if (insert_comma) {
+ output[0] = ',';
+ start = &output[0];
+ } else {
+ // We are skipping the '['.
+ output_length -= 1;
+ }
DataStreamToConsumer(consumer,
user_data,
- &output[1],
+ start,
output_length,
"timeline");
// We stole the JSONStream's output buffer, free it.
free(output);
- // Finish the stream.
- FinishStreamToConsumer(consumer, user_data, "timeline");
return true;
}
@@ -5949,7 +5951,20 @@ DART_EXPORT bool Dart_TimelineGetTrace(Dart_StreamConsumer consumer,
JSONStream js;
IsolateTimelineEventFilter filter(isolate->main_port());
timeline_recorder->PrintTraceEvent(&js, &filter);
- return StreamTraceEvents(consumer, user_data, &js);
+ StartStreamToConsumer(consumer, user_data, "timeline");
+ bool success = StreamTraceEvents(consumer, user_data, &js, false);
+ FinishStreamToConsumer(consumer, user_data, "timeline");
+ return success;
+}
+
+
+DART_EXPORT void Dart_SetEmbedderTimelineCallbacks(
+ Dart_EmbedderTimelineStartRecording start_recording,
+ Dart_EmbedderTimelineStopRecording stop_recording,
+ Dart_EmbedderTimelineGetTimeline get_timeline) {
+ Timeline::set_start_recording_cb(start_recording);
+ Timeline::set_stop_recording_cb(stop_recording);
+ Timeline::set_get_timeline_cb(get_timeline);
}
@@ -5974,7 +5989,18 @@ DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer,
JSONStream js;
TimelineEventFilter filter;
timeline_recorder->PrintTraceEvent(&js, &filter);
- return StreamTraceEvents(consumer, user_data, &js);
+ StartStreamToConsumer(consumer, user_data, "timeline");
+ bool success = false;
+ if (Timeline::get_get_timeline_cb() != NULL) {
+ if (Timeline::get_get_timeline_cb()(consumer, user_data)) {
+ success = true;
+ }
+ }
+ if (StreamTraceEvents(consumer, user_data, &js, success)) {
+ success = true;
+ }
+ FinishStreamToConsumer(consumer, user_data, "timeline");
+ return success;
}
@@ -6099,7 +6125,6 @@ DART_EXPORT Dart_Handle Dart_TimelineAsyncEnd(const char* label,
return Api::Success();
}
-
// The precompiler is included in dart_bootstrap and dart_noopt, and
// excluded from dart and dart_precompiled_runtime.
#if !defined(DART_PRECOMPILER)

Powered by Google App Engine
This is Rietveld 408576698