SF: Track transaction tracing states in order
Need to preserve order when rebuilding layers
from the traces.
Test: TreeHugger
Bug: 200284593
Change-Id: Ie33f9c22f60d3bf3016b04b9b39dcfdb25165364
diff --git a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
index 7e12313..783b36e 100644
--- a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
+++ b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
@@ -43,7 +43,7 @@
}
proto::TransactionState TransactionProtoParser::toProto(
- const std::unordered_map<int32_t /* layerId */, TracingLayerState> states) {
+ const std::map<int32_t /* layerId */, TracingLayerState> states) {
proto::TransactionState proto;
for (auto& [layerId, state] : states) {
proto::LayerState layerProto = toProto(state, nullptr);
diff --git a/services/surfaceflinger/Tracing/TransactionProtoParser.h b/services/surfaceflinger/Tracing/TransactionProtoParser.h
index 619ee05..16e9b5e 100644
--- a/services/surfaceflinger/Tracing/TransactionProtoParser.h
+++ b/services/surfaceflinger/Tracing/TransactionProtoParser.h
@@ -51,7 +51,7 @@
static proto::TransactionState toProto(const TransactionState&, LayerHandleToIdFn getLayerIdFn,
DisplayHandleToIdFn getDisplayIdFn);
static proto::TransactionState toProto(
- const std::unordered_map<int32_t /* layerId */, TracingLayerState>);
+ const std::map<int32_t /* layerId */, TracingLayerState>);
static proto::LayerCreationArgs toProto(const TracingLayerCreationArgs& args);
diff --git a/services/surfaceflinger/Tracing/TransactionTracing.h b/services/surfaceflinger/Tracing/TransactionTracing.h
index 0aa22ed..546ac7a 100644
--- a/services/surfaceflinger/Tracing/TransactionTracing.h
+++ b/services/surfaceflinger/Tracing/TransactionTracing.h
@@ -85,8 +85,7 @@
std::vector<proto::LayerCreationArgs> mCreatedLayers GUARDED_BY(mTraceLock);
std::unordered_map<BBinder* /* layerHandle */, int32_t /* layerId */> mLayerHandles
GUARDED_BY(mTraceLock);
- std::unordered_map<int32_t /* layerId */, TracingLayerState> mStartingStates
- GUARDED_BY(mTraceLock);
+ std::map<int32_t /* layerId */, TracingLayerState> mStartingStates GUARDED_BY(mTraceLock);
// We do not want main thread to block so main thread will try to acquire mMainThreadLock,
// otherwise will push data to temporary container.
diff --git a/services/surfaceflinger/tests/unittests/TransactionTracingTest.cpp b/services/surfaceflinger/tests/unittests/TransactionTracingTest.cpp
index ffe5671..4e49c18 100644
--- a/services/surfaceflinger/tests/unittests/TransactionTracingTest.cpp
+++ b/services/surfaceflinger/tests/unittests/TransactionTracingTest.cpp
@@ -165,7 +165,7 @@
mTracing->onLayerAdded(fakeLayerHandle->localBinder(), mParentLayerId, "parent",
123 /* flags */, -1 /* parentId */);
const sp<IBinder> fakeChildLayerHandle = new BBinder();
- mTracing->onLayerAdded(fakeChildLayerHandle->localBinder(), 2 /* layerId */, "child",
+ mTracing->onLayerAdded(fakeChildLayerHandle->localBinder(), mChildLayerId, "child",
456 /* flags */, mParentLayerId);
// add some layer transaction
@@ -179,7 +179,8 @@
transaction.states.add(layerState);
ComposerState childState;
childState.state.surface = fakeChildLayerHandle;
- layerState.state.z = 43;
+ childState.state.what = layer_state_t::eLayerChanged;
+ childState.state.z = 43;
transaction.states.add(childState);
mTracing->addQueuedTransaction(transaction);
@@ -227,6 +228,7 @@
}
int mParentLayerId = 1;
+ int mChildLayerId = 2;
int64_t mVsyncId = 0;
int64_t VSYNC_ID_FIRST_LAYER_CHANGE;
int64_t VSYNC_ID_SECOND_LAYER_CHANGE;
@@ -244,8 +246,11 @@
EXPECT_GT(proto.entry().size(), 0);
EXPECT_GT(proto.entry(0).transactions().size(), 0);
EXPECT_GT(proto.entry(0).added_layers().size(), 0);
- EXPECT_GT(proto.entry(0).transactions(0).layer_changes().size(), 0);
+ EXPECT_EQ(proto.entry(0).transactions(0).layer_changes().size(), 2);
+ EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(0).layer_id(), mParentLayerId);
EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(0).z(), 42);
+ EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(1).layer_id(), mChildLayerId);
+ EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(1).z(), 43);
}
TEST_F(TransactionTracingLayerHandlingTest, updateStartingState) {