gperftools-cpu性能分析

通过 gperf 对程序进行性能分析

软件安装

  • 在 mac os 上安装 brew install gperftools

在 CMakeLists.txt 中链接 profiler

1
2
3
set(LIB_PROFILER_DIR "/opt/homebrew/Cellar/gperftools/2.16/lib")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${LIB_PROFILER_DIR} -lprofiler -ltcmalloc")
add_executable(expression_template_array_profile calculation_profile.cc)

执行 profiler

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
bin_name=expression_template_array_profile
prof_file=$bin_name.prof
text_file=$bin_name.txt
svg_file=$bin_name.svg

# 生成 prof 文件
env CPUPROFILE=$prof_file $bin_name

# 输出文本和 svg 图片
pprof $bin_path $prof_file --text > $text_file
pprof $bin_path $prof_file --svg > $svg_file

TODO

火焰图

其他

comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计