xcode 无论如何要在Xcode中查看方法执行时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4562968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
anyway to see method execution times in Xcode?
提问by Slee
I need to debug a certain ViewController I have and I can't seem to pinpoint exactly what is causing my lag time for the view to show.
我需要调试我拥有的某个 ViewController,但我似乎无法准确指出是什么导致了我的视图显示延迟时间。
IS there any debugger tool in Xcode that will show me how long my methods are taking to run so i can at least find the right place to start?
Xcode 中是否有任何调试器工具可以显示我的方法运行需要多长时间,以便我至少可以找到正确的开始位置?
回答by Dan Ray
Instruments has a profiler built into it ever since iOS 4.0 (before which you used a stand-alone profiler tool called Shark).
从 iOS 4.0 开始,Instruments 就内置了一个分析器(在此之前你使用了一个名为 Shark 的独立分析器工具)。
Here's a quick little tutorial that will get you started: http://blancer.com/tutorials/flex/78335/apple-profiling-tools-shark-is-out-instruments-is-in/
这是一个快速的小教程,可以帮助您入门:http: //blancer.com/tutorials/flex/78335/apple-profiling-tools-shark-is-out-instruments-is-in/
If you don't know about Instruments, you should. It's how you know what's really going on inside your code while it runs.
如果您不了解 Instruments,那么您应该了解。这是您在代码运行时了解代码内部实际情况的方式。
回答by raaz
Apart from Time Profiler as suggested by Dan you can also use Sampler instrument which generally stops a program at prescribed intervals and records the stack trace information for each of the program's threads. You can use this information to determine where execution time is being spent in your program and improve your code to reduce running time.
除了 Dan 建议的 Time Profiler 之外,您还可以使用 Sampler 工具,它通常以规定的时间间隔停止程序并记录每个程序线程的堆栈跟踪信息。您可以使用此信息来确定程序中的执行时间花在何处,并改进代码以减少运行时间。
The main difference between sampler & Time profiler :
采样器和时间分析器之间的主要区别:
Sampler instrument operates upon a single process but Time Profiler operates upon a single/All processes.
Sampler 仪器在单个进程上运行,而 Time Profiler 在单个/所有进程上运行。