美文网首页
iOS 性能检测

iOS 性能检测

作者: cyhai | 来源:发表于2019-10-14 17:21 被阅读0次
启动耗时
页面加载耗时
CPU占用
内存占用
传送门:https://github.com/CYHAI9/MonitorTools

启动耗时

image.png
启动耗时主要分main函数前后时间,pre-main的时间是相对较难拿到的,参考美团性能检测([https://tech.meituan.com/2018/12/06/waimai-ios-optimizing-startup.html](https://tech.meituan.com/2018/12/06/waimai-ios-optimizing-startup.html
可以从获取进程的开始的时间。
#import <sys/sysctl.h>
#import <mach/mach.h>

+ (BOOL)processInfoForPID:(int)pid procInfo:(struct kinfo_proc*)procInfo
{
    int cmd[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
    size_t size = sizeof(*procInfo);
    return sysctl(cmd, sizeof(cmd)/sizeof(*cmd), procInfo, &size, NULL, 0) == 0;
}

+ (NSTimeInterval)processStartTime
{
    struct kinfo_proc kProcInfo;
    if ([self processInfoForPID:[[NSProcessInfo processInfo] processIdentifier] procInfo:&kProcInfo]) {
        return kProcInfo.kp_proc.p_un.__p_starttime.tv_sec * 1000.0 + kProcInfo.kp_proc.p_un.__p_starttime.tv_usec / 1000.0;
    } else {
        NSAssert(NO, @"无法取得进程的信息");
        return 0;
    }
}

业界当中虽然有采用加载某个执行文件load方法打点和找到叶子节点的dylib,然后以其中某个类的+load方法的执行时间作为起始点这两个方法,两个方法在于精确性问题,所以同样存在一个问题,就是Initializers方法前的时间都没拿到,起始点过后。
待续。。。。。。

相关文章

  • Instruments的使用

    1: iOS性能优化:Instruments使用实战 2: Instruments性能检测 3: iOS Inst...

  • 卡顿检测资料

    微信iOS卡顿监控系统 卡顿方案思考 卡顿检测 移动端监控体系之技术原理 iOS性能检测

  • iOS性能检测

    《iOS APP 性能检测》 原创: colawyeeqiu 腾讯Bugly 2017-09-28 | 导语 最近...

  • iOS性能检测

    1.概览 工具通过Xcode工具栏中Product->Profile可以启动,启动后界面如下: Instrumen...

  • iOS性能检测

  • iOS 性能检测

    启动耗时 页面加载耗时 CPU占用 内存占用 传送门:https://github.com/CYHAI9/Moni...

  • iOS性能优化篇小结(一)

    iOS性能优化篇小结(二) 随着公司项目逐渐的稳定,前段时间在项目中引入了一个性能检测的工具,同时 iOS性能优化...

  • iOS 各种优化

    iOS 性能优化相关:性能检测1,https://mp.weixin.qq.com/s/e-UDC_j9LZX5_...

  • iOS性能调优笔记

    并不是所有的代码都需要性能调优。iOS的性能调优主要就在于表格的性能,而在使用instruments在做性能检测的...

  • iOS中性能检测工具Instruments之 Core Anim

    iOS中切圆角的性能检测工具Instruments之 Core Animation 准备工作 在性能优化中一个最具...

网友评论

      本文标题:iOS 性能检测

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