APM相关

记录一下最近在扩展GT时遇到的一些问题

  1. 通过residentSize获取的常驻内存和Xcode上显示的内存值不一致。
    原因大致如下:
    residentSize返回的内存由这三部分构成(DirtyMemory + CompressedMemory + CleanMemory)

    Xcode统计的是MemoryFootPrint,不包含CleanMemory。

用WWDC-Memory Deep Dive中的一句话总结:

when we talk about the app's footprint, we're really talking about the dirty and compressed segments.Clean memory doesn't really count.


memoryFootPrint.png

参考:
iOS内存abort(Jetsam) 原理探究

iOS Memory Deep Dive

WWDC 2018:iOS 内存深入研究

深度揭秘各大 APM 厂商 iOS SDK 背后的核心技术和实现细节

iOS 性能监控 SDK

基于iOS平台的性能检测方案

  1. GT源码中获取residentMemorySize的API已经不被Apple建议使用

源API:

- (NSUInteger)getResidentMemory
{
    struct task_basic_info t_info;
    mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
    
    int r = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count);
    if (r == KERN_SUCCESS)
    {
        return t_info.resident_size;
    }
    else
    {
        return -1;
    }
}
apple.png

可以更换为Apple建议的API:

- (NSUInteger)updateMemoryResidentSize {
    struct mach_task_basic_info t_info;
    mach_msg_type_number_t t_info_count = MACH_TASK_BASIC_INFO_COUNT;
    int r = task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count);
    if (r == KERN_SUCCESS) {
        return t_info.resident_size;
    } else {
        return -1;
    }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容