I am attempting to analyze the amount of time individual images are taking to load into my iPhone app. dyld has some fun environment variables for seeing the overall time, but tracking individual libraries is not possible (As far as I know). I looked into the dyld source code and found Tracing.h which led me to believe I could put together a custom instrument to track image loading. Here is the schema I used:
<ktrace-interval-schema>
<id>com-google-dyld-map-image-schema</id>
<title>dyld map image</title>
<start-pattern>
<class>31</class>
<subclass>7</subclass>
<code>2</code>
<function>1</function>
<arg1>?id</arg1>
<arg2>?afilepath</arg2>
</start-pattern>
<end-pattern>
<class>31</class>
<subclass>7</subclass>
<code>2</code>
<function>2</function>
<arg1>?id</arg1>
</end-pattern>
<start-column>
<mnemonic>start</mnemonic>
<title>Start</title>
<type>start-time</type>
</start-column>
<duration-column>
<mnemonic>duration</mnemonic>
<title>Duration</title>
<type>duration</type>
</duration-column>
<column>
<mnemonic>id</mnemonic>
<title>id</title>
<type>uint64</type>
<expression>?id</expression>
</column>
<column>
<mnemonic>path</mnemonic>
<title>path</title>
<type>file-path</type>
<kdebug-string-from>?afilepath</kdebug-string-from>
</column>
<column>
<mnemonic>path-id</mnemonic>
<title>path-id</title>
<type>kdebug-string</type>
<expression>?afilepath</expression>
</column>
</ktrace-interval-schema>
and here is the table/graph/list:
<create-table>
<id>timings-table</id>
<schema-ref>com-google-dyld-map-image-schema</schema-ref>
</create-table>
<graph>
<title>Image Mapping Trace</title>
<lane>
<title>Image Mappings</title>
<table-ref>timings-table</table-ref>
<plot>
<value-from>path</value-from>
</plot>
</lane>
</graph>
<list>
<title>Image Mapping Times</title>
<table-ref>timings-table</table-ref>
<column>start</column>
<column>duration</column>
<column>path</column>
<column>path-id</column>
</list>
</instrument>
So when I run this in instruments, I get:
Notice that the path is "n/a"
I look in the Instruments Inspector for kdebug-strings and see:
I'm assuming I am getting N/A because there are two strings (one filled and one blank) tied to each of the kdebug string IDs. Is this a valid assumption?
I went looking in the dyld timing code, and it appears Tracing.h that kdebug_trace_string is being called both to set and clear the string. I'm guessing that we never want kdebug_trace_strings cleared.
Is there anyway for me to get my image name to appear correctly?
The complete source for my instrument is here.
Cheers,
Dave