Latest 0.1.0
Homepage https://github.com/chenzhengxu/AppTrace
License MIT
Platforms ios 8.0
Dependencies fishhook
Frameworks UIKit, Foundation
Authors

CI Status
Version
License
Platform

Usage

用来追踪app运行期间所有调用的方法以及耗时时间,支持真机和模拟器,方便开发者对于app进行优化。如图:

sample

How it works

通过 fishhook 钩住 objc_msg_send 方法,在替代的方法中实现参数寄存器值的保存与恢复,从而在原始的 objc_msg_send 方法前后调用自定义方法,又不影响本身函数的调用,在 arm64 下的大致逻辑是:

保存寄存器x0 - x8,q0 - q7到栈上,
记录class,selector,startTime,lr
恢复寄存器x0 - x8,q0 - q7,
调用原始objc_msg_send,
保存寄存器x0 - x8,q0 - q7到栈上,
记录endTime,
恢复寄存器x0 - x8,q0 - q7,以及lr

最后产出物为 trace.json 文件,使用项目中的脚本 sh perf_file.sh 对文件进行处理,可打开网站 chrome://tracing 直接拖入 .json 文件展示,也可以使用脚本 sh generate_html.sh 输出稳定的html文件。

Sample

项目下的 Generate 有案例展示。

Quick start

AppTrace is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'AppTrace'

Import the framework header,then call start method.

#import "AppTrace.h"

// call it wherever you want, pefer to call in main.m like Example
[AppTrace startTrace];

Thanks

  1. Locus : https://github.com/hzfanfei/locus
  2. HookZz : https://github.com/jmpews/HookZz
  3. catapult : https://github.com/catapult-project/catapult
  4. AppleTrace : https://github.com/everettjf/AppleTrace
  5. fishhook : https://github.com/facebook/fishhook

License

AppTrace is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "AppTrace",
    "version": "0.1.0",
    "summary": "A track util of App.",
    "description": "A track util of Appuff0chelp develop to know how their app runs.",
    "homepage": "https://github.com/chenzhengxu/AppTrace",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "chenzhengxu": "[email protected]"
    },
    "source": {
        "git": "https://github.com/chenzhengxu/AppTrace.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "AppTrace/Classes/**/*",
    "pod_target_xcconfig": {
        "OTHER_LDFLAGS": "-lObjC"
    },
    "frameworks": [
        "UIKit",
        "Foundation"
    ],
    "dependencies": {
        "fishhook": []
    }
}

Pin It on Pinterest

Share This