基于汇编实现 hook objc_msgSend,统计方法耗时的方案

文章目录


简介

首先,iOS 中进行 hook 的方案有多种,这里使用的是 Facebook 的 fishhook 库:Github:fishhook

hook objc_msgsend ,货拉拉技术团队已有完善的方案:基于汇编实现objc_msgSend hook方法耗时的方案

另外,它们还开源了基于fishhook、汇编 hook objc_msgsend 并支持方法耗时可视化的项目:hll-wp-guldan-ios

接入

首先在 Podfile 中添加:

cpp 复制代码
pod 'Guldan', :git => "https://github.com/HuolalaTech/hll-wp-guldan-ios.git"

然后设置要监控的代码片段:

objectivec 复制代码
[GDNOCMethodTimeProfiler start];
// 下载图片
[self downloadImages];
[GDNOCMethodTimeProfiler stop];
[GDNOCMethodTimeProfiler handleRecordsWithComplete:^(NSArray<NSString *> * _Nonnull filePaths) {
       // file path
       for (NSString *filePath in filePaths) {
             NSLog(@"File path: %@", filePath);
         }
   }];

从控制台拿到 path:

最后将 path 的文件拖入 chrome://tracing/ :

经测试,模拟器(arm64)和真机均支持,不支持模拟器(x86_64)。

相关推荐
我的golang之路果然有问题12 小时前
mac 上进行 comfyUI 等绘画的好处以及分享
人工智能·macos·ai作画·人工智能作画·comfy
奔跑的呱呱牛12 小时前
解决MacOS下Chrome嗯下F5不刷新页面的问题
chrome·macos·mac
叶之道12 小时前
MacOS 配置 Qt 开发环境
qt·macos
ii_best12 小时前
按键精灵安卓/IOS手机助手 × 手机按键 App:1 分钟搞定设备连接(超详细教程)
android·ios·智能手机·自动化·编辑器
2501_9160074713 小时前
在没有 Mac 的情况下完成 iOS 应用上架 App Store
android·macos·ios·小程序·uni-app·iphone·webview
TheNextByte113 小时前
iPhone存储空间已满?如何轻松释放iPhone空间?
android·ios·iphone
—Qeyser1 天前
Flutter 颜色完全指南
android·flutter·ios
2501_916008891 天前
iOS 上架需要哪些准备,账号、Bundle ID、证书、描述文件、安装测试及上传
android·ios·小程序·https·uni-app·iphone·webview
Zender Han1 天前
Flutter Android 启动页 & App 图标替换(不使用任何插件的完整实践)
android·flutter·ios
—Qeyser1 天前
Flutter CustomScrollView 自定义滚动视图 - 完全指南
android·flutter·ios