From 88b2d88817097bb8a4fe294420ba03b211163ac4 Mon Sep 17 00:00:00 2001 From: Huihong Luo Date: Fri, 4 Jun 2021 15:19:38 -0700 Subject: Put debug/log code under verbose flag So they are not invoked when verbose flag is off: (1) that the compiler will optimize to strip out no-op loops (2) statements are put into a local function variable so invoked only with ALOGV. Bug: 189837811 Test: examine logcat Change-Id: I00ba0433f47586d8356423b8147cf9786f1045b9 --- .../CompositionEngine/src/planner/Flattener.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp b/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp index fb24fa4160..550fdebea4 100644 --- a/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp +++ b/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp @@ -231,6 +231,7 @@ bool Flattener::mergeWithCachedSets(const std::vector& layers return false; } + // the compiler should strip out the following no-op loops when ALOGV is off ALOGV("[%s] Incoming layers:", __func__); for (const LayerState* layer : layers) { ALOGV("%s", layer->getName().c_str()); @@ -238,9 +239,12 @@ bool Flattener::mergeWithCachedSets(const std::vector& layers ALOGV("[%s] Current layers:", __func__); for (const CachedSet& layer : mLayers) { - std::string dump; - layer.dump(dump); - ALOGV("%s", dump.c_str()); + const auto dumper = [&] { + std::string dump; + layer.dump(dump); + return dump; + }; + ALOGV("%s", dumper().c_str()); } auto currentLayerIter = mLayers.begin(); @@ -473,9 +477,14 @@ void Flattener::buildCachedSets(time_point now) { ++mCachedSetCreationCount; mCachedSetCreationCost += mNewCachedSet->getCreationCost(); - std::string setDump; - mNewCachedSet->dump(setDump); - ALOGV("[%s] Added new cached set:\n%s", __func__, setDump.c_str()); + + // note the compiler should strip the follow no-op statements when ALOGV is off + const auto dumper = [&] { + std::string setDump; + mNewCachedSet->dump(setDump); + return setDump; + }; + ALOGV("[%s] Added new cached set:\n%s", __func__, dumper().c_str()); } } // namespace android::compositionengine::impl::planner -- cgit v1.2.3-59-g8ed1b