使用sample和FlameGraph
sample ${pid} ${timeout} -f ~/Desktop/ouput.prof
git clone https://github.com/brendangregg/FlameGraph
cd FlameGraph
./stackcollapse-sample.awk ~/Desktop/ouput.prof| flamegraph.pl > ~/Desktop/perf.svg
pid为进程号
timeout为抓取的时间,单位为秒
另外一种方法是使用instruments工具中的Time profiler,这个工具比火焰图更加强大,但是Time profiler抓取的是CPU时间,可能在非计算场景下并不准确。