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

相关推荐
陌上花开缓缓归以6 小时前
mips u-boot如何在汇编中添加调式打印
汇编
harder3219 小时前
Swift 面向协议编程的 RMP 模式
开发语言·ios·mvc·swift·策略模式
YoungHong19929 小时前
Claude Code & 智谱GLM-5.1 环境配置指南 (Windows/macOS/Ubuntu)
windows·ubuntu·macos
leluckys9 小时前
Jenkins CI/CD 持续集成专题十二、iOS-Jenkins自动化打包集成
ios·ci/cd·jenkins
leluckys9 小时前
Jenkins CI/CD 持续集成专题八- jenkins 之 iOS 打包及上传至蒲公英
ios·ci/cd·jenkins
全栈攻略9 小时前
老版本Docker Desktop for Mac 历史版本下载大全(macOS 10.15/11/12)
macos·docker·容器
YoungHong19929 小时前
【图文】Codex接入Kimi K2/GLM-5.1 环境配置指南 (Windows/macOS/Ubuntu)
windows·ubuntu·macos
leluckys9 小时前
Jenkins CI/CD 持续集成专题十一、jenkins打包ios脚本证书
ios·ci/cd·jenkins
leluckys9 小时前
Jenkins CI/CD 持续集成专题十-jenkins 可以通过api 打ios包
ios·ci/cd·jenkins
leluckys9 小时前
Jenkins CI/CD 持续集成专题九 -Mac服务器上配置Jenkins实现iOS项目自动打包
macos·ci/cd·jenkins