Latest 1.0.0
Homepage https://github.com/featuretower/GYMonitor
License MIT (LICENSE)
Platforms ios 7.0, requires ARC
Dependencies PLCrashReporter
Authors

GYMonitor是用于监控iOS app性能状况的代码库,目前包括有FPS监控,发现FPS过低会自动产生堆栈,便于在开发过程中发现卡顿问题。

安装

使用CocoaPods

# Podfile
platform :ios, '7.0'
target 'YourTarget'
pod 'GYMonitor'

手工导入

  • 拖动GYMonitor整个文件夹到已有的Xcode工程。值得注意的是GYMonitor里面有CrashReporter.framework这个库。
  • 包含头文件#import "GYMonitor.h"
  • dsymInfo文件夹拷贝到工程文件的同一个目录,然后在工程文件中的Build Phases最后加上一个Run Script,脚本内容为python ${PROJECT_DIR}/dsymInfo/backup.py
    (Run Script)

使用

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // normal code...

    [self startMonitor];

    return YES;
}

- (void)startMonitor {
    [GYMonitor sharedInstance].monitorFPS = YES;
    [GYMonitor sharedInstance].showDebugView = YES;
    [[GYMonitor sharedInstance] startMonitor];
}

- (void)stopMonitor {
    [GYMonitor sharedInstance].monitorFPS = NO;
    [GYMonitor sharedInstance].showDebugView = NO;
    [[GYMonitor sharedInstance] startMonitor];
}

运行效果

  • 在模拟器/真机(真机只能看到部分符号)

fps低
fps卡顿
模拟器上的堆栈

  • 在mac上反解

(反解堆栈菜单)
(mac上反解结果)

原理

  • 通过CADisplayLink获取屏幕刷新频率,输出FPS的值
  • 在子线程开启定时器监控FPS的值
  • 当FPS的值过低时,通过CrashReporter获取全部线程的堆栈,保存为$currentController.crash文件
  • 编译项目成功后通过dsymutil产生dSYM文件然后保存,为了节省空间最多保存5个。还有为它们在所的目录添加Spotlight索引,反解堆栈时能让mac os自动找到它们
  • 在手机可通过点击监控条,然后用AirDrop把crash文件传输到mac上,在mac使用symbolicatecrash反解堆栈,为了方便,我使用了Automator为右键点击*.crash文件时添加服务项反解堆栈,点击后会运行脚本去反解堆栈。

Latest podspec

{
    "name": "GYMonitor",
    "version": "1.0.0",
    "summary": "A collection of code for profiling iOS app, such as monitoring FPS.",
    "homepage": "https://github.com/featuretower/GYMonitor",
    "license": "MIT (LICENSE)",
    "authors": {
        "featuretower": "[email protected]"
    },
    "source": {
        "git": "https://github.com/featuretower/GYMonitor.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source_files": [
        "GYMonitor",
        "GYMonitor/**/*.{h,m}"
    ],
    "exclude_files": "GYMonitor/CrashReporter.framework",
    "dependencies": {
        "PLCrashReporter": []
    },
    "requires_arc": true
}

Pin It on Pinterest

Share This