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
diff --git a/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp b/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp
index fb24fa4..550fdeb 100644
--- a/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp
@@ -231,6 +231,7 @@
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 @@
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 @@
++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