性能分析工具gperftools安装及使用

本文介绍如何在Ubuntu环境下安装libunwind和gperftools,并配置kcachegrind工具。通过具体示例展示如何利用gperftools进行性能分析,包括设置环境变量以生成性能报告文件,并使用pprof工具将报告转换为PDF或TXT格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

./configure --prefix=/home/your_name/tools/libunwind/ CFLAGS=-U_FORTRIFY_SOURCE
make
make install 
./configure --prefix=/home/your_name/tools/gperftools LDFLAGS=-L/home/your_name/tools/libunwind/lib CPPFLAGS=-I/home/your_name/tools/libunwind/include
make
make install 
  • 3、安装kcachegrind
    系统ubuntu16.04
sudo apt-get install kcachegrind
env LD_PRELOAD="/home/your-name/tools/gperftools/lib/libprofiler.so" CPUPROFILE_FREQUENCY=100 CPUPROFILE=cpu_perf.prof ./Test

运行完成后会在当前目录下生成cpu_perf.prof文件,结合pprof工具(gperftools/bin)可生成txt或pdf等:

~/tools/gperftools/bin/pprof --pdf ./test cpu_perf.prof > cpu_perf.pdf
~/tools/gperftools/bin/pprof --txt ./test cpu_perf.prof > cpu_perf.txt

或者在代码中加入google/profiler.h头文件并结合相应函数使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值