[macOS] Profiling — visualize program bottleneck with Flamegraph

<p>This article is a follow up on the previous&nbsp;<a href="https://medium.com/@techhara/profiling-visualize-program-bottleneck-with-flamegraph-3e0c5855b2fe" rel="noopener">article</a>&nbsp;that describes how to obtain Flamegraph on Linux. Today, let&rsquo;s do the same for macOS platform.</p> <p>The first difference is that on macOS, there is no&nbsp;<code>perf</code>&nbsp;utility, as it is specific to Linux. One can use&nbsp;<code>dtrace</code>&nbsp;as an alternative, but then macOS has system integrity protection (SIP) feature that blocks collecting system calls. A better alternative is to use Apple&rsquo;s own profiling tool,&nbsp;<a href="https://help.apple.com/instruments/mac/current/#/" rel="noopener ugc nofollow" target="_blank">Instruments</a>. Unfortunately, this is intended as a GUI app, so it&rsquo;s hard to make a script and automate things, but the good news is that at least it is doable.</p> <p>First, make sure to install Instruments by installing&nbsp;<a href="https://apps.apple.com/us/app/xcode/id497799835?mt=12" rel="noopener ugc nofollow" target="_blank">XCode</a>. Make sure you can run&nbsp;<code>xctrace</code>, which should output shown below</p> <p><a href="https://medium.com/@techhara/profiling-visualize-program-bottleneck-with-flamegraph-macos-4a2b3598df8a"><strong>Visit Now</strong></a></p>