From 000807898dc36fe7871456a7de0efaa089a308a2 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 29 Mar 2017 13:04:25 -0700 Subject: [PATCH] Cleanup timeline markers. (flutter/engine#3540) * Name the platform thread in the timeline. This does not affect (nor is it affected by) the pthread name set by the embedder. * Make it easier in the timeline to see not only when the frame was request, but also when that frame request was fulfilled. * Trace message loop wakes. --- engine/src/flutter/fml/message_loop_impl.cc | 2 ++ engine/src/flutter/shell/common/animator.cc | 18 ++++++++++++------ engine/src/flutter/shell/common/animator.h | 1 + .../flutter/shell/common/tracing_controller.cc | 2 ++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/fml/message_loop_impl.cc b/engine/src/flutter/fml/message_loop_impl.cc index 56282a1a22..448ed5f219 100644 --- a/engine/src/flutter/fml/message_loop_impl.cc +++ b/engine/src/flutter/fml/message_loop_impl.cc @@ -7,6 +7,7 @@ #include #include +#include "flutter/fml/trace_event.h" #include "lib/ftl/build_config.h" #if OS_MACOSX @@ -111,6 +112,7 @@ ftl::TimePoint MessageLoopImpl::RegisterTaskAndGetNextWake( } ftl::TimePoint MessageLoopImpl::RunExpiredTasksAndGetNextWake() { + TRACE_EVENT0("fml", "MessageLoop::RunExpiredTasks"); std::vector invocations; { diff --git a/engine/src/flutter/shell/common/animator.cc b/engine/src/flutter/shell/common/animator.cc index 56925b819b..acf28add8e 100644 --- a/engine/src/flutter/shell/common/animator.cc +++ b/engine/src/flutter/shell/common/animator.cc @@ -18,6 +18,7 @@ Animator::Animator(ftl::WeakPtr rasterizer, engine_(engine), layer_tree_pipeline_(ftl::MakeRefCounted(3)), pending_frame_semaphore_(1), + frame_number_(1), paused_(false), weak_factory_(this) {} @@ -37,6 +38,8 @@ void Animator::Start() { } void Animator::BeginFrame(ftl::TimePoint frame_time) { + TRACE_EVENT_ASYNC_END0("flutter", "Frame Request Pending", frame_number_++); + pending_frame_semaphore_.Signal(); if (!producer_continuation_) { @@ -101,12 +104,15 @@ void Animator::RequestFrame() { // started an expensive operation right after posting this message however. // To support that, we need edge triggered wakes on VSync. - blink::Threads::UI()->PostTask([self = weak_factory_.GetWeakPtr()]() { - if (!self.get()) - return; - TRACE_EVENT_INSTANT0("flutter", "RequestFrame"); - self->AwaitVSync(); - }); + blink::Threads::UI()->PostTask( + [ self = weak_factory_.GetWeakPtr(), frame_number = frame_number_ ]() { + if (!self.get()) { + return; + } + TRACE_EVENT_ASYNC_BEGIN0("flutter", "Frame Request Pending", + frame_number); + self->AwaitVSync(); + }); } void Animator::AwaitVSync() { diff --git a/engine/src/flutter/shell/common/animator.h b/engine/src/flutter/shell/common/animator.h index fc84fe62ec..475c1156ff 100644 --- a/engine/src/flutter/shell/common/animator.h +++ b/engine/src/flutter/shell/common/animator.h @@ -47,6 +47,7 @@ class Animator { ftl::RefPtr layer_tree_pipeline_; flutter::Semaphore pending_frame_semaphore_; LayerTreePipeline::ProducerContinuation producer_continuation_; + int64_t frame_number_; bool paused_; ftl::WeakPtrFactory weak_factory_; diff --git a/engine/src/flutter/shell/common/tracing_controller.cc b/engine/src/flutter/shell/common/tracing_controller.cc index 588e08f148..85cdb0d421 100644 --- a/engine/src/flutter/shell/common/tracing_controller.cc +++ b/engine/src/flutter/shell/common/tracing_controller.cc @@ -30,6 +30,8 @@ static void AddTraceMetadata() { blink::Threads::Gpu()->PostTask([]() { Dart_SetThreadName("gpu_thread"); }); blink::Threads::UI()->PostTask([]() { Dart_SetThreadName("ui_thread"); }); blink::Threads::IO()->PostTask([]() { Dart_SetThreadName("io_thread"); }); + blink::Threads::Platform()->PostTask( + []() { Dart_SetThreadName("platform_thread"); }); } void TracingController::StartTracing() {