Loading libs/hwui/pipeline/skia/SkiaMemoryTracer.cpp +10 −5 Original line number Diff line number Diff line Loading @@ -86,12 +86,9 @@ void SkiaMemoryTracer::processElement() { } } // if we don't have a resource name then we don't know how to label the // data and should abort. // if we don't have a pretty name then use the dumpName if (resourceName == nullptr) { mCurrentElement.clear(); mCurrentValues.clear(); return; resourceName = mCurrentElement.c_str(); } auto result = mResults.find(resourceName); Loading Loading @@ -157,6 +154,14 @@ void SkiaMemoryTracer::logOutput(String8& log) { } } size_t SkiaMemoryTracer::total() { processElement(); if (!strcmp("bytes", mTotalSize.units)) { return mTotalSize.value; } return 0; } void SkiaMemoryTracer::logTotals(String8& log) { TraceValue total = convertUnits(mTotalSize); TraceValue purgeable = convertUnits(mPurgeableSize); Loading libs/hwui/pipeline/skia/SkiaMemoryTracer.h +1 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ public: bool hasOutput(); void logOutput(String8& log); void logTotals(String8& log); size_t total(); void dumpNumericValue(const char* dumpName, const char* valueName, const char* units, uint64_t value) override; Loading libs/hwui/renderthread/CacheManager.cpp +20 −4 Original line number Diff line number Diff line Loading @@ -130,27 +130,43 @@ void CacheManager::trimStaleResources() { mGrContext->purgeResourcesNotUsedInMs(std::chrono::seconds(30)); } void CacheManager::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) { *cpuUsage = 0; *gpuUsage = 0; if (!mGrContext) { return; } skiapipeline::SkiaMemoryTracer cpuTracer("category", true); SkGraphics::DumpMemoryStatistics(&cpuTracer); *cpuUsage += cpuTracer.total(); skiapipeline::SkiaMemoryTracer gpuTracer("category", true); mGrContext->dumpMemoryStatistics(&gpuTracer); *gpuUsage += gpuTracer.total(); } void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState) { if (!mGrContext) { log.appendFormat("No valid cache instance.\n"); return; } log.appendFormat("Font Cache (CPU):\n"); log.appendFormat(" Size: %.2f kB \n", SkGraphics::GetFontCacheUsed() / 1024.0f); log.appendFormat(" Glyph Count: %d \n", SkGraphics::GetFontCacheCountUsed()); std::vector<skiapipeline::ResourcePair> cpuResourceMap = { {"skia/sk_resource_cache/bitmap_", "Bitmaps"}, {"skia/sk_resource_cache/rrect-blur_", "Masks"}, {"skia/sk_resource_cache/rects-blur_", "Masks"}, {"skia/sk_resource_cache/tessellated", "Shadows"}, {"skia/sk_glyph_cache", "Glyph Cache"}, }; skiapipeline::SkiaMemoryTracer cpuTracer(cpuResourceMap, false); SkGraphics::DumpMemoryStatistics(&cpuTracer); if (cpuTracer.hasOutput()) { log.appendFormat("CPU Caches:\n"); cpuTracer.logOutput(log); log.appendFormat(" Glyph Count: %d \n", SkGraphics::GetFontCacheCountUsed()); log.appendFormat("Total CPU memory usage:\n"); cpuTracer.logTotals(log); } skiapipeline::SkiaMemoryTracer gpuTracer("category", true); Loading libs/hwui/renderthread/CacheManager.h +1 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ public: void trimMemory(TrimMemoryMode mode); void trimStaleResources(); void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr); void getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage); size_t getCacheSize() const { return mMaxResourceBytes; } size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; } Loading libs/hwui/renderthread/RenderProxy.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -195,6 +195,17 @@ void RenderProxy::trimMemory(int level) { } } void RenderProxy::purgeCaches() { if (RenderThread::hasInstance()) { RenderThread& thread = RenderThread::getInstance(); thread.queue().post([&thread]() { if (thread.getGrContext()) { thread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::Complete); } }); } } void RenderProxy::overrideProperty(const char* name, const char* value) { // expensive, but block here since name/value pointers owned by caller RenderThread::getInstance().queue().runSync( Loading Loading @@ -256,6 +267,13 @@ void RenderProxy::dumpGraphicsMemory(int fd, bool includeProfileData) { } } void RenderProxy::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) { if (RenderThread::hasInstance()) { auto& thread = RenderThread::getInstance(); thread.queue().runSync([&]() { thread.getMemoryUsage(cpuUsage, gpuUsage); }); } } void RenderProxy::setProcessStatsBuffer(int fd) { auto& rt = RenderThread::getInstance(); rt.queue().post([&rt, fd = dup(fd)]() { Loading Loading
libs/hwui/pipeline/skia/SkiaMemoryTracer.cpp +10 −5 Original line number Diff line number Diff line Loading @@ -86,12 +86,9 @@ void SkiaMemoryTracer::processElement() { } } // if we don't have a resource name then we don't know how to label the // data and should abort. // if we don't have a pretty name then use the dumpName if (resourceName == nullptr) { mCurrentElement.clear(); mCurrentValues.clear(); return; resourceName = mCurrentElement.c_str(); } auto result = mResults.find(resourceName); Loading Loading @@ -157,6 +154,14 @@ void SkiaMemoryTracer::logOutput(String8& log) { } } size_t SkiaMemoryTracer::total() { processElement(); if (!strcmp("bytes", mTotalSize.units)) { return mTotalSize.value; } return 0; } void SkiaMemoryTracer::logTotals(String8& log) { TraceValue total = convertUnits(mTotalSize); TraceValue purgeable = convertUnits(mPurgeableSize); Loading
libs/hwui/pipeline/skia/SkiaMemoryTracer.h +1 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ public: bool hasOutput(); void logOutput(String8& log); void logTotals(String8& log); size_t total(); void dumpNumericValue(const char* dumpName, const char* valueName, const char* units, uint64_t value) override; Loading
libs/hwui/renderthread/CacheManager.cpp +20 −4 Original line number Diff line number Diff line Loading @@ -130,27 +130,43 @@ void CacheManager::trimStaleResources() { mGrContext->purgeResourcesNotUsedInMs(std::chrono::seconds(30)); } void CacheManager::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) { *cpuUsage = 0; *gpuUsage = 0; if (!mGrContext) { return; } skiapipeline::SkiaMemoryTracer cpuTracer("category", true); SkGraphics::DumpMemoryStatistics(&cpuTracer); *cpuUsage += cpuTracer.total(); skiapipeline::SkiaMemoryTracer gpuTracer("category", true); mGrContext->dumpMemoryStatistics(&gpuTracer); *gpuUsage += gpuTracer.total(); } void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState) { if (!mGrContext) { log.appendFormat("No valid cache instance.\n"); return; } log.appendFormat("Font Cache (CPU):\n"); log.appendFormat(" Size: %.2f kB \n", SkGraphics::GetFontCacheUsed() / 1024.0f); log.appendFormat(" Glyph Count: %d \n", SkGraphics::GetFontCacheCountUsed()); std::vector<skiapipeline::ResourcePair> cpuResourceMap = { {"skia/sk_resource_cache/bitmap_", "Bitmaps"}, {"skia/sk_resource_cache/rrect-blur_", "Masks"}, {"skia/sk_resource_cache/rects-blur_", "Masks"}, {"skia/sk_resource_cache/tessellated", "Shadows"}, {"skia/sk_glyph_cache", "Glyph Cache"}, }; skiapipeline::SkiaMemoryTracer cpuTracer(cpuResourceMap, false); SkGraphics::DumpMemoryStatistics(&cpuTracer); if (cpuTracer.hasOutput()) { log.appendFormat("CPU Caches:\n"); cpuTracer.logOutput(log); log.appendFormat(" Glyph Count: %d \n", SkGraphics::GetFontCacheCountUsed()); log.appendFormat("Total CPU memory usage:\n"); cpuTracer.logTotals(log); } skiapipeline::SkiaMemoryTracer gpuTracer("category", true); Loading
libs/hwui/renderthread/CacheManager.h +1 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ public: void trimMemory(TrimMemoryMode mode); void trimStaleResources(); void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr); void getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage); size_t getCacheSize() const { return mMaxResourceBytes; } size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; } Loading
libs/hwui/renderthread/RenderProxy.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -195,6 +195,17 @@ void RenderProxy::trimMemory(int level) { } } void RenderProxy::purgeCaches() { if (RenderThread::hasInstance()) { RenderThread& thread = RenderThread::getInstance(); thread.queue().post([&thread]() { if (thread.getGrContext()) { thread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::Complete); } }); } } void RenderProxy::overrideProperty(const char* name, const char* value) { // expensive, but block here since name/value pointers owned by caller RenderThread::getInstance().queue().runSync( Loading Loading @@ -256,6 +267,13 @@ void RenderProxy::dumpGraphicsMemory(int fd, bool includeProfileData) { } } void RenderProxy::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) { if (RenderThread::hasInstance()) { auto& thread = RenderThread::getInstance(); thread.queue().runSync([&]() { thread.getMemoryUsage(cpuUsage, gpuUsage); }); } } void RenderProxy::setProcessStatsBuffer(int fd) { auto& rt = RenderThread::getInstance(); rt.queue().post([&rt, fd = dup(fd)]() { Loading