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

相关推荐
Zender Han4 小时前
Flutter Bloc / Cubit 最新详解与实战指南(2026版)
android·flutter·ios
小路恢弘4 小时前
xcode替换LLVM插件
ide·macos·xcode
ChengQianO5 小时前
从 0 开始:Mac 下 UTM 虚拟机安装 ROS Noetic(Ubuntu 20.04)
linux·ubuntu·macos
BigDark的笔记6 小时前
【ARM汇编】0x01_ARM和C混合编程实现基本运算
c语言·汇编·arm开发
tangweiguo030519877 小时前
iOS vs Android 开发对照手册
android·ios
草帽lufei8 小时前
macOS中的Cursor等软件突然不能用了
macos·cursor
weixin_443478518 小时前
flutter组件学习之Cupertino 组件(iOS风格)
学习·flutter·ios
Rabbit_QL8 小时前
【Warp+Claude】任务完成自动通知(macOS + Warp 版)
macos·策略模式
X档案库10 小时前
【ROS2】Mac M4 虚拟机 Ubuntu 24.04 安装 ROS2 Jazzy 新手教程
macos·机器人·ros
江城月下10 小时前
从零开始:我在 Mac M1 上搭建离线 AI 知识库的实战记录
人工智能·macos