APM相关

作者: 陈_振 | 来源:发表于2018-12-04 16:17 被阅读0次

记录一下最近在扩展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;
    }
}

相关文章

网友评论

      本文标题:APM相关

      本文链接:https://www.haomeiwen.com/subject/uqqvcqtx.html