Search code examples
profilinginstruments

Instruments profiling: "top functions" reorders functions


I have optimized a function Render() by changing OpenGL code. I have then run Instruments / Time Profile with time limit 180 sec (so the measure was done accurately).

  1. Turn on Invert Call Tree:
    • 680 ms for non-optimized,
    • 500 ms for optimized.
  2. Turn off Invert Call Tree:
    • 277 ms for non-optimized,
    • 345 ms for optimized.
  3. Turn on Top Functions (still turn off Invert Call Tree):
    • 4591 ms for non-optimized,
    • 5277 ms for optimized.
  4. Turn on Invert Call Tree (still turn on Top Functions):
    • no changes (4591),
    • no changes (5277).

How to interpret this? Is the optimized version faster or slower?


Solution

  • The Time Profiler results depend on the version of Xcode you're running. If you are running Xcode 4.4 or later, the Time Profiler instrument has two columns for each symbol in the call tree: Running Time and Self. The Self column is more important because it tells you the amount of time the function was at the top of the call stack. All the Running Time column tells you is how much time the function was on the call stack, which doesn't really mean as much as being at the top of the stack.

    To see how much time your app spent in Render(), deselect the Invert Call Tree checkbox and look at the Self column for Render(). If this is a game you're profiling, what can help is to double-click your game loop function in the call tree. Double-clicking the game loop function opens the source view, which will tell you the percentage of time your game loop spends in the Render() function.

    The Time Profiler instrument isn't the best tool for profiling OpenGL code. If you're writing a Mac app, the OpenGL Profiler tool profiles OpenGL code better than Instruments. Instruments also has an OpenGL Driver instrument for measuring OpenGL statistics. If you're profiling an iOS app, use the OpenGL ES Analysis Instruments template and the OpenGL ES Performance Detective tool.