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

相关推荐
草莓熊Lotso7 小时前
Python 库使用全攻略:从标准库到第三方库(附实战案例)
运维·服务器·汇编·人工智能·经验分享·git·python
2501_916007477 小时前
iOS 自动化上架的工具组合,在多平台环境中实现稳定发布
android·运维·ios·小程序·uni-app·自动化·iphone
TO_ZRG7 小时前
iOS 符号表文件概要
macos·ios·cocoa
默默在路上7 小时前
M芯片使用VMware Fusion安装CentOS Stream 9教程
linux·macos·centos
TheNextByte18 小时前
如何在Mac上收发Android信息 [2026 指南]
android·macos
耘田8 小时前
 macOS Launch Agent 定时任务实践指南
java·开发语言·macos
不爱吃糖的程序媛8 小时前
macOS 系统本地安装 openJiuwen 完整指南
macos
William.csj8 小时前
Mac——一款支持跨平台的与服务器之间的远程传输工具 FileZilla
macos·filezilla
shankss1 天前
GetX 状态管理详解
android·flutter·ios
Nightmare0041 天前
Mac打开终端
macos