基于汇编实现 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)。

相关推荐
卜锦元1 天前
nvm常用命令(nodejs)
macos·编辑器·nodejs·开发工具
山峰哥1 天前
SQL调优核心战法——索引失效场景与Explain深度解析
大数据·汇编·数据库·sql·编辑器·深度优先
小鸡脚来咯2 天前
怎么配置主机名映射?
linux·windows·macos
牛奔2 天前
macOS 使用 conda,同时本地安装了python,遇到 ModuleNotFoundError: No module named ‘xxx‘` 解决
开发语言·python·macos·conda
川川菜鸟2 天前
Codex+ 中转 API 部署教程(Mac版)
macos
rockage2 天前
【技巧】MacOS下使用LaunchDaemons实现开机自启动
macos
鹏多多2 天前
Flutter下拉刷新上拉加载侧拉刷新插件:easy_refresh全面使用指南
android·前端·ios
青花锁2 天前
Mac电脑安装Docker
macos·docker·容器
驱动探索者2 天前
[缩略语大全]之[IOS]篇
ios
kkk_皮蛋3 天前
在移动端使用 WebRTC (Android/iOS)
android·ios·webrtc