From cb5926761b47e340554e38fadd5f4b66185fd5af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 18 Jun 2023 14:18:45 +0200 Subject: [PATCH] Add a way to monitor the icon cache from the system info screen. --- Common/UI/IconCache.cpp | 15 +++++++++++++++ Common/UI/IconCache.h | 8 ++++++++ UI/DevScreens.cpp | 15 +++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/Common/UI/IconCache.cpp b/Common/UI/IconCache.cpp index 4326323ef2..7a8ac6c984 100644 --- a/Common/UI/IconCache.cpp +++ b/Common/UI/IconCache.cpp @@ -225,3 +225,18 @@ Draw::Texture *IconCache::BindIconTexture(UIContext *context, const std::string return texture; } + +IconCacheStats IconCache::GetStats() { + IconCacheStats stats{}; + + std::unique_lock lock(lock_); + + for (auto &iter : cache_) { + stats.cachedCount++; + if (iter.second.texture) + stats.textureCount++; + stats.dataSize += iter.second.data.size(); + } + + return stats; +} diff --git a/Common/UI/IconCache.h b/Common/UI/IconCache.h index b16924f46d..b9791a0bf7 100644 --- a/Common/UI/IconCache.h +++ b/Common/UI/IconCache.h @@ -20,6 +20,12 @@ class Texture; // TODO: Possibly make this smarter and use instead of ManagedTexture? +struct IconCacheStats { + size_t cachedCount; + size_t textureCount; // number of cached images that are "live" textures + size_t dataSize; +}; + class IconCache { public: Draw::Texture *BindIconTexture(UIContext *context, const std::string &key); @@ -35,6 +41,8 @@ public: void ClearTextures(); void ClearData(); + IconCacheStats GetStats(); + private: struct Entry { std::string data; diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index bc4a66b723..e31220e940 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -43,6 +43,8 @@ #include "Common/UI/View.h" #include "Common/UI/ViewGroup.h" #include "Common/UI/UI.h" +#include "Common/UI/IconCache.h" +#include "Common/Data/Text/Parsers.h" #include "Common/Profiler/Profiler.h" #include "Common/LogManager.h" @@ -782,6 +784,19 @@ void SystemInfoScreen::CreateTabs() { gpuExtensions->Add(new TextView(extension, new LayoutParams(FILL_PARENT, WRAP_CONTENT)))->SetFocusable(true); } } + + LinearLayout *internals = AddTab("DevSystemInfoInternals", si->T("Internals")); + + internals->Add(new ItemHeader(si->T("Icon cache"))); + IconCacheStats iconStats = g_iconCache.GetStats(); + internals->Add(new InfoItem(si->T("Image data count"), StringFromFormat("%d", iconStats.cachedCount))); + internals->Add(new InfoItem(si->T("Texture count"), StringFromFormat("%d", iconStats.textureCount))); + internals->Add(new InfoItem(si->T("Data size"), NiceSizeFormat(iconStats.dataSize))); + internals->Add(new Choice(di->T("Clear")))->OnClick.Add([&](UI::EventParams &) { + g_iconCache.ClearData(); + RecreateViews(); + return UI::EVENT_DONE; + }); } void AddressPromptScreen::CreatePopupContents(UI::ViewGroup *parent) {