Do not create new LayerTracing instance within LayerTraceGenerator
LayerDataSource holds a reference to LayerTracing in order to notify
LayerTracing about perfetto events (OnSetup, OnStart, OnFlush, OnStop).
Having multiple instances of LayerTracing complicates things, as it arises
the question of which instance(s) should be referenced and notified
by LayerDataSource.
This commit eliminates the problem at its root, by avoiding to create
an extra LayerTracing instance within LayerTraceGenerator.
Bug: b/293429094
Test: atest transactiontrace_testsuite && atest SurfaceFlinger_test
Change-Id: Id2cf232d1198f9470b476d9a9d9eb86c21246c61
diff --git a/services/surfaceflinger/Tracing/LayerTracing.cpp b/services/surfaceflinger/Tracing/LayerTracing.cpp
index 657df16..403e105 100644
--- a/services/surfaceflinger/Tracing/LayerTracing.cpp
+++ b/services/surfaceflinger/Tracing/LayerTracing.cpp
@@ -36,6 +36,10 @@
LayerDataSource::Initialize(*this);
}
+LayerTracing::LayerTracing(std::ostream& outStream) : LayerTracing() {
+ mOutStream = std::ref(outStream);
+}
+
LayerTracing::~LayerTracing() {
LayerDataSource::UnregisterLayerTracing();
}
@@ -49,10 +53,6 @@
mTransactionTracing = &transactionTracing;
}
-void LayerTracing::setOutputStream(std::ostream& outStream) {
- mOutStream = std::ref(outStream);
-}
-
void LayerTracing::onStart(Mode mode, uint32_t flags) {
switch (mode) {
case Mode::MODE_ACTIVE: {
@@ -95,7 +95,7 @@
}
auto transactionTrace = mTransactionTracing->writeToProto();
- LayerTraceGenerator{}.generate(transactionTrace, flags);
+ LayerTraceGenerator{}.generate(transactionTrace, flags, *this);
ALOGD("Flushed generated tracing");
}