Context: We're trying to add xctrace
support for inferno, a rust library used to generate flamegraphes. Actual issue can be found here. This question was previously asked on apple developer forums, without luck so far.
Flamegraphes are built by aggregating CPU samples to see which functions are hot.
To do so we need to have access to the full callstack for each sample, however when exporting a trace with xctrace export
, the callstack is cropped.
Steps to reproduce the issue:
$ xctrace record --template 'System Trace' --output PATH/TO/TRACE/FILE.trace --launch YOUR_PROCESS_NAME
, and wait for the given process to finish.$ xctrace export --output foo.xml --input PATH/TO/TRACE/FILE.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="time-sample"]
3. open foo.xml
, and check the rowsNote: xctrace export
have several export schema available but time-sample
seems to be the one containing the callstack.
Sample row:
<row>
<sample-time id="22" fmt="00:00.039.455">39...</sample-time>
<thread ref="2"/>
<process ref="4"/>
<core ref="14"/>
<thread-state ref="8"/>
<weight ref="9"/>
<backtrace id="23" fmt="test::test::foo ← (11 other frames)">
<process ref="4"/>
<text-addresses id="24" fmt="frag 1732">4331406713 4331406716</text-addresses>
<process ref="4"/>
<text-addresses id="25" fmt="frag 1733">4331403 ...</text-addresses>
</backtrace>
</row>
As one can see the callstack/backtrace is cropped "(11 other frames)", however according to the apple Instrument.app
's (Apple's GUI to read xctrace
reports) documentation it is possible to have it listed and symbolicated:
In extended views, the entire symbolicated backtrace is listed.
I was unable to find how to export the extended view.
Another option would be to symbolicate the backtrace using the text-addresses
if those are trustable. That question was asked a year ago on apple developers forums, without answer so far.
Starting from Xcode 14.3, xctrace export
contains the fully desymbolicated backtraces.
You can start a recording with either of these commands:
xctrace record --template 'Time Profiler' --launch <executable> --output tmp.trace
xctrace record --template 'Time Profiler' --attach <pid|proc_name> --output tmp.trace
then extract the time profile from it:
xctrace export --input tmp.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="time-profile"]'