From e926ab508d94a32cfded4778d0f2ed3217cfbce3 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 14 Aug 2019 15:16:00 -0700 Subject: 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 --- services/surfaceflinger/TimeStats/TimeStats.cpp | 7 ++++++- services/surfaceflinger/TimeStats/TimeStats.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/services/surfaceflinger/TimeStats/TimeStats.cpp b/services/surfaceflinger/TimeStats/TimeStats.cpp index 93fe7d056c..3e3ab18e8f 100644 --- a/services/surfaceflinger/TimeStats/TimeStats.cpp +++ b/services/surfaceflinger/TimeStats/TimeStats.cpp @@ -72,8 +72,10 @@ std::string TimeStats::miniDump() { std::string result = "TimeStats miniDump:\n"; std::lock_guard 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 @@ void TimeStats::setPostTime(int32_t layerID, uint64_t frameNumber, const std::st postTime); std::lock_guard 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; diff --git a/services/surfaceflinger/TimeStats/TimeStats.h b/services/surfaceflinger/TimeStats/TimeStats.h index 2bcb5682b0..eed711158a 100644 --- a/services/surfaceflinger/TimeStats/TimeStats.h +++ b/services/surfaceflinger/TimeStats/TimeStats.h @@ -161,6 +161,7 @@ private: GlobalRecord mGlobalRecord; static const size_t MAX_NUM_LAYER_RECORDS = 200; + static const size_t MAX_NUM_LAYER_STATS = 200; }; } // namespace impl -- cgit v1.2.3-59-g8ed1b