From 967d4926670fcd9b2f2da081e4d60715ed8aa7a3 Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Tue, 31 Aug 2021 17:21:02 -0700 Subject: [PATCH] merge accounting of the (mutually exclusive) picture and dl cache entries in reported statistics (flutter/engine#28392) --- engine/src/flutter/flow/raster_cache.cc | 36 +++++++------------ engine/src/flutter/flow/raster_cache.h | 15 ++------ engine/src/flutter/shell/common/shell.cc | 3 -- .../flutter/shell/common/shell_unittests.cc | 2 +- 4 files changed, 16 insertions(+), 40 deletions(-) diff --git a/engine/src/flutter/flow/raster_cache.cc b/engine/src/flutter/flow/raster_cache.cc index d1671a1c1a..7412bc46ac 100644 --- a/engine/src/flutter/flow/raster_cache.cc +++ b/engine/src/flutter/flow/raster_cache.cc @@ -413,11 +413,7 @@ size_t RasterCache::GetLayerCachedEntriesCount() const { } size_t RasterCache::GetPictureCachedEntriesCount() const { - return picture_cache_.size(); -} - -size_t RasterCache::GetDisplayListCachedEntriesCount() const { - return display_list_cache_.size(); + return picture_cache_.size() + display_list_cache_.size(); } void RasterCache::SetCheckboardCacheImages(bool checkerboard) { @@ -434,14 +430,13 @@ void RasterCache::SetCheckboardCacheImages(bool checkerboard) { void RasterCache::TraceStatsToTimeline() const { #if !FLUTTER_RELEASE - FML_TRACE_COUNTER("flutter", "RasterCache", reinterpret_cast(this), - "LayerCount", layer_cache_.size(), "LayerMBytes", - EstimateLayerCacheByteSize() / kMegaByteSizeInBytes, - "PictureCount", picture_cache_.size(), "PictureMBytes", - EstimatePictureCacheByteSize() / kMegaByteSizeInBytes, - "DisplayListCount", display_list_cache_.size(), - "DisplayListMBytes", - EstimateDisplayListCacheByteSize() / kMegaByteSizeInBytes); + FML_TRACE_COUNTER( + "flutter", // + "RasterCache", reinterpret_cast(this), // + "LayerCount", GetLayerCachedEntriesCount(), // + "LayerMBytes", EstimateLayerCacheByteSize() / kMegaByteSizeInBytes, // + "PictureCount", GetPictureCachedEntriesCount(), // + "PictureMBytes", EstimatePictureCacheByteSize() / kMegaByteSizeInBytes); #endif // !FLUTTER_RELEASE } @@ -463,17 +458,12 @@ size_t RasterCache::EstimatePictureCacheByteSize() const { picture_cache_bytes += item.second.image->image_bytes(); } } + for (const auto& item : display_list_cache_) { + if (item.second.image) { + picture_cache_bytes += item.second.image->image_bytes(); + } + } return picture_cache_bytes; } -size_t RasterCache::EstimateDisplayListCacheByteSize() const { - size_t display_list_cache_bytes = 0; - for (const auto& item : display_list_cache_) { - if (item.second.image) { - display_list_cache_bytes += item.second.image->image_bytes(); - } - } - return display_list_cache_bytes; -} - } // namespace flutter diff --git a/engine/src/flutter/flow/raster_cache.h b/engine/src/flutter/flow/raster_cache.h index a440ade791..586dc3a413 100644 --- a/engine/src/flutter/flow/raster_cache.h +++ b/engine/src/flutter/flow/raster_cache.h @@ -186,11 +186,10 @@ class RasterCache { size_t GetPictureCachedEntriesCount() const; - size_t GetDisplayListCachedEntriesCount() const; - /** * @brief Estimate how much memory is used by picture raster cache entries in - * bytes. + * bytes, including cache entries in the SkPicture cache and the DisplayList + * cache. * * Only SkImage's memory usage is counted as other objects are often much * smaller compared to SkImage. SkImageInfo::computeMinByteSize is used to @@ -198,16 +197,6 @@ class RasterCache { */ size_t EstimatePictureCacheByteSize() const; - /** - * @brief Estimate how much memory is used by display list raster cache - * entries in bytes. - * - * Only SkImage's memory usage is counted as other objects are often much - * smaller compared to SkImage. SkImageInfo::computeMinByteSize is used to - * estimate the SkImage memory usage. - */ - size_t EstimateDisplayListCacheByteSize() const; - /** * @brief Estimate how much memory is used by layer raster cache entries in * bytes. diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index 6eba4d7547..8d1b52608e 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -1707,9 +1707,6 @@ bool Shell::OnServiceProtocolEstimateRasterCacheMemory( response->AddMember("pictureBytes", raster_cache.EstimatePictureCacheByteSize(), response->GetAllocator()); - response->AddMember("displayListBytes", - raster_cache.EstimateDisplayListCacheByteSize(), - response->GetAllocator()); return true; } diff --git a/engine/src/flutter/shell/common/shell_unittests.cc b/engine/src/flutter/shell/common/shell_unittests.cc index d083b66d45..eff95541eb 100644 --- a/engine/src/flutter/shell/common/shell_unittests.cc +++ b/engine/src/flutter/shell/common/shell_unittests.cc @@ -2185,7 +2185,7 @@ TEST_F(ShellTest, OnServiceProtocolEstimateRasterCacheMemoryWorks) { document.Accept(writer); std::string expected_json = "{\"type\":\"EstimateRasterCacheMemory\",\"layerBytes\":40000,\"picture" - "Bytes\":400,\"displayListBytes\":0}"; + "Bytes\":400}"; std::string actual_json = buffer.GetString(); ASSERT_EQ(actual_json, expected_json);