用于统计 iPhone 上方法调用次数的工具
Time Profiler 可以测量某些方法所花费的时间量。是否有类似的方法来测量方法被调用的次数?
The Time Profiler can measure the amount of time spent on certain methods. Is there a similar method that measures the number of times a method is called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DTrace 可以做到这一点,但仅限于 iPhone 模拟器(Snow Leopard 支持它,但 iOS 尚不支持)。我在 MacResearch 上有两篇关于这项技术的文章 这里和此处,我将介绍一些使用 DTrace 查找特定方法及其调用时间的案例研究。
例如,我创建了以下 DTrace 脚本来测量对带有 CP 前缀的类调用方法的次数,以及计算在这些方法中花费的时间的总和:
生成以下格式良好的输出:
这会 从命令行运行 DTrace 脚本,您最好的选择可能是在 Instruments 中创建自定义仪器并在该仪器中填写适当的 D 代码。然后,您可以在模拟器中针对您的应用程序轻松运行它。
同样,这在设备上不起作用,但如果您只想统计某项被调用的次数,而不是它运行的持续时间,这可能可以完成工作。
DTrace can do this, but only in the iPhone Simulator (it's supported by Snow Leopard, but not yet by iOS). I have two writeups about this technology on MacResearch here and here where I walk through some case studies of using DTrace to look for specific methods and when they are called.
For example, I created the following DTrace script to measure the number of times methods were called on classes with the CP prefix, as well as total up the time spent in those methods:
This generates the following nicely formatted output:
While you can create and run DTrace scripts from the command line, probably your best bet would be to create a custom instrument in Instruments and fill in the appropriate D code within that instrument. You can then easily run that against your application in the Simulator.
Again, this won't work on the device, but if you just want statistics on the number of times something is called, and not the duration it runs for, this might do the job.