使用 Instruments Time Profiler 时如何细分函数
我有一个相对较长的函数,它在 Instruments Time Profiler 中占主导地位。有没有办法向该函数添加额外的符号,以便采样将显示分配给函数不同部分的时间?我正在寻找类似 prof(1) 几年前存在的 MARK 宏的东西。
I've got a relatively long function that's dominant in the Instruments Time Profiler. Is there a way to add additional symbols to this function so the sampling will show time allocated to different parts of the function? I'm looking for something like the MARK macro that existed for prof(1) years ago.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用宏:
对我来说效果很好。这实际上只是我在原来的问题中提到的旧 MARK 宏的简化。放置MARK(LOOP1);函数中的某处将添加一个新符号 M.LOOP1,它将显示在 shark 或仪器显示的函数列表中。
Using the macro:
has been working well for me. This is really just a simplification of the old MARK macro I mentioned in my original question. Placing MARK(LOOP1); somewhere in a function will add a new symbol, M.LOOP1 that will show up in a list of functions shown by shark or instruments.
我最近发现,在仪器的时间分析器中,如果双击一个方法,它会向您显示源代码以及每行所花费的时间百分比。
http://douglasheriot.com/blog/2011/04/xcode- 4-instruments-awesomeness/
我发现它非常有用,但我不确定这是否是您所要求的。
I discovered recently that in the time profiler in instruments, if you double-click on a method, it'll show you your source code with percentages of time spent on each line.
http://douglasheriot.com/blog/2011/04/xcode-4-instruments-awesomeness/
I've found it very useful, but I'm not sure if that's what you're asking for.
有人告诉我 Shark 可以做到这一点,所以 Instruments 也应该这样做,但你必须告诉它要做什么:
在挂钟时间(不仅仅是 CPU 时间)上对函数调用堆栈(不是仅程序计数器 PC)。
告诉您出现在大部分堆栈样本中的代码行(不仅仅是函数)。
堆栈样本包括 PC 和指向 PC 所在位置的每条调用指令。
堆栈上的每条指令都共同负责所花费的时间片。
因此,任何负责 X% 时间的代码行将有 X% 的时间位于堆栈上。如果它足够大,值得一看,您就会在样品上看到它。您可能会得到很多样品,但实际上并不需要很多。这是因为定位问题比精确测量问题更重要。
如果你最大的问题在解决后可以节省 5%,那么它就会出现在大约 5% 或更多的样本中。如果它比这个小,那么你的代码就相当最优了。它很可能比这个大得多,所以你可以毫不费力地看到它的准确位置。
添加:进行实时堆栈采样并按行显示百分比的探查器示例是 Zoom,所以我建议你看那个视频。然后,尝试让 Instruments 做同样的事情。
I'm told that Shark can do this, so Instruments should also, but you have to tell it what to do:
Do sampling, on wall-clock time (not just CPU time), of the function call stack (not just the program counter PC).
To tell you the lines of code (not just functions) that appear on a good percentage of stack samples.
A stack sample includes the PC and every call instruction leading to where the PC is.
Every instruction on the stack is jointly responsible for that slice of time being spent.
So any line of code responsible for X% of the time will be on the stack X% of the time. If it's big enough to be worth looking at, you will see it on the samples. You may get a lot of samples, but you don't actually need a lot. This is because it's more important to locate the problem than to measure it with much precision.
If your biggest problem, when fixed, would save you 5%, it will appear on about 5% or more of samples. If it's any smaller than that, your code's pretty optimal. Chances are it's a lot bigger than that, so you won't have any trouble seeing precisely where it is.
Added: An example of a profiler that does wall-time stack sampling and shows percent-by-line is Zoom, so I suggest you watch that video. Then, try to get Instruments to do the same thing.
更新:
我已经更新了代码并创建了一个单独的项目:
https://github.com/nielsbot/Profiler
我有一些代码可以在这里执行此操作:我有一些代码您可能会在这里找到可以执行此操作的代码:https:// /gist.github.com/952456 HTH
您可以使用以下代码来分析函数的各个部分,如下所示:
UPDATE:
I have updated the code and created a separate project:
https://github.com/nielsbot/Profiler
I have some code that can do this here: I have some code you might fin that can do this here: https://gist.github.com/952456 HTH
You can profile sections of your function using this code like this: