Move SF trace logging into a separate thread
SF trace logging currently happens on the main thread, which affects
performance. Move it to a separate thread to mitigate the overhead.
Use a lock to prevent the drawing state to be updated while it is being
dumped.
Also, allow the buffer size for SF traces to be configured. Current buffer
size is fixed to 100MB, which is unfeasible for phones with lower resources.
Created option 1029 to manually update the buffer size.
To trigger the option use:
- adb shell su root service call SurfaceFlinger 1029 i32 <SIZE>
This option trigger an "Invalid Argument" error if it receives a
negative value.
Finally, just log Winscope trace if visible regions are dirty. SF
currently logs all Winscope frames. It should log only if there is a
change to mitigate resource consumption.
Test: Flash a device. Start a trace. Run systrace. Record a trace. Check
if the `commitTransaction` trace happens in a separate SF thread and
doesn't block the critical path
Change-Id: Ie05ad5c025a185b28209bbc5d26655ba9ff9042b
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 96a21cc..2b524bd 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -367,6 +367,7 @@
friend class BufferStateLayer;
friend class MonitoredProducer;
friend class RegionSamplingThread;
+ friend class SurfaceTracing;
// For unit tests
friend class TestableSurfaceFlinger;
@@ -376,6 +377,7 @@
enum { LOG_FRAME_STATS_PERIOD = 30*60*60 };
static const size_t MAX_LAYERS = 4096;
+ static const int MAX_TRACING_MEMORY = 100 * 1024 * 1024; // 100MB
// We're reference counted, never destroy SurfaceFlinger directly
virtual ~SurfaceFlinger();
@@ -580,7 +582,7 @@
uint32_t setTransactionFlags(uint32_t flags);
uint32_t setTransactionFlags(uint32_t flags, Scheduler::TransactionStart transactionStart);
void latchAndReleaseBuffer(const sp<Layer>& layer);
- void commitTransaction();
+ void commitTransaction() REQUIRES(mStateLock);
bool containsAnyInvalidClientState(const Vector<ComposerState>& states);
bool transactionIsReadyToBeApplied(int64_t desiredPresentTime,
const Vector<ComposerState>& states);
@@ -774,7 +776,6 @@
void prepareFrame(const sp<DisplayDevice>& display);
void doComposition(const sp<DisplayDevice>& display, bool repainEverything);
void doDebugFlashRegions(const sp<DisplayDevice>& display, bool repaintEverything);
- void doTracing(const char* where);
void logLayerStats();
void doDisplayComposition(const sp<DisplayDevice>& display, const Region& dirtyRegion);
@@ -891,6 +892,7 @@
void dumpDisplayIdentificationData(std::string& result) const;
void dumpWideColorInfo(std::string& result) const;
LayersProto dumpProtoInfo(LayerVector::StateSet stateSet) const;
+ void withTracingLock(std::function<void()> operation) REQUIRES(mStateLock);
LayersProto dumpVisibleLayersProtoInfo(const sp<DisplayDevice>& display) const;
bool isLayerTripleBufferingDisabled() const {
@@ -932,6 +934,9 @@
bool mAnimTransactionPending;
SortedVector< sp<Layer> > mLayersPendingRemoval;
+ // guards access to the mDrawing state if tracing is enabled.
+ mutable std::mutex mDrawingStateLock;
+
// global color transform states
Daltonizer mDaltonizer;
float mGlobalSaturationFactor = 1.0f;
@@ -1010,6 +1015,8 @@
bool mPropagateBackpressure = true;
std::unique_ptr<SurfaceInterceptor> mInterceptor{mFactory.createSurfaceInterceptor(this)};
SurfaceTracing mTracing;
+ bool mTracingEnabled = false;
+ bool mTracingEnabledChanged GUARDED_BY(mStateLock) = false;
LayerStats mLayerStats;
std::shared_ptr<TimeStats> mTimeStats;
bool mUseHwcVirtualDisplays = false;