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/tools/main.cpp b/services/surfaceflinger/Tracing/tools/main.cpp
index a8ac36a..65e8479 100644
--- a/services/surfaceflinger/Tracing/tools/main.cpp
+++ b/services/surfaceflinger/Tracing/tools/main.cpp
@@ -52,6 +52,8 @@
(argc == 3) ? argv[2] : "/data/misc/wmtrace/layers_trace.winscope";
auto outStream = std::ofstream{outputLayersTracePath, std::ios::binary | std::ios::app};
+ auto layerTracing = LayerTracing{outStream};
+
const bool generateLastEntryOnly =
argc >= 4 && std::string_view(argv[3]) == "--last-entry-only";
@@ -60,7 +62,7 @@
ALOGD("Generating %s...", outputLayersTracePath);
std::cout << "Generating " << outputLayersTracePath << "\n";
- if (!LayerTraceGenerator().generate(transactionTraceFile, traceFlags, outStream,
+ if (!LayerTraceGenerator().generate(transactionTraceFile, traceFlags, layerTracing,
generateLastEntryOnly)) {
std::cout << "Error: Failed to generate layers trace " << outputLayersTracePath;
return -1;