Commit c76cc200 authored by Fady Samuel's avatar Fady Samuel Committed by Commit Bot

Surface Synchronization: Implement SurfaceId flows

This CL implements two types of tracing flows:

1. Embed Flow: The flow from allocating a LocalSurfaceId to embedding it in
a SurfaceLayer and SurfaceLayerImpl for the first time until a reference is
added for the first time to a parent CompositorFrame.

2. Submission Flow: The flow from allocating a LocalSurfaceId to passing it
to the child to use to submit CompositorFrames.

These flows let us debug surface synchronization performance regressions and
lets one visually see the parallelism achieved with surface synchronization.

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I02b7baec283e60528faa24dffdca74b641135d2e
Bug: 672962
Reviewed-on: https://chromium-review.googlesource.com/1124976
Commit-Queue: Fady Samuel <fsamuel@chromium.org>
Reviewed-by: default avatarSaman Sami <samans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572429}
parent 5c301712
...@@ -29,6 +29,14 @@ void SurfaceLayer::SetPrimarySurfaceId(const viz::SurfaceId& surface_id, ...@@ -29,6 +29,14 @@ void SurfaceLayer::SetPrimarySurfaceId(const viz::SurfaceId& surface_id,
deadline_policy.use_existing_deadline()) { deadline_policy.use_existing_deadline()) {
return; return;
} }
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Embed.Flow",
TRACE_ID_GLOBAL(surface_id.local_surface_id().embed_trace_id()),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step",
"SetPrimarySurfaceId", "surface_id", surface_id.ToString());
primary_surface_id_ = surface_id; primary_surface_id_ = surface_id;
// We should never block or set a deadline on an invalid // We should never block or set a deadline on an invalid
// |primary_surface_id_|. // |primary_surface_id_|.
...@@ -45,6 +53,13 @@ void SurfaceLayer::SetFallbackSurfaceId(const viz::SurfaceId& surface_id) { ...@@ -45,6 +53,13 @@ void SurfaceLayer::SetFallbackSurfaceId(const viz::SurfaceId& surface_id) {
if (fallback_surface_id_ == surface_id) if (fallback_surface_id_ == surface_id)
return; return;
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Submission.Flow",
TRACE_ID_GLOBAL(surface_id.local_surface_id().submission_trace_id()),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step",
"SetFallbackSurfaceId", "surface_id", surface_id.ToString());
if (layer_tree_host()) if (layer_tree_host())
layer_tree_host()->RemoveSurfaceLayerId(fallback_surface_id_); layer_tree_host()->RemoveSurfaceLayerId(fallback_surface_id_);
......
...@@ -33,6 +33,14 @@ void SurfaceLayerImpl::SetPrimarySurfaceId( ...@@ -33,6 +33,14 @@ void SurfaceLayerImpl::SetPrimarySurfaceId(
deadline_in_frames_ == deadline_in_frames) { deadline_in_frames_ == deadline_in_frames) {
return; return;
} }
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Embed.Flow",
TRACE_ID_GLOBAL(surface_id.local_surface_id().embed_trace_id()),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step",
"ImplSetPrimarySurfaceId", "surface_id", surface_id.ToString());
primary_surface_id_ = surface_id; primary_surface_id_ = surface_id;
deadline_in_frames_ = deadline_in_frames; deadline_in_frames_ = deadline_in_frames;
NoteLayerPropertyChanged(); NoteLayerPropertyChanged();
...@@ -42,6 +50,13 @@ void SurfaceLayerImpl::SetFallbackSurfaceId(const viz::SurfaceId& surface_id) { ...@@ -42,6 +50,13 @@ void SurfaceLayerImpl::SetFallbackSurfaceId(const viz::SurfaceId& surface_id) {
if (fallback_surface_id_ == surface_id) if (fallback_surface_id_ == surface_id)
return; return;
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Submission.Flow",
TRACE_ID_GLOBAL(surface_id.local_surface_id().submission_trace_id()),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step",
"ImplSetFallbackSurfaceId", "surface_id", surface_id.ToString());
fallback_surface_id_ = surface_id; fallback_surface_id_ = surface_id;
NoteLayerPropertyChanged(); NoteLayerPropertyChanged();
} }
......
...@@ -156,6 +156,13 @@ void AsyncLayerTreeFrameSink::SubmitCompositorFrame( ...@@ -156,6 +156,13 @@ void AsyncLayerTreeFrameSink::SubmitCompositorFrame(
last_submitted_device_scale_factor_ = frame.device_scale_factor(); last_submitted_device_scale_factor_ = frame.device_scale_factor();
last_submitted_size_in_pixels_ = frame.size_in_pixels(); last_submitted_size_in_pixels_ = frame.size_in_pixels();
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Submission.Flow",
TRACE_ID_GLOBAL(local_surface_id_.submission_trace_id()),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step",
"SubmitCompositorFrame", "surface_id", local_surface_id_.ToString());
compositor_frame_sink_ptr_->SubmitCompositorFrame( compositor_frame_sink_ptr_->SubmitCompositorFrame(
local_surface_id_, std::move(frame), std::move(hit_test_region_list), local_surface_id_, std::move(frame), std::move(hit_test_region_list),
tracing_enabled ? base::TimeTicks::Now().since_origin().InMicroseconds() tracing_enabled ? base::TimeTicks::Now().since_origin().InMicroseconds()
......
...@@ -1213,6 +1213,13 @@ void LayerTreeHost::SetLocalSurfaceIdFromParent( ...@@ -1213,6 +1213,13 @@ void LayerTreeHost::SetLocalSurfaceIdFromParent(
const viz::LocalSurfaceId& local_surface_id_from_parent) { const viz::LocalSurfaceId& local_surface_id_from_parent) {
if (local_surface_id_from_parent_ == local_surface_id_from_parent) if (local_surface_id_from_parent_ == local_surface_id_from_parent)
return; return;
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Submission.Flow",
TRACE_ID_GLOBAL(local_surface_id_from_parent.submission_trace_id()),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step",
"SetLocalSurfaceIdFromParent", "surface_id",
local_surface_id_from_parent.ToString());
local_surface_id_from_parent_ = local_surface_id_from_parent; local_surface_id_from_parent_ = local_surface_id_from_parent;
has_pushed_local_surface_id_from_parent_ = false; has_pushed_local_surface_id_from_parent_ = false;
UpdateDeferCommitsInternal(); UpdateDeferCommitsInternal();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stdint.h> #include <stdint.h>
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/trace_event/trace_event.h"
namespace viz { namespace viz {
...@@ -36,6 +37,22 @@ const LocalSurfaceId& ChildLocalSurfaceIdAllocator::GenerateId() { ...@@ -36,6 +37,22 @@ const LocalSurfaceId& ChildLocalSurfaceIdAllocator::GenerateId() {
kInvalidParentSequenceNumber); kInvalidParentSequenceNumber);
++current_local_surface_id_.child_sequence_number_; ++current_local_surface_id_.child_sequence_number_;
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Embed.Flow",
TRACE_ID_GLOBAL(current_local_surface_id_.embed_trace_id()),
TRACE_EVENT_FLAG_FLOW_OUT, "step",
"ChildLocalSurfaceIdAllocator::GenerateId", "local_surface_id",
current_local_surface_id_.ToString());
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Submission.Flow",
TRACE_ID_GLOBAL(current_local_surface_id_.submission_trace_id()),
TRACE_EVENT_FLAG_FLOW_OUT, "step",
"ChildLocalSurfaceIdAllocator::GenerateId", "local_surface_id",
current_local_surface_id_.ToString());
return current_local_surface_id_; return current_local_surface_id_;
} }
......
...@@ -109,6 +109,14 @@ class VIZ_COMMON_EXPORT LocalSurfaceId { ...@@ -109,6 +109,14 @@ class VIZ_COMMON_EXPORT LocalSurfaceId {
return embed_token_; return embed_token_;
} }
// The |embed_trace_id| is used as the id for trace events associated with
// embedding this LocalSurfaceId.
uint64_t embed_trace_id() const { return hash() << 1; }
// The |submission_trace_id| is used as the id for trace events associated
// with submission of a CompositorFrame to a surface with this LocalSurfaceId.
uint64_t submission_trace_id() const { return (hash() << 1) | 1; }
bool operator==(const LocalSurfaceId& other) const { bool operator==(const LocalSurfaceId& other) const {
return parent_sequence_number_ == other.parent_sequence_number_ && return parent_sequence_number_ == other.parent_sequence_number_ &&
child_sequence_number_ == other.child_sequence_number_ && child_sequence_number_ == other.child_sequence_number_ &&
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/trace_event/trace_event.h"
namespace viz { namespace viz {
...@@ -13,9 +14,11 @@ base::LazyInstance<LocalSurfaceId>::Leaky g_invalid_local_surface_id = ...@@ -13,9 +14,11 @@ base::LazyInstance<LocalSurfaceId>::Leaky g_invalid_local_surface_id =
LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
ParentLocalSurfaceIdAllocator::ParentLocalSurfaceIdAllocator() ParentLocalSurfaceIdAllocator::ParentLocalSurfaceIdAllocator()
: current_local_surface_id_(kInitialParentSequenceNumber, : current_local_surface_id_(kInvalidParentSequenceNumber,
kInitialChildSequenceNumber, kInitialChildSequenceNumber,
base::UnguessableToken::Create()) {} base::UnguessableToken::Create()) {
GenerateId();
}
bool ParentLocalSurfaceIdAllocator::UpdateFromChild( bool ParentLocalSurfaceIdAllocator::UpdateFromChild(
const LocalSurfaceId& child_allocated_local_surface_id) { const LocalSurfaceId& child_allocated_local_surface_id) {
...@@ -24,6 +27,13 @@ bool ParentLocalSurfaceIdAllocator::UpdateFromChild( ...@@ -24,6 +27,13 @@ bool ParentLocalSurfaceIdAllocator::UpdateFromChild(
current_local_surface_id_.child_sequence_number_ = current_local_surface_id_.child_sequence_number_ =
child_allocated_local_surface_id.child_sequence_number_; child_allocated_local_surface_id.child_sequence_number_;
is_invalid_ = false; is_invalid_ = false;
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Embed.Flow",
TRACE_ID_GLOBAL(current_local_surface_id_.embed_trace_id()),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step",
"UpdateFromChild", "local_surface_id",
current_local_surface_id_.ToString());
return true; return true;
} }
return false; return false;
...@@ -42,6 +52,22 @@ const LocalSurfaceId& ParentLocalSurfaceIdAllocator::GenerateId() { ...@@ -42,6 +52,22 @@ const LocalSurfaceId& ParentLocalSurfaceIdAllocator::GenerateId() {
if (!is_allocation_suppressed_) if (!is_allocation_suppressed_)
++current_local_surface_id_.parent_sequence_number_; ++current_local_surface_id_.parent_sequence_number_;
is_invalid_ = false; is_invalid_ = false;
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Embed.Flow",
TRACE_ID_GLOBAL(current_local_surface_id_.embed_trace_id()),
TRACE_EVENT_FLAG_FLOW_OUT, "step",
"ParentLocalSurfaceIdAllocator::GenerateId", "local_surface_id",
current_local_surface_id_.ToString());
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Submission.Flow",
TRACE_ID_GLOBAL(current_local_surface_id_.submission_trace_id()),
TRACE_EVENT_FLAG_FLOW_OUT, "step",
"ParentLocalSurfaceIdAllocator::GenerateId", "local_surface_id",
current_local_surface_id_.ToString());
return current_local_surface_id_; return current_local_surface_id_;
} }
......
...@@ -268,11 +268,21 @@ CompositorFrameSinkSupport::MaybeSubmitCompositorFrame( ...@@ -268,11 +268,21 @@ CompositorFrameSinkSupport::MaybeSubmitCompositorFrame(
mojom::CompositorFrameSink::SubmitCompositorFrameSyncCallback callback) { mojom::CompositorFrameSink::SubmitCompositorFrameSyncCallback callback) {
TRACE_EVENT1("viz", "CompositorFrameSinkSupport::MaybeSubmitCompositorFrame", TRACE_EVENT1("viz", "CompositorFrameSinkSupport::MaybeSubmitCompositorFrame",
"FrameSinkId", frame_sink_id_.ToString()); "FrameSinkId", frame_sink_id_.ToString());
TRACE_EVENT_WITH_FLOW1( TRACE_EVENT_WITH_FLOW1(
"viz,benchmark", "Graphics.Pipeline", "viz,benchmark", "Graphics.Pipeline",
TRACE_ID_GLOBAL(frame.metadata.begin_frame_ack.trace_id), TRACE_ID_GLOBAL(frame.metadata.begin_frame_ack.trace_id),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step", TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step",
"ReceiveCompositorFrame"); "ReceiveCompositorFrame");
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Submission.Flow",
TRACE_ID_GLOBAL(local_surface_id.submission_trace_id()),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step",
"ReceiveCompositorFrame", "local_surface_id",
local_surface_id.ToString());
DCHECK(local_surface_id.is_valid()); DCHECK(local_surface_id.is_valid());
DCHECK(!frame.render_pass_list.empty()); DCHECK(!frame.render_pass_list.empty());
DCHECK(!frame.size_in_pixels().IsEmpty()); DCHECK(!frame.size_in_pixels().IsEmpty());
......
...@@ -29,7 +29,15 @@ Surface::Surface(const SurfaceInfo& surface_info, ...@@ -29,7 +29,15 @@ Surface::Surface(const SurfaceInfo& surface_info,
: surface_info_(surface_info), : surface_info_(surface_info),
surface_manager_(surface_manager), surface_manager_(surface_manager),
surface_client_(std::move(surface_client)), surface_client_(std::move(surface_client)),
needs_sync_tokens_(needs_sync_tokens) {} needs_sync_tokens_(needs_sync_tokens) {
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Submission.Flow",
TRACE_ID_GLOBAL(
surface_info.id().local_surface_id().submission_trace_id()),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step",
"SurfaceCreated", "surface_id", surface_info.id().ToString());
}
Surface::~Surface() { Surface::~Surface() {
ClearCopyRequests(); ClearCopyRequests();
...@@ -324,6 +332,14 @@ void Surface::ActivateFrame(FrameData frame_data, ...@@ -324,6 +332,14 @@ void Surface::ActivateFrame(FrameData frame_data,
surface_client_->OnSurfaceActivated(this); surface_client_->OnSurfaceActivated(this);
if (!seen_first_frame_activation_) { if (!seen_first_frame_activation_) {
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Submission.Flow",
TRACE_ID_GLOBAL(
surface_info_.id().local_surface_id().submission_trace_id()),
TRACE_EVENT_FLAG_FLOW_IN, "step", "FirstSurfaceActivation",
"surface_id", surface_info_.id().ToString());
seen_first_frame_activation_ = true; seen_first_frame_activation_ = true;
surface_manager_->FirstSurfaceActivation(surface_info_); surface_manager_->FirstSurfaceActivation(surface_info_);
} }
......
...@@ -317,6 +317,13 @@ void SurfaceManager::AddSurfaceReferenceImpl( ...@@ -317,6 +317,13 @@ void SurfaceManager::AddSurfaceReferenceImpl(
return; return;
} }
TRACE_EVENT_WITH_FLOW2(
TRACE_DISABLED_BY_DEFAULT("viz.surface_id_flow"),
"LocalSurfaceId.Embed.Flow",
TRACE_ID_GLOBAL(child_id.local_surface_id().embed_trace_id()),
TRACE_EVENT_FLAG_FLOW_IN, "step", "NewReference", "reference",
reference.ToString());
references_[parent_id].children.insert(child_id); references_[parent_id].children.insert(child_id);
references_[child_id].parents.insert(parent_id); references_[child_id].parents.insert(parent_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment