HCClangTrace
HCClangTrace is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod'HCClangTrace','~> 1.0.0'
Other C Flags增加-fsanitize-coverage=func,trace-pc-guard 如果你是OC Swift混编,则在Other Swift Flags增加-sanitize-coverage=func, -sanitize=undefined
在你的首页的viewDidAppear函数中加上生成orderFile的函数,然后运行app
2.1 编写测试代码测试c函数、pod库函数、block、swift方法
- (void)callSomeMethods {//call third lib method[[AFNetworkReachabilityManagersharedManager]startMonitoring];//call blockself.testCallBlock();//call swift method[[TestCallSwiftnew]testCallSwiftMethod];//call c methodtestCallCMethod();}
- (void)viewDidAppear:(BOOL)animated { [superviewDidAppear:animated]; [HCClangTracegenerateOrderFile];}
2020-08-1117:35:09.895881+0800HCClangTrace_Example[47015:1422955] _main-[HCAppDelegatewindow]-[HCAppDelegatesetWindow:]-[HCAppDelegateapplication:didFinishLaunchingWithOptions:]-[HCViewControllerviewDidLoad]-[HCViewControllersetTestCallBlock:]-[HCViewControllercallSomeMethods]+[AFNetworkReachabilityManagersharedManager]___45+[AFNetworkReachabilityManagersharedManager]_block_invoke+[AFNetworkReachabilityManagermanager]+[AFNetworkReachabilityManagermanagerForAddress:]-[AFNetworkReachabilityManagerinitWithReachability:]-[AFNetworkReachabilityManagersetNetworkReachabilityStatus:]-[AFNetworkReachabilityManagerstartMonitoring]-[AFNetworkReachabilityManagerstopMonitoring]-[AFNetworkReachabilityManagernetworkReachability]___copy_helper_block_e8_32w_AFNetworkReachabilityRetainCallback___copy_helper_block_e8_32s40b-[HCViewControllertestCallBlock]___31-[HCViewControllerviewDidLoad]_block_invoke_testCallCMethod-[HCAppDelegateapplicationDidBecomeActive:]-[HCViewControllerviewDidAppear:]___34-[HCViewControllerviewDidAppear:]_block_invoke
函数的调用符号会在app的沙盒的tmp目录下生成,trace.order的文件,可以直接去提取
由于我们是通过编译选项去做的插桩,它只会生效于有该选项的工程,而pod库则是单独的工程,我们可以通过post_install来给pod库 自动加上这些编译选项 只需要在Podfile文件后面加上下面这段,Demo的Podfile也加上了这个
post_installdo|installer|installer.pods_project.targets.eachdo|target|target.build_configurations.eachdo|config|macho_type=config.build_settings['MACH_O_TYPE']#if macho_type == 'staticlib'ifconfig.name=='Debug'# 将依赖的pod项目的Other C Flags加上’-fsanitize-coverage=func,trace-pc-guard‘选项config.build_settings['OTHER_CFLAGS']||=['$(inherited)','-fsanitize-coverage=func,trace-pc-guard']config.build_settings['OTHER_SWIFT_FLAGS']||=['$(inherited)','-fsanitize-coverage=func,trace-pc-guard']end#endendendend
有问题欢迎提issue,一起沟通解决,学习进步; 在使用之前可以先参照下我写的文档iOS App启动时间优化--Clang插桩获取启动调用的函数符号