How to find out what mach_msg_trap waits for?

房东的猫 提交于 2019-12-18 11:11:24

问题


I a profiling my iPhone application on target, and according to Instruments 65% of the time is spent in mach_msg_trap.

I have a background thread that runs-forever and send results back to the main thread using performSelectorOnMainThread:withObject:waitUntilDone:, aproximately every 2 seconds. I am not waiting until done.


回答1:


Turn out my app is not actually spending 65% of it's time in the mach_msg_trap function. It was a configuration error in Instruments on my part.

The Sampler tool defaults to All Sample Counts, this will measure all threads regardless of their state.

Instead switch to Running Sample Times that will reflect the current actual workload. Screenshot of Instruments http://developer.apple.com/library/mac/qa/qa2009/images/qa1619_running_sample_times.png




回答2:


If you're not expecting your main thread to be doing anything other than waiting on this background thread (or waiting for user input) there's nothing to be concerned about -- your application simply has nothing to do most of the time.

If you're expecting the main thread to be actively doing something else, please update your question to describe that. In this case, you might want to look at the full call stacks to mach_msg_trap as it's often at the bottom of a call stack where the actual time-waster is further up.



来源:https://stackoverflow.com/questions/1488601/how-to-find-out-what-mach-msg-trap-waits-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!