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

相关推荐
_瑞4 小时前
读懂 iOS 的线程调用栈
ios·编译原理·汇编语言
末代iOS程序员华仔7 小时前
iOS 语聊直播/聊天APP4.3条例被拒解决
flutter·ios·swift
Lucky09288 小时前
codex 安装前置软件
linux·运维·macos
Zguigo17 小时前
lesson24-26计算机网络第三章精讲:从MAC地址到CSMA/CD,数据链路层核心知识一网打尽
计算机网络·macos
极客互动API1 天前
企业微信 iPad 协议服务搭建与 AI 回调实战
网络·汇编·人工智能·微信·企业微信·ipad
EXI-小洲1 天前
MacOS 环境下 IntelliJ IDEA 的 Maven 配置指南
macos·maven·intellij-idea
2601_965798471 天前
Build a Fast, High-Ranking Restaurant Website with Rolanda Theme
开发语言·ios·swift
极客互动API1 天前
企业微信 iPad 协议消息接口开发:文本 / 图片 / 群发消息的统一封装
人工智能·ios·微信·机器人·企业微信·ipad
我血条子呢1 天前
iOS 软键盘遮挡底部输入框解决报告
ios
aspirant-complete1 天前
MAC(Apple Silicon)嵌入式基于Clion(stm32CubeMX)环境搭建
stm32·macos