Instruments — How to measure large memory copies

What's the best way in Instruments, to measure the amount of time spent on large memory copies? For a very simple example, when directly calling memcpy? Memory copying does not show up in the time profiler, it's not a VM cache miss or zeroing event, etc so it doesn't show there, it doesn't (as far as I can tell) show up in the system trace, and there aren't any other choices.

Replies

Instruments doesn't offer a way to measure all time an app spends copying memory. There's no great way for Instruments to distinguish between copying memory (reading from some memory locations and writing the read values to others) and reading and writing memory without copying.

Instruments can help if you know which parts of your code or system-provided functions like memcpy() perform these copies. The Time Profiler instrument can estimate time spent in specific functions like memcpy(), and the os_signpost instrument can display signpost intervals you add around copies performed by your code.

To estimate time spent in a specific function like memcpy(), capture a Time Profiler trace of your app, then filter to only samples involving that function's symbol using the filter field.

If you need more precision than Time Profiler provides, or want to time only parts of functions, you can add signposts around the parts of your code which perform these copies, then visualize the signpost data with the os_signpost instrument.

  • Thanks. The trouble is, memcpy as a symbol does not show at all in the Time Profiler. (Nor any other symbol in its place.) If you stick a long hard loop on just memcpy() from whatever location to wherever else, it simply does not show up as a sample anywhere. Which then leaves wrapping it or signposts around every place I can conceive of as a potentially hot spot for copying.

Add a Comment