MonitorTools
性能指标
快速使用
使用 Cocoapods,通过 pod 'CyhMonitorTools' 引入
#import <CountObj.h>
(1)启动耗时
启动耗分为 T1, T2, T3, T4, T(总耗时)
T1 和 T2 的开始与结束,T1 记录 application 初始化前的时钟,包括 main 函数前的时钟(pre-main),T2 是初始化开始到启动页结束。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#pragma mark application初始化结束记录T1,T2继续 启动总时间T
finishLaunchTime(^(NSDictionary * _Nonnull timeDict) {
//当T1-T4都统计完了,这里会回调统计数据
});
}
T3 和 T4 开始
_startCountWithId(LaunchT3,MonitorTypeLaunch)
_startCountWithId(LaunchT4,MonitorTypeLaunch)
结束
_endCountWithId(LaunchT3End,MonitorTypeLaunch)
_endCountWithId(LaunchT4End,MonitorTypeLaunch)
MonitorTypeLaunch,标识用于启动耗时统计,MonitorTypeViewLoad,标识用于页面加载耗时统计。页面加载耗时没有类似的“LaunchT4”,因为需要自己定义时间段(T1, T2...T100)。
(2)获取 CPU 占用
[CountObj getCpuUsage];
(3)获取内存占用
[CountObj getMemoryUsage];
(4) 获取堆栈
[CountObj stackSymbols];