Frequent small methods and Time Profiler

So, I'm profilling an iOS application with the Time Profiler instrument for 10m, and I can see that somewhere around 35% of the samples show a particular method block. It's triggered frequently, but it shouldn't be particularly slow, so given that Time Profiler is a sampling profiler, and 35% of samples doesn't necessarily mean 35% of code execution, I was curious to dig a little further.


With the new signposts API and the System Trace instrument, I thought I'd compare. In a 10s window, it looks like this same block runs 11 times, from 7-27ms.


It seems odd to me that the Time Profiler would report 35% of samples contain this code tree when it seems to run about once a second for a very short time. Trying to reconcile those facts, and something that I don't know how it fits in is "idle time." If the CPU, when sampled, is doing nothing to speak of, or nothing in my app -- does that sample get discarded? Is the 35% actually 35% of "samples that contained something to do with your app"? If so, that might be enough to reconcile th diffrence, because the app shouldn't be working the system hard during either of these samples, something they both certainly show.


Now that I've said that all "out loud", it actually seems like an extremely likely explanation, but ... I've already typed this all, and I'd be happy to have someone agree with me. 😉

Accepted Reply

When you Time Profile a single application, a "sample" is whenever we see your application doing something. So, 1000 times a seconds we check to see what is running on the CPU(s). If a CPU is idle, nothing is recorded. If a CPU is running another application, nothing is recorded. Only if your application is on a CPU at that instant do we take a sample and record its backtrace.


So yeah, 35% of the time when Instruments looked and saw your application running, your app was in that particular block.

Replies

FWIW, screenshots to illustrate:

http://imgur.com/a/zOV5w

When you Time Profile a single application, a "sample" is whenever we see your application doing something. So, 1000 times a seconds we check to see what is running on the CPU(s). If a CPU is idle, nothing is recorded. If a CPU is running another application, nothing is recorded. Only if your application is on a CPU at that instant do we take a sample and record its backtrace.


So yeah, 35% of the time when Instruments looked and saw your application running, your app was in that particular block.