CocoaPods trunk is moving to be read-only. Read more on the blog, there are 8 months to go.
| TestsTested | ✗ |
| LangLanguage | Obj-CObjective C |
| License | MIT |
| ReleasedLast Release | Mar 2017 |
Maintained by AndrewZhu.
AZ-THPerformanceMonitor 是一个基于 老谭笔记 博客中对 主线程RunLoop 卡顿的监控demo,并集成 CPU使用率 监控功能的框架。当RunLoop耗时超过设定的时间一定次数或者CPU使用率超过一定限度,则会抓取当前所有线程的函数调用栈,以*.crash的格式保存在~/Documents/PerformanceMonitorLogs/文件夹下。目前开源在 GitHub 上。
你也可以手动把 AZ-THPerformanceMonitor 加入到项目中。把 Class 目录下的所有文件导入到项目中即可。
#import "AZPerformanceMonitorMarco.h"
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
AZPerformanceMonitor *monitor = ObserveRunLoop(1, 10)
AZPerformanceMonitor *anotherMonitor = ObserveCPU(90.f, 500)
return YES;
}OberveRunLoop(mostCount, mils) 是一个便捷启动 RunLoop监控 的宏。mils 的含义是当主线程的两个耗时阶段的监控耗时触发点,以毫秒为单位。mostCount 的含义是连续出现耗时超时则触发抓取动作的次数。
ObserveCPU(usage, mils) 则是启动 CPU使用率监控 的宏。usage 参数指触发抓取动作的CPU使用率下限,mils 是两次监控的时间间隔,以毫秒为单位。
这两个宏都会返回一个 AZPerformanceMonitor 的实例,可以持有该实例,进而可以在适时停止或者暂停监控(目前抓取所有线程函数调用栈的动作会导致CPU占用率提高30%~40%左右,因此每次触发抓取动作,AZPerformanceMonitorManager 会主动暂停所有监控,待抓取动作完成才继续监控)。也可以通过 AZPerformanceMonitorManager 单例来管理所有的监控动作。