TimeStats: bound the stats pool size
On any device having TimeStats enabled, the stats pool will be cleared once per
day based on the stats pulling schedule. This change just adds an additional
protect in case the layer count explodes during a tracing period.
Test: TimeStatsTest
Change-Id: I3067239c12645008bceb61a1b7e59d8d6f89076a
diff --git a/services/surfaceflinger/TimeStats/TimeStats.cpp b/services/surfaceflinger/TimeStats/TimeStats.cpp
index 93fe7d0..3e3ab18 100644
--- a/services/surfaceflinger/TimeStats/TimeStats.cpp
+++ b/services/surfaceflinger/TimeStats/TimeStats.cpp
@@ -72,8 +72,10 @@
std::string result = "TimeStats miniDump:\n";
std::lock_guard<std::mutex> lock(mMutex);
- android::base::StringAppendF(&result, "Number of tracked layers is %zu\n",
+ android::base::StringAppendF(&result, "Number of layers currently being tracked is %zu\n",
mTimeStatsTracker.size());
+ android::base::StringAppendF(&result, "Number of layers in the stats pool is %zu\n",
+ mTimeStats.stats.size());
return result;
}
@@ -250,6 +252,9 @@
postTime);
std::lock_guard<std::mutex> lock(mMutex);
+ if (!mTimeStats.stats.count(layerName) && mTimeStats.stats.size() >= MAX_NUM_LAYER_STATS) {
+ return;
+ }
if (!mTimeStatsTracker.count(layerID) && mTimeStatsTracker.size() < MAX_NUM_LAYER_RECORDS &&
layerNameIsValid(layerName)) {
mTimeStatsTracker[layerID].layerName = layerName;