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

相关推荐
●VON22 分钟前
【鸿蒙PC】在 HarmonyOS 上跑 Electron?手把手教你搞定桌面欢迎页!(Mac版)
开发语言·macos·华为·electron·电脑·harmonyos
一见34 分钟前
macOS 上 OpenClaw + QQBot 安装指南
macos
2501_9159214339 分钟前
iOS APP上架工具,在没有 Mac 的环境中发布苹果应用
android·macos·ios·小程序·uni-app·iphone·webview
AI-小柒1 小时前
巨省Token:OpenClaw安装部署并接入数眼智能特价模型全流程(包含Windows和Mac)
大数据·人工智能·windows·网络协议·tcp/ip·http·macos
一只代码狗1 小时前
OpenClaw 安装教程(Windows&&macOS)
windows·macos·ai·openclaw
今晚务必早点睡1 小时前
Linux和macOS 常用包安装工具梳理
linux·运维·macos
wjm0410061 小时前
ios学习路线 -- Swift基础(1)
开发语言·ios·swift
00后程序员张1 小时前
iOS 应用的 HTTPS 连接端口在网络抓包调试中有什么作用
android·网络·ios·小程序·https·uni-app·iphone
2501_915909062 小时前
iPhone 手机日志实时查看,开发和测试中常用的几种方法
android·ios·智能手机·小程序·uni-app·iphone·webview
库奇噜啦呼2 小时前
【iOS】Effective Objective-C第二章
ios·objective-c·cocoa