diff --git a/shell/common/animator.cc b/shell/common/animator.cc index 9d31a0c2e..78fdd98b3 100644 --- a/shell/common/animator.cc +++ b/shell/common/animator.cc @@ -62,6 +62,17 @@ void Animator::SetDimensionChangePending() { dimension_change_pending_ = true; } +void Animator::EnqueueTraceFlowId(uint64_t trace_flow_id) { + fml::TaskRunner::RunNowOrPostTask( + task_runners_.GetUITaskRunner(), + [self = weak_factory_.GetWeakPtr(), trace_flow_id] { + if (!self) { + return; + } + self->trace_flow_ids_.push_back(trace_flow_id); + }); +} + // This Parity is used by the timeline component to correctly align // GPU Workloads events with their respective Framework Workload. const char* Animator::FrameParity() { @@ -78,6 +89,13 @@ void Animator::BeginFrame(fml::TimePoint frame_start_time, fml::TimePoint frame_target_time) { TRACE_EVENT_ASYNC_END0("flutter", "Frame Request Pending", frame_number_++); + TRACE_EVENT0("flutter", "Animator::BeginFrame"); + while (!trace_flow_ids_.empty()) { + uint64_t trace_flow_id = trace_flow_ids_.front(); + TRACE_FLOW_END("flutter", "DispatchPointerDataPacket", trace_flow_id); + trace_flow_ids_.pop_front(); + } + frame_scheduled_ = false; notify_idle_task_id_++; regenerate_layer_tree_ = false; diff --git a/shell/common/animator.h b/shell/common/animator.h index 4f75b8fb3..15f8b8c74 100644 --- a/shell/common/animator.h +++ b/shell/common/animator.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_SHELL_COMMON_ANIMATOR_H_ #define FLUTTER_SHELL_COMMON_ANIMATOR_H_ +#include + #include "flutter/common/task_runners.h" #include "flutter/fml/memory/ref_ptr.h" #include "flutter/fml/memory/weak_ptr.h" @@ -48,6 +50,10 @@ class Animator final { void SetDimensionChangePending(); + // Enqueue |trace_flow_id| into |trace_flow_ids_|. The corresponding flow + // will be ended during the next |BeginFrame|. + void EnqueueTraceFlowId(uint64_t trace_flow_id); + private: using LayerTreePipeline = flutter::Pipeline; @@ -77,6 +83,7 @@ class Animator final { int notify_idle_task_id_; bool dimension_change_pending_; SkISize last_layer_tree_size_; + std::deque trace_flow_ids_; fml::WeakPtrFactory weak_factory_; diff --git a/shell/common/engine.cc b/shell/common/engine.cc index c0aec58ee..084216072 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -355,7 +355,11 @@ void Engine::HandleSettingsPlatformMessage(blink::PlatformMessage* message) { } } -void Engine::DispatchPointerDataPacket(const blink::PointerDataPacket& packet) { +void Engine::DispatchPointerDataPacket(const blink::PointerDataPacket& packet, + uint64_t trace_flow_id) { + TRACE_EVENT0("flutter", "Engine::DispatchPointerDataPacket"); + TRACE_FLOW_STEP("flutter", "PointerEvent", trace_flow_id); + animator_->EnqueueTraceFlowId(trace_flow_id); runtime_controller_->DispatchPointerDataPacket(packet); } diff --git a/shell/common/engine.h b/shell/common/engine.h index 1c241a57a..b390b36a2 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -104,7 +104,8 @@ class Engine final : public blink::RuntimeDelegate { void DispatchPlatformMessage(fml::RefPtr message); - void DispatchPointerDataPacket(const blink::PointerDataPacket& packet); + void DispatchPointerDataPacket(const blink::PointerDataPacket& packet, + uint64_t trace_flow_id); void DispatchSemanticsAction(int id, blink::SemanticsAction action, diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 2a00a4460..c1dec19f6 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -546,14 +546,18 @@ void Shell::OnPlatformViewDispatchPlatformMessage( // |shell::PlatformView::Delegate| void Shell::OnPlatformViewDispatchPointerDataPacket( std::unique_ptr packet) { + TRACE_EVENT0("flutter", "Shell::OnPlatformViewDispatchPointerDataPacket"); + TRACE_FLOW_BEGIN("flutter", "PointerEvent", next_pointer_flow_id_); FML_DCHECK(is_setup_); FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread()); task_runners_.GetUITaskRunner()->PostTask(fml::MakeCopyable( - [engine = engine_->GetWeakPtr(), packet = std::move(packet)] { + [engine = engine_->GetWeakPtr(), packet = std::move(packet), + flow_id = next_pointer_flow_id_] { if (engine) { - engine->DispatchPointerDataPacket(*packet); + engine->DispatchPointerDataPacket(*packet, flow_id); } })); + next_pointer_flow_id_++; } // |shell::PlatformView::Delegate| diff --git a/shell/common/shell.h b/shell/common/shell.h index 2222fa453..17b0f1705 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -99,6 +99,8 @@ class Shell final : public PlatformView::Delegate, service_protocol_handlers_; bool is_setup_ = false; + uint64_t next_pointer_flow_id_ = 0; + Shell(blink::TaskRunners task_runners, blink::Settings settings); static std::unique_ptr CreateShellOnPlatformThread( diff --git a/shell/platform/android/android_shell_holder.cc b/shell/platform/android/android_shell_holder.cc index 4c9a1ba07..06a3697da 100644 --- a/shell/platform/android/android_shell_holder.cc +++ b/shell/platform/android/android_shell_holder.cc @@ -192,12 +192,18 @@ void AndroidShellHolder::DispatchPointerDataPacket( return; } + TRACE_EVENT0("flutter", "AndroidShellHolder::DispatchPointerDataPacket"); + TRACE_FLOW_BEGIN("flutter", "PointerEvent", next_pointer_flow_id_); + shell_->GetTaskRunners().GetUITaskRunner()->PostTask(fml::MakeCopyable( - [engine = shell_->GetEngine(), packet = std::move(packet)] { + [engine = shell_->GetEngine(), packet = std::move(packet), + flow_id = next_pointer_flow_id_] { if (engine) { - engine->DispatchPointerDataPacket(*packet); + engine->DispatchPointerDataPacket(*packet, flow_id); } })); + + next_pointer_flow_id_++; } Rasterizer::Screenshot AndroidShellHolder::Screenshot( diff --git a/shell/platform/android/android_shell_holder.h b/shell/platform/android/android_shell_holder.h index 1fbca8a28..d01cc5d43 100644 --- a/shell/platform/android/android_shell_holder.h +++ b/shell/platform/android/android_shell_holder.h @@ -52,6 +52,7 @@ class AndroidShellHolder { std::unique_ptr shell_; bool is_valid_ = false; pthread_key_t thread_destruct_key_; + uint64_t next_pointer_flow_id_; static void ThreadDestructCallback(void* value); diff --git a/shell/platform/embedder/embedder_engine.cc b/shell/platform/embedder/embedder_engine.cc index 9061bd3e8..168de1b83 100644 --- a/shell/platform/embedder/embedder_engine.cc +++ b/shell/platform/embedder/embedder_engine.cc @@ -89,12 +89,17 @@ bool EmbedderEngine::DispatchPointerDataPacket( return false; } + TRACE_EVENT0("flutter", "EmbedderEngine::DispatchPointerDataPacket"); + TRACE_FLOW_BEGIN("flutter", "PointerEvent", next_pointer_flow_id_); + shell_->GetTaskRunners().GetUITaskRunner()->PostTask(fml::MakeCopyable( - [engine = shell_->GetEngine(), packet = std::move(packet)] { + [engine = shell_->GetEngine(), packet = std::move(packet), + flow_id = next_pointer_flow_id_] { if (engine) { - engine->DispatchPointerDataPacket(*packet); + engine->DispatchPointerDataPacket(*packet, flow_id); } })); + next_pointer_flow_id_++; return true; } diff --git a/shell/platform/embedder/embedder_engine.h b/shell/platform/embedder/embedder_engine.h index b8110f02a..204776554 100644 --- a/shell/platform/embedder/embedder_engine.h +++ b/shell/platform/embedder/embedder_engine.h @@ -56,6 +56,7 @@ class EmbedderEngine { const EmbedderExternalTextureGL::ExternalTextureCallback external_texture_callback_; bool is_valid_ = false; + uint64_t next_pointer_flow_id_; FML_DISALLOW_COPY_AND_ASSIGN(EmbedderEngine); };