Graphics内存数据拆解

https://gerrit.pt.mioffice.cn/c/platform/external/skia/+/5763241

https://gerrit.pt.mioffice.cn/c/platform/frameworks/base/+/5763674

精简+开关:

https://gerrit.pt.mioffice.cn/q/BUGOS2-707079

GL+trace日志增强 — 分析每一帧 vulkan内存申请

创建所有texture的方法中 输出尺寸

正常情况在prepareTree或者renderFrameImpl阶段去创建texture时,都可以正常找到对应的view

如果创建texture阶段在flush layers,则需要添加更详细的tag,如下:

07-11 16:27:23.764 18977 19062 E ndroid.systemui: WWWLLLTTT - GrVkGpu::onCreateTexture
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #00 pc 0000000000756d08  /system/lib64/libhwui.so (GrVkGpu::onCreateTexture(SkISize, GrBackendFormat const&, skgpu::Renderable, int, skgpu::Budgeted, skgpu::Protected, int, unsigned int, std::__1::basic_string_view<char, std::__1::char_traits<char>>)+488) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #01 pc 0000000000621d38  /system/lib64/libhwui.so (GrGpu::createTextureCommon(SkISize, GrBackendFormat const&, GrTextureType, skgpu::Renderable, int, skgpu::Budgeted, skgpu::Protected, int, unsigned int, std::__1::basic_string_view<char, std::__1::char_traits<char>>)+280) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #02 pc 0000000000621e88  /system/lib64/libhwui.so (GrGpu::createTexture(SkISize, GrBackendFormat const&, GrTextureType, skgpu::Renderable, int, skgpu::Mipmapped, skgpu::Budgeted, skgpu::Protected, std::__1::basic_string_view<char, std::__1::char_traits<char>>)+120) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #03 pc 000000000063dcec  /system/lib64/libhwui.so (GrResourceProvider::createTexture(SkISize, GrBackendFormat const&, GrTextureType, skgpu::Renderable, int, skgpu::Mipmapped, skgpu::Budgeted, skgpu::Protected, std::__1::basic_string_view<char, std::__1::char_traits<char>>)+332) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #04 pc 0000000000642264  /system/lib64/libhwui.so (GrSurfaceProxy::createSurfaceImpl(GrResourceProvider*, int, skgpu::Renderable, skgpu::Mipmapped) const+132) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #05 pc 000000000064566c  /system/lib64/libhwui.so (virtual thunk to GrTextureRenderTargetProxy::createSurface(GrResourceProvider*) const+108) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #06 pc 00000000006351e4  /system/lib64/libhwui.so (GrResourceAllocator::Register::instantiateSurface(GrSurfaceProxy*, GrResourceProvider*)+116) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #07 pc 0000000000636004  /system/lib64/libhwui.so (GrResourceAllocator::assign()+84) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #08 pc 000000000060de98  /system/lib64/libhwui.so (GrDrawingManager::flush(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*)+1688) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #09 pc 000000000060ee30  /system/lib64/libhwui.so (GrDrawingManager::flushSurfaces(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*)+176) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #10 pc 000000000060807c  /system/lib64/libhwui.so (GrDirectContextPriv::flushSurfaces(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*)+236) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #11 pc 0000000000605ce0  /system/lib64/libhwui.so (GrDirectContext::flush(SkSurface*, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&)+160) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #12 pc 0000000000354744  /system/lib64/libhwui.so (android::uirenderer::renderthread::VulkanManager::finishFrame(SkSurface*)+436) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #13 pc 0000000000347620  /system/lib64/libhwui.so (android::uirenderer::skiapipeline::SkiaVulkanPipeline::draw(android::uirenderer::renderthread::Frame const&, SkRect const&, SkRect const&, android::uirenderer::LightGeometry const&, android::uirenderer::LayerUpdateQueue*, android::uirenderer::Rect const&, bool, android::uirenderer::LightInfo const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>> const&, android::uirenderer::FrameInfoVisualizer*, android::uirenderer::renderthread::HardwareBufferRenderParams const&, std::__1::mutex&, android::Region const&)+496) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #14 pc 00000000002e3220  /system/lib64/libhwui.so (android::uirenderer::renderthread::CanvasContext::draw(bool)+1408) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #15 pc 00000000002e702c  /system/lib64/libhwui.so (android::uirenderer::renderthread::DrawFrameTask::run()+844) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #16 pc 00000000002f5f80  /system/lib64/libhwui.so (android::uirenderer::WorkQueue::process()+592) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #17 pc 00000000003591b4  /system/lib64/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+116) (BuildId: 64598b83b3301756de9e829f9f0215da)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #18 pc 000000000001a0e8  /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+248) (BuildId: 53608a825a5da3b6272e26214a673ed8)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #19 pc 000000000001c174  /system/lib64/libutils.so (libutil_thread_trampoline(void*) (.__uniq.226528677032898775202282855395389835431)+20) (BuildId: 53608a825a5da3b6272e26214a673ed8)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #20 pc 0000000000083f3c  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+236) (BuildId: 517881b6f57d65e4cf2b8b1f5d3a20f4)
07-11 16:27:23.784 18977 19062 D WWWLLLTTT-onCreateTexture:   #21 pc 0000000000076460  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 517881b6f57d65e4cf2b8b1f5d3a20
  • onCreateTexture大部分通过GrResourceAllocator::assign()调用下去,其中会遍历Interval,其他非GrResourceAllocator::assign()需要根据不同的allocate堆栈添加对应的tag。

//external/skia/src/gpu/ganesh/GrResourceAllocator.cpp

bool GrResourceAllocator::assign() {
    if (fFailedInstantiation) {
        return false;
    }
    SkASSERT(fPlanned && !fAssigned);
    SkDEBUGCODE(fAssigned = true;)
    auto resourceProvider = fDContext->priv().resourceProvider();
    //从fFinishedIntvls中按顺序取出Interval,一个optask会对应多个intvl,需要在intvl收集的时候就找到其对应的optask
    while (Interval* cur = fFinishedIntvls.popHead()) {
        if (fFailedInstantiation) {
            break;
        }
        if (cur->proxy()->isInstantiated()) {
            continue;
        }
        if (cur->proxy()->isLazy()) {
            fFailedInstantiation = !cur->proxy()->priv().doLazyInstantiation(resourceProvider);
            continue;
        }
        Register* r = cur->getRegister();
        SkASSERT(r);
        fFailedInstantiation = !r->instantiateSurface(cur->proxy(), resourceProvider);
    }
    return !fFailedInstantiation;
}
  • 需要在Interval初始化时就创建一个uniqueID,当Interval 去createTexture时,就输出构造Interval时创建的ID;

  • 同时在Interval创建时,打印出task id,这样就可以通过 Interval id task id view的步骤找到对应的veiw

GL mtrack 拆解实战

通过cat mem_profile获取详细buffer通道,主要受Channel: GFX Device Memory CPU Uncached 、Vulkan Bound Buffer Memory、Vulkan Bound Image Memory三部分影响,具体buffer大小如下:

Channel: GFX Device Memory CPU Uncached (Total memory: 21606400)
 Bin id             Count / Memory
 13:                    2 / 8192
 14:                    8 / 65536
 17:                    3 / 270336
 21:                    2 / 2105344
 22:                    1 / 2101248
 23:                    4 / 17055744
 
Channel: Vulkan Bound Buffer Memory (Total memory: 385284)
 Bin id             Count / Memory
  8:                    2 / 372
  9:                   33 / 12560
 10:                   18 / 11520
 11:                   12 / 18816
 15:                    1 / 30720
 16:                    5 / 180224
 17:                    2 / 131072
 
Channel: Vulkan Bound Image Memory (Total memory: 17353152)
 Bin id             Count / Memory
 14:                   16 / 187456
 15:                   20 / 420992
 16:                   11 / 377472
 18:                    3 / 651264
 19:                    2 / 774656
 20:                   16 / 10484864
 23:                    1 / 4456448
 
 操作后:
 Channel: GFX Device Memory CPU Uncached (Total memory: 25804800)
 Bin id             Count / Memory
 13:                    2 / 8192
 14:                    8 / 65536
 17:                    3 / 270336
 21:                    2 / 2105344
 22:                    1 / 2101248
 23:                    5 / 21254144

频繁操作某个场景后,GFX Device Memory CPU Uncached多了一个4198400大小的buffer不释放。

//external/angle/third_party/vulkan_memory_allocator/include/vk_mem_alloc.h

VmaAllocator_T::AllocateVulkanMemory — 最常见的申请vulkan内存方式

07-24 15:37:33.713 32746   454 E ndroid.systemui: XRING-O1:cutils_histogram_add class is Channel: GFX Device Memory CPU Uncached, bytes is 4198400
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #00 pc 0000000000dbcb9c  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #01 pc 0000000000c81f30  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #02 pc 0000000000c814cc  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #03 pc 0000000000c808f8  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #04 pc 0000000000c803dc  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #05 pc 0000000000dbc648  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #06 pc 0000000000f36f2c  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #07 pc 00000000005f1c18  /system/lib64/libhwui.so (VmaAllocator_T::AllocateVulkanMemory(VkMemoryAllocateInfo const*, VkDeviceMemory_T**)+192) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #08 pc 00000000005f3998  /system/lib64/libhwui.so (VmaBlockVector::CreateBlock(unsigned long, unsigned long*)+208) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #09 pc 00000000005f0ed4  /system/lib64/libhwui.so (VmaAllocator_T::AllocateMemoryOfType(VmaPool_T*, unsigned long, unsigned long, bool, VkBuffer_T*, VkImage_T*, unsigned int, VmaAllocationCreateInfo const&, unsigned int, VmaSuballocationType, VmaDedicatedAllocationList&, VmaBlockVector&, unsigned long, VmaAllocation_T**)+1008) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #10 pc 00000000005f0804  /system/lib64/libhwui.so (VmaAllocator_T::AllocateMemory(VkMemoryRequirements const&, bool, bool, VkBuffer_T*, VkImage_T*, unsigned int, VmaAllocationCreateInfo const&, VmaSuballocationType, unsigned long, VmaAllocation_T**)+296) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #11 pc 00000000005f0668  /system/lib64/libhwui.so (vmaAllocateMemoryForImage+244) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #12 pc 00000000007769b0  /system/lib64/libhwui.so (skgpu::VulkanAMDMemoryAllocator::allocateImageMemory(VkImage_T*, unsigned int, long*)+268) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #13 pc 00000000005d3764  /system/lib64/libhwui.so (GrVkImage::InitImageInfo(GrVkGpu*, GrVkImage::ImageDesc const&, GrVkImageInfo*)+380) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #14 pc 00000000005d2b60  /system/lib64/libhwui.so (GrVkImage::Make(GrVkGpu*, SkISize, GrAttachment::UsageFlags, int, VkFormat, unsigned int, unsigned int, skgpu::Protected, GrMemoryless, skgpu::Budgeted)+164) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #15 pc 00000000005d0630  /system/lib64/libhwui.so (GrVkTextureRenderTarget::MakeNewTextureRenderTarget(GrVkGpu*, skgpu::Budgeted, SkISize, VkFormat, unsigned int, int, GrMipmapStatus, skgpu::Protected, std::__1::basic_string_view<char, std::__1::char_traits<char>>)+116) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #16 pc 0000000000777008  /system/lib64/libhwui.so (GrVkGpu::onCreateTexture(SkISize, GrBackendFormat const&, skgpu::Renderable, int, skgpu::Budgeted, skgpu::Protected, int, unsigned int, std::__1::basic_string_view<char, std::__1::char_traits<char>>)+920) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #17 pc 000000000055a994  /system/lib64/libhwui.so (GrGpu::createTextureCommon(SkISize, GrBackendFormat const&, GrTextureType, skgpu::Renderable, int, skgpu::Budgeted, skgpu::Protected, int, unsigned int, std::__1::basic_string_view<char, std::__1::char_traits<char>>)+236) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #18 pc 00000000004e231c  /system/lib64/libhwui.so (GrResourceProvider::createTexture(SkISize, GrBackendFormat const&, GrTextureType, skgpu::Renderable, int, skgpu::Mipmapped, skgpu::Budgeted, skgpu::Protected, std::__1::basic_string_view<char, std::__1::char_traits<char>>)+472) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #19 pc 000000000055af10  /system/lib64/libhwui.so (GrSurfaceProxy::createSurfaceImpl(GrResourceProvider*, int, skgpu::Renderable, skgpu::Mipmapped) const+136) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #20 pc 000000000055ae1c  /system/lib64/libhwui.so (GrTextureRenderTargetProxy::createSurface(GrResourceProvider*) const+92) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #21 pc 00000000009d9c0c  /system/lib64/libhwui.so (GrResourceAllocator::Register::instantiateSurface(GrSurfaceProxy*, GrResourceProvider*)+344) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #22 pc 00000000004ba500  /system/lib64/libhwui.so (GrResourceAllocator::assign()+368) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #23 pc 0000000000402178  /system/lib64/libhwui.so (GrDrawingManager::flush(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*)+6536) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #24 pc 0000000000494578  /system/lib64/libhwui.so (GrDirectContextPriv::flushSurfaces(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*)+200) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #25 pc 00000000009cb8a4  /system/lib64/libhwui.so (GrDirectContext::flush(SkSurface*, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&)+140) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #26 pc 00000000008b7ec0  /system/lib64/libhwui.so (android::uirenderer::renderthread::VulkanManager::finishFrame(SkSurface*)+528) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #27 pc 00000000008ae488  /system/lib64/libhwui.so (android::uirenderer::skiapipeline::SkiaVulkanPipeline::draw(android::uirenderer::renderthread::Frame const&, SkRect const&, SkRect const&, android::uirenderer::LightGeometry const&, android::uirenderer::LayerUpdateQueue*, android::uirenderer::Rect const&, bool, android::uirenderer::LightInfo const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>> const&, android::uirenderer::FrameInfoVisualizer*, android::uirenderer::renderthread::HardwareBufferRenderParams const&, std::__1::mutex&, android::Region const&)+536) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #28 pc 000000000048fc38  /system/lib64/libhwui.so (android::uirenderer::renderthread::CanvasContext::draw(bool)+2044) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #29 pc 000000000048d7fc  /system/lib64/libhwui.so (android::uirenderer::renderthread::DrawFrameTask::run()+3232) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #30 pc 000000000060358c  /system/lib64/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+764) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #31 pc 0000000000019fd8  /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+248) (BuildId: 4b1691936eed20bb9d1f28f76e3d264e)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #32 pc 000000000001beec  /system/lib64/libutils.so (libutil_thread_trampoline(void*) (.__uniq.226528677032898775202282855395389835431)+20) (BuildId: 4b1691936eed20bb9d1f28f76e3d264e)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #33 pc 000000000007faf8  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+232) (BuildId: 321fbc20a04b7667eb38749b2cd93310)
07-24 15:37:33.725 32746   454 D xring-gpu:cutils_histogram_add:   #34 pc 0000000000072e44  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 321fbc20a04b7667eb38749b2cd93310)
07-24 15:37:33.725 32746   454 E ndroid.systemui: XRING-O1: end in vkAllocateMemory: VkDeviceMemory:0xb4000071bdb57510, size:0x400000, memoryTypeIndex:0x0
07-24 15:37:33.725 32746   454 E ndroid.systemui: CSTEST:in skia, size : 4194304  the allocate pMemory is  b4000071bdb57510 
  • 相同的VkDeviceMemory 地址,在GPU侧统计的大小是4198400,直接在trace上搜是找不到的,因为在skia侧统计的实际大小是4194304,大小比较接近但是还有误差,具体原因可能是计算方式存在区别?

结合上文提到的GL+trace方案:

创建该texture的原因是 DynamicIslandContentFakeView要做alpha操作,需要创建离屏的buffer,特别注意,对于view的alpha操作需要在view可见时进行,不然可能出现预期之外的内存泄漏问题O8-OS2.2 GPU memory泄漏问题分析https://gerrit.pt.mioffice.cn/c/platform/packages/apps/MiuiSystemUI/+/5667746

  • 对于效果不明显或者没有view重叠的alpha操作,可以改成非离屏渲染,优化性能;

其他Allocate mem的地方还有很多,需要添加对应的tag去定位问题,添加方式和GL+trace日志增强方案类似

  • 不通过GrResourceAllocator::assign()调用的堆栈:
07-24 15:37:00.091 32746   454 E ndroid.systemui: XRING-O1:cutils_histogram_add class is Channel: GFX Device Memory CPU Uncached, bytes is 4198400
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #00 pc 0000000000dbcb9c  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #01 pc 0000000000c81f30  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #02 pc 0000000000c814cc  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #03 pc 0000000000c808f8  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #04 pc 0000000000c803dc  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #05 pc 0000000000dbc648  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #06 pc 0000000000f36f2c  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #07 pc 00000000005f1c18  /system/lib64/libhwui.so (VmaAllocator_T::AllocateVulkanMemory(VkMemoryAllocateInfo const*, VkDeviceMemory_T**)+192) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #08 pc 00000000005f3998  /system/lib64/libhwui.so (VmaBlockVector::CreateBlock(unsigned long, unsigned long*)+208) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #09 pc 00000000005f0ed4  /system/lib64/libhwui.so (VmaAllocator_T::AllocateMemoryOfType(VmaPool_T*, unsigned long, unsigned long, bool, VkBuffer_T*, VkImage_T*, unsigned int, VmaAllocationCreateInfo const&, unsigned int, VmaSuballocationType, VmaDedicatedAllocationList&, VmaBlockVector&, unsigned long, VmaAllocation_T**)+1008) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #10 pc 00000000005f0804  /system/lib64/libhwui.so (VmaAllocator_T::AllocateMemory(VkMemoryRequirements const&, bool, bool, VkBuffer_T*, VkImage_T*, unsigned int, VmaAllocationCreateInfo const&, VmaSuballocationType, unsigned long, VmaAllocation_T**)+296) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #11 pc 00000000005f0500  /system/lib64/libhwui.so (vmaAllocateMemoryForBuffer+244) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #12 pc 000000000078b8b4  /system/lib64/libhwui.so (skgpu::VulkanAMDMemoryAllocator::allocateBufferMemory(VkBuffer_T*, skgpu::VulkanMemoryAllocator::BufferUsage, unsigned int, long*)+148) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #13 pc 00000000005cfb14  /system/lib64/libhwui.so (GrVkBuffer::Make(GrVkGpu*, unsigned long, GrGpuBufferType, GrAccessPattern)+396) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #14 pc 0000000000761178  /system/lib64/libhwui.so (GrVkGpu::onCreateBuffer(unsigned long, GrGpuBufferType, GrAccessPattern)+36) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #15 pc 0000000000480b98  /system/lib64/libhwui.so (GrGpu::createBuffer(unsigned long, GrGpuBufferType, GrAccessPattern)+104) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #16 pc 0000000000480f4c  /system/lib64/libhwui.so (GrResourceProvider::createBuffer(unsigned long, GrGpuBufferType, GrAccessPattern, GrResourceProvider::ZeroInit)+492) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #17 pc 0000000000798da8  /system/lib64/libhwui.so (GrStagingBufferManager::allocateStagingBufferSlice(unsigned long, unsigned long)+184) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #18 pc 0000000000798638  /system/lib64/libhwui.so (GrVkGpu::onWritePixels(GrSurface*, SkIRect, GrColorType, GrColorType, GrMipLevel const*, int, bool)+592) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #19 pc 000000000055a188  /system/lib64/libhwui.so (GrGpu::writePixels(GrSurface*, SkIRect, GrColorType, GrColorType, GrMipLevel const*, int, bool)+460) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #20 pc 0000000000559b84  /system/lib64/libhwui.so (GrOpFlushState::doUpload(std::__1::function<void (std::__1::function<bool (GrTextureProxy*, SkIRect, GrColorType, void const*, unsigned long)>&)>&, bool)::$_0::operator()(GrTextureProxy*, SkIRect, GrColorType, void const*, unsigned long) const (.__uniq.202563907186678916635362162699847805487)+332) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #21 pc 00000000007a31f0  /system/lib64/libhwui.so (GrDeferredProxyUploader::scheduleUpload(GrOpFlushState*, GrTextureProxy*)::'lambda'(std::__1::function<bool (GrTextureProxy*, SkIRect, GrColorType, void const*, unsigned long)>&)::operator()(std::__1::function<bool (GrTextureProxy*, SkIRect, GrColorType, void const*, unsigned long)>&) const+180) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #22 pc 00000000009d6914  /system/lib64/libhwui.so (GrOpFlushState::doUpload(std::__1::function<void (std::__1::function<bool (GrTextureProxy*, SkIRect, GrColorType, void const*, unsigned long)>&)>&, bool)+88) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #23 pc 000000000042bbb4  /system/lib64/libhwui.so (GrOpFlushState::preExecuteDraws()+60) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #24 pc 00000000004021f8  /system/lib64/libhwui.so (GrDrawingManager::flush(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*)+6664) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #25 pc 0000000000494578  /system/lib64/libhwui.so (GrDirectContextPriv::flushSurfaces(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*)+200) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #26 pc 00000000009cb8a4  /system/lib64/libhwui.so (GrDirectContext::flush(SkSurface*, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&)+140) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #27 pc 00000000008b7ec0  /system/lib64/libhwui.so (android::uirenderer::renderthread::VulkanManager::finishFrame(SkSurface*)+528) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #28 pc 00000000008ae488  /system/lib64/libhwui.so (android::uirenderer::skiapipeline::SkiaVulkanPipeline::draw(android::uirenderer::renderthread::Frame const&, SkRect const&, SkRect const&, android::uirenderer::LightGeometry const&, android::uirenderer::LayerUpdateQueue*, android::uirenderer::Rect const&, bool, android::uirenderer::LightInfo const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>> const&, android::uirenderer::FrameInfoVisualizer*, android::uirenderer::renderthread::HardwareBufferRenderParams const&, std::__1::mutex&, android::Region const&)+536) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #29 pc 000000000048fc38  /system/lib64/libhwui.so (android::uirenderer::renderthread::CanvasContext::draw(bool)+2044) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #30 pc 000000000048d7fc  /system/lib64/libhwui.so (android::uirenderer::renderthread::DrawFrameTask::run()+3232) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #31 pc 000000000060358c  /system/lib64/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+764) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #32 pc 0000000000019fd8  /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+248) (BuildId: 4b1691936eed20bb9d1f28f76e3d264e)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #33 pc 000000000001beec  /system/lib64/libutils.so (libutil_thread_trampoline(void*) (.__uniq.226528677032898775202282855395389835431)+20) (BuildId: 4b1691936eed20bb9d1f28f76e3d264e)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #34 pc 000000000007faf8  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+232) (BuildId: 321fbc20a04b7667eb38749b2cd93310)
07-24 15:37:00.103 32746   454 D xring-gpu:cutils_histogram_add:   #35 pc 0000000000072e44  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 321fbc20a04b7667eb38749b2cd93310)
07-24 15:37:00.103 32746   454 E ndroid.systemui: XRING-O1: end in vkAllocateMemory: VkDeviceMemory:0xb4000071bda474d0, size:0x400000, memoryTypeIndex:0x1
07-24 15:37:00.103 32746   454 E ndroid.systemui: CSTEST:in skia, size : 4194304  the allocate pMemory is  b4000071bda474d0 
  • 不通过AllocateVulkanMemory接口申请内存的堆栈:

// external/skia/src/gpu/vk/VulkanUtilsPriv.cpp

skgpu::AllocateAndBindImageMemory

07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #00 pc 0000000000dbcb9c  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #01 pc 0000000000c81f30  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #02 pc 0000000000c814cc  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #03 pc 0000000000c808f8  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #04 pc 0000000000c803dc  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #05 pc 0000000000dbf25c  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #06 pc 0000000000dbec80  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #07 pc 0000000000dba938  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #08 pc 0000000000db9140  /vendor/lib64/egl/libGLES_mali.so (BuildId: fabe4c713a323cf6)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #09 pc 000000000002fac8  /system/lib64/libvulkan.so (vulkan::driver::BindImageMemory2(VkDevice_T*, unsigned int, VkBindImageMemoryInfo const*)+120) (BuildId: 83a9ba50ee2c60126239a73368507305)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #10 pc 0000000000a759d4  /system/lib64/libhwui.so (skgpu::AllocateAndBindImageMemory(skgpu::VulkanAlloc*, VkImage_T*, VkPhysicalDeviceMemoryProperties2 const&, VkAndroidHardwareBufferPropertiesANDROID const&, AHardwareBuffer*, skgpu::VulkanInterface const*, VkDevice_T*)+272) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #11 pc 0000000000557c50  /system/lib64/libhwui.so (GrAHardwareBufferUtils::MakeVulkanBackendTexture(GrDirectContext*, AHardwareBuffer*, int, int, void (**)(void*), void (**)(void*, GrDirectContext*), void**, bool, GrBackendFormat const&, bool, bool)+784) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #12 pc 00000000005573b0  /system/lib64/libhwui.so (SkSurfaces::WrapAndroidHardwareBuffer(GrDirectContext*, AHardwareBuffer*, GrSurfaceOrigin, sk_sp<SkColorSpace>, SkSurfaceProps const*, bool)+308) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #13 pc 0000000000495004  /system/lib64/libhwui.so (android::uirenderer::renderthread::VulkanManager::dequeueNextBuffer(android::uirenderer::renderthread::VulkanSurface*)+1984) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #14 pc 000000000048f620  /system/lib64/libhwui.so (android::uirenderer::renderthread::CanvasContext::draw(bool)+484) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #15 pc 000000000048d7fc  /system/lib64/libhwui.so (android::uirenderer::renderthread::DrawFrameTask::run()+3232) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #16 pc 000000000060358c  /system/lib64/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+764) (BuildId: 221c7c7a2938b90dc1512d7a2d73b7cc)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #17 pc 0000000000019fd8  /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+248) (BuildId: 4b1691936eed20bb9d1f28f76e3d264e)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #18 pc 000000000001beec  /system/lib64/libutils.so (libutil_thread_trampoline(void*) (.__uniq.226528677032898775202282855395389835431)+20) (BuildId: 4b1691936eed20bb9d1f28f76e3d264e)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #19 pc 000000000007faf8  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+232) (BuildId: 321fbc20a04b7667eb38749b2cd93310)
07-24 15:36:58.753 32746   454 D xring-gpu:cutils_histogram_add:   #20 pc 0000000000072e44  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 321fbc20a04b7667eb38749b2cd93310)
  • 还有很多未记录的申请vulkan内存的方式,需要通过gpu侧加堆栈打印出,可以和xring的gpu团队联系打个mail.so库进一步排查

createTexture时创建尺寸估算内存大小会和vkallocate的大小有偏差,怀疑是没有设置alpha通道,比如270x600x4=64800 0.6M,但是vkallocate确有4194304 4.19M,差距很大

非RenderLayer申请buffer的原因

场景在首次下拉通知栏

09-26 10:25:18.034 14948 15374 E ndroid.systemui: WWWLLLTTT - GrVkGpu::onCreateTexture 1216 x 576 
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #00 pc 00000000007791fc  /system/lib64/libhwui.so (GrVkGpu::onCreateTexture(SkISize, GrBackendFormat const&, skgpu::Renderable, int, skgpu::Budgeted, skgpu::Protected, int, unsigned int, std::__1::basic_string_view<char, std::__1::char_traits<char>>)+364) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #01 pc 00000000005849c4  /system/lib64/libhwui.so (GrGpu::createTextureCommon(SkISize, GrBackendFormat const&, GrTextureType, skgpu::Renderable, int, skgpu::Budgeted, skgpu::Protected, int, unsigned int, std::__1::basic_string_view<char, std::__1::char_traits<char>>)+244) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #02 pc 0000000000487b10  /system/lib64/libhwui.so (GrResourceProvider::createTexture(SkISize, GrBackendFormat const&, GrTextureType, skgpu::Renderable, int, skgpu::Mipmapped, skgpu::Budgeted, skgpu::Protected, std::__1::basic_string_view<char, std::__1::char_traits<char>>)+480) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #03 pc 0000000000487604  /system/lib64/libhwui.so (GrSurfaceProxy::createSurfaceImpl(GrResourceProvider*, int, skgpu::Renderable, skgpu::Mipmapped) const+132) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #04 pc 000000000048750c  /system/lib64/libhwui.so (GrTextureRenderTargetProxy::createSurface(GrResourceProvider*) const+92) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #05 pc 00000000009fa8b8  /system/lib64/libhwui.so (GrResourceAllocator::Register::instantiateSurface(GrSurfaceProxy*, GrResourceProvider*)+344) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #06 pc 00000000004a0a90  /system/lib64/libhwui.so (GrResourceAllocator::assign()+368) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #07 pc 00000000004021b0  /system/lib64/libhwui.so (GrDrawingManager::flush(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*)+6704) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #08 pc 0000000000532618  /system/lib64/libhwui.so (GrDirectContextPriv::flushSurfaces(SkSpan<GrSurfaceProxy*>, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&, skgpu::MutableTextureState const*)+200) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #09 pc 00000000009ebf6c  /system/lib64/libhwui.so (GrDirectContext::flush(SkSurface*, SkSurfaces::BackendSurfaceAccess, GrFlushInfo const&)+140) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #10 pc 00000000008d055c  /system/lib64/libhwui.so (android::uirenderer::renderthread::VulkanManager::finishFrame(SkSurface*)+508) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #11 pc 00000000008c6380  /system/lib64/libhwui.so (android::uirenderer::skiapipeline::SkiaVulkanPipeline::draw(android::uirenderer::renderthread::Frame const&, SkRect const&, SkRect const&, android::uirenderer::LightGeometry const&, android::uirenderer::LayerUpdateQueue*, android::uirenderer::Rect const&, bool, android::uirenderer::LightInfo const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>> const&, android::uirenderer::FrameInfoVisualizer*, android::uirenderer::renderthread::HardwareBufferRenderParams const&, std::__1::mutex&, android::Region const&)+528) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #12 pc 000000000053416c  /system/lib64/libhwui.so (android::uirenderer::renderthread::CanvasContext::draw(bool)+2044) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #13 pc 00000000008985d4  /system/lib64/libhwui.so (std::__1::__function::__func<android::uirenderer::renderthread::DrawFrameTask::postAndWait()::$_0, std::__1::allocator<android::uirenderer::renderthread::DrawFrameTask::postAndWait()::$_0>, void ()>::operator()() (.__uniq.264041412789356548918088680803242235290.3c9219c4c61f046e2a02e26efbc92a9c)+2996) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #14 pc 0000000000604ce4  /system/lib64/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+772) (BuildId: 1738d86492d8a5d2368a374d4cad3fdd)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #15 pc 0000000000037ec8  /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+456) (BuildId: 4d39e49050a383c02d800bbe8f9c715a)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #16 pc 000000000003bcd4  /system/lib64/libutils.so (libutil_thread_trampoline(void*) (.__uniq.226528677032898775202282855395389835431)+20) (BuildId: 4d39e49050a383c02d800bbe8f9c715a)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #17 pc 000000000008426c  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+236) (BuildId: c0085b1625d4c77521e9a135f55cde77)
09-26 10:25:18.061 14948 15374 D WWWLLLTTT-onCreateTexture:   #18 pc 00000000000767a0  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: c0085b1625d4c77521e9a135f55cde77)
  • 高级材质makeBackgroundImage时会申请离屏内存

//vendor/xiaomi/frameworks/base/libs/hwui/pipeline/skia/MiBackgroundBlurBlendImpl.cpp

void MiBackgroundBlurBlendImpl::makeBackgroundImage(GrRecordingContext* rContext, MiBackgroundBlurBlend* backgroundBlurBlend, SkCanvas* canvas) {
    ATRACE_FORMAT("makeBackgroundImage-%s", backgroundBlurBlend->getName());
    SkSamplingOptions linearSampling(SkFilterMode::kLinear, SkMipmapMode::kNone);
    bool useRGBA8 = backgroundBlurBlend->mBackgroundBlurType == GRADIENT_BLUR_TYPE;
    // sk_sp<SkSurface> surface = backgroundBlurBlend->getSurface(backgroundBlurBlend->mBlurScale, backgroundBlurBlend->mBounds, false, useRGBA8);
    sk_sp<SkSurface> surface = MiBlurBlendUtils::instance().getSurface(
                    rContext, backgroundBlurBlend->mBlurScale, backgroundBlurBlend->mBounds, false, 
                    useRGBA8 ? SkColorType::kRGBA_8888_SkColorType : SkColorType::kRGBA_1010102_SkColorType);

GFX日志增强

任航https://gerrit.pt.mioffice.cn/q/topic:%22gfxinfo+dump%22

gfxinfo可以用于分析和优化应用程序的图形渲染性能

我们可以粗略看到GPU mem信息以及buffer尺寸和内存大小

对于具体分析问题这些信息可能不够,采用如下的日志增强方案可以看到详细的GrVkImage、GrVkTextureRenderTarget、Buffer Object的尺寸以及大小信息。

  • gfxinfo的dump信息在CacheManager::dumpMemoryUsage方法输出

frameworks/base/libs/hwui/renderthread/CacheManager.cpp

  • SkiaMemoryTracer是SkTraceMemoryDump子类

libs/hwui/pipeline/skia/SkiaMemoryTracer.h

在GrGpuResource::dumpMemoryStatisticsPriv中调用SkiaMemoryTracer定义的dumpLogcat方法把buffer的type,size输出到dump信息中;

  • 这些type和size都是GrGpuResource子类调用自身dump信息得到。

external/skia/src/gpu/ganesh/GrGpuResource.cpp

void GrGpuResource::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
    if (this->fRefsWrappedObjects && !traceMemoryDump->shouldDumpWrappedObjects()) {
        return;
    }
 
    this->dumpMemoryStatisticsPriv(traceMemoryDump, this->getResourceName(),
                                   this->getResourceType(), this->gpuMemorySize());
}
 
void GrGpuResource::dumpMemoryStatisticsPriv(SkTraceMemoryDump* traceMemoryDump,
                                             const SkString& resourceName,
                                             const char* type, size_t size) const {
    const char* tag = "Scratch";
    if (fUniqueKey.isValid()) {
        tag = (fUniqueKey.tag() != nullptr) ? fUniqueKey.tag() : "Other";
    }
 
    traceMemoryDump->dumpNumericValue(resourceName.c_str(), "size", "bytes", size);
    traceMemoryDump->dumpStringValue(resourceName.c_str(), "type", type);
    traceMemoryDump->dumpStringValue(resourceName.c_str(), "label", this->getLabel().c_str());
    traceMemoryDump->dumpStringValue(resourceName.c_str(), "category", tag);
    if (this->isPurgeable()) {
        traceMemoryDump->dumpNumericValue(resourceName.c_str(), "purgeable_size", "bytes", size);
    }
    if (traceMemoryDump->shouldDumpWrappedObjects()) {
        traceMemoryDump->dumpWrappedState(resourceName.c_str(), fRefsWrappedObjects);
    }
 
    this->setMemoryBacking(traceMemoryDump, resourceName);
}
  • 常见子类包括GrVkTextureRenderTarget和GrVkImage等,可以根据需求重写getResourceType方法

  • GrVkImage :用于存储多维数据,如纹理、帧缓冲等;
  • GrVkTextureRenderTarget :提供了一个可以同时用作纹理和渲染目标的资源;
  • Buffer Object :用于存储线性数据,如顶点数据、索引数据、uniform 数据等;

这样我们可以在gfxinfo中看到通过vkAllocateMemory申请的详细内存以及对应的尺寸信息,协助分析。

原生支持

VMA中提供统计allocationbytes的能力

//external/skia/src/gpu/vk/vulkanmemoryallocator/VulkanAMDMemoryAllocator.cpp

std::pair<uint64_t, uint64_t> VulkanAMDMemoryAllocator::totalAllocatedAndUsedMemory() const {
    VmaTotalStatistics stats;
    vmaCalculateStatistics(fAllocator, &stats);
    return {stats.total.statistics.blockBytes, stats.total.statistics.allocationBytes};
}