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,
deadline_policy.use_existing_deadline()) {
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;
// We should never block or set a deadline on an invalid
// |primary_surface_id_|.
......@@ -45,6 +53,13 @@ void SurfaceLayer::SetFallbackSurfaceId(const viz::SurfaceId& surface_id) {
if (fallback_surface_id_ == surface_id)
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())
layer_tree_host()->RemoveSurfaceLayerId(fallback_surface_id_);
......
......@@ -33,6 +33,14 @@ void SurfaceLayerImpl::SetPrimarySurfaceId(
deadline_in_frames_ == deadline_in_frames) {
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;
deadline_in_frames_ = deadline_in_frames;
NoteLayerPropertyChanged();
......@@ -42,6 +50,13 @@ void SurfaceLayerImpl::SetFallbackSurfaceId(const viz::SurfaceId& surface_id) {
if (fallback_surface_id_ == surface_id)
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;
NoteLayerPropertyChanged();
}
......
......@@ -156,6 +156,13 @@ void AsyncLayerTreeFrameSink::SubmitCompositorFrame(
last_submitted_device_scale_factor_ = frame.device_scale_factor();
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(
local_surface_id_, std::move(frame), std::move(hit_test_region_list),
tracing_enabled ? base::TimeTicks::Now().since_origin().InMicroseconds()
......
......@@ -1213,6 +1213,13 @@ void LayerTreeHost::SetLocalSurfaceIdFromParent(
const viz::LocalSurfaceId& local_surface_id_from_parent) {
if (local_surface_id_from_parent_ == local_surface_id_from_parent)
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;
has_pushed_local_surface_id_from_parent_ = false;
UpdateDeferCommitsInternal();
......
......@@ -7,6 +7,7 @@
#include <stdint.h>
#include "base/rand_util.h"
#include "base/trace_event/trace_event.h"
namespace viz {
......@@ -36,6 +37,22 @@ const LocalSurfaceId& ChildLocalSurfaceIdAllocator::GenerateId() {
kInvalidParentSequenceNumber);
++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_;
}
......
......@@ -109,6 +109,14 @@ class VIZ_COMMON_EXPORT LocalSurfaceId {
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 {
return parent_sequence_number_ == other.parent_sequence_number_ &&
child_sequence_number_ == other.child_sequence_number_ &&
......
......@@ -6,6 +6,7 @@
#include "base/lazy_instance.h"
#include "base/rand_util.h"
#include "base/trace_event/trace_event.h"
namespace viz {
......@@ -13,9 +14,11 @@ base::LazyInstance<LocalSurfaceId>::Leaky g_invalid_local_surface_id =
LAZY_INSTANCE_INITIALIZER;
ParentLocalSurfaceIdAllocator::ParentLocalSurfaceIdAllocator()
: current_local_surface_id_(kInitialParentSequenceNumber,
: current_local_surface_id_(kInvalidParentSequenceNumber,
kInitialChildSequenceNumber,
base::UnguessableToken::Create()) {}
base::UnguessableToken::Create()) {
GenerateId();
}
bool ParentLocalSurfaceIdAllocator::UpdateFromChild(
const LocalSurfaceId& child_allocated_local_surface_id) {
......@@ -24,6 +27,13 @@ bool ParentLocalSurfaceIdAllocator::UpdateFromChild(
current_local_surface_id_.child_sequence_number_ =
child_allocated_local_surface_id.child_sequence_number_;
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 false;
......@@ -42,6 +52,22 @@ const LocalSurfaceId& ParentLocalSurfaceIdAllocator::GenerateId() {
if (!is_allocation_suppressed_)
++current_local_surface_id_.parent_sequence_number_;
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_;
}
......
......@@ -268,11 +268,21 @@ CompositorFrameSinkSupport::MaybeSubmitCompositorFrame(
mojom::CompositorFrameSink::SubmitCompositorFrameSyncCallback callback) {
TRACE_EVENT1("viz", "CompositorFrameSinkSupport::MaybeSubmitCompositorFrame",
"FrameSinkId", frame_sink_id_.ToString());
TRACE_EVENT_WITH_FLOW1(
"viz,benchmark", "Graphics.Pipeline",
TRACE_ID_GLOBAL(frame.metadata.begin_frame_ack.trace_id),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "step",
"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(!frame.render_pass_list.empty());
DCHECK(!frame.size_in_pixels().IsEmpty());
......
......@@ -29,7 +29,15 @@ Surface::Surface(const SurfaceInfo& surface_info,
: surface_info_(surface_info),
surface_manager_(surface_manager),
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() {
ClearCopyRequests();
......@@ -324,6 +332,14 @@ void Surface::ActivateFrame(FrameData frame_data,
surface_client_->OnSurfaceActivated(this);
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;
surface_manager_->FirstSurfaceActivation(surface_info_);
}
......
......@@ -317,6 +317,13 @@ void SurfaceManager::AddSurfaceReferenceImpl(
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_[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