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

相关推荐
CZIDC37 分钟前
MacOS字体看起来比在 Windows 上更好?
macos
Cosmoshhhyyy8 小时前
linux远程部署dify和mac本地部署dify
linux·运维·macos
行星0088 小时前
mac 通过homebrew 安装和使用nvm
macos·npm·node.js
麦兜*10 小时前
【swift】SwiftUI动画卡顿全解:GeometryReader滥用检测与Canvas绘制替代方案
服务器·ios·swiftui·android studio·objective-c·ai编程·swift
2501_9280946516 小时前
Mac电脑录屏工具 Omi录屏专家(Mac中文)
macos·mac·录屏工具·omi
small_wh1te_coder17 小时前
GCC深度剖析:从编译原理到嵌入式底层实战
汇编·c++·面试·嵌入式·状态模式·c
GeniuswongAir18 小时前
iOS 26 一键登录失效:三大运营商 SDK 无法正常获取手机号
ios
吴Wu涛涛涛涛涛Tao19 小时前
Flutter 实现类似抖音/TikTok 的竖向滑动短视频播放器
android·flutter·ios
森之鸟19 小时前
Mac chrome浏览器下载DevEco Studio 6.0.0 Beta2失败
前端·chrome·macos