重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

使用gperftools进行C++代码分析-创新互联

1 安装

成都创新互联公司从2013年成立,是专业互联网技术服务公司,拥有项目成都网站建设、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元黄埔做网站,已为上家服务,为黄埔各地企业和个人服务,联系电话:028-86922220

1.1 基础软件

在命令行中通过 apt 安装 autoconf、automake、libtool:

sudo apt install autoconf automake libtool

1.2 libunwind

gperftools 在 64 位操作系统下需要 libunwind 库的支持,libunwind 提供了可用于分析程序调用栈的 API,进行安装:

cd ~
wgethttps://github.com/libunwind/libunwind/releases/download/v1.6.2/libunwind-1.6.tar.gz
tar -zxvf libunwind-1.6.2.tar.gz
cd libunwind-1.6.2
./configure
make -j8
sudo make install
cd ~
rm -rf libunwind-1.6.2.tar.gz libunwind-1.6.2

1.3 graphviz

gperftools 使用 graphviz 将代码性能分析结果进行图形化显示。graphviz 是一个由 AT&T 实验室开发的开源工具包,用于绘制 DOT 语言脚本描述的图形,ubuntu 可通过 apt 直接安装:

sudo apt install graphviz

1.4 gperftools

gperftools 可直接执行下述命令行进行安装:

cd ~

wgethttps://github.com/gperftools/gperftools/releases/download/gperftools10/gperftools-2.10.tar.gz

tar -zxvf gperftools-2.10.tar.gz

cd gperftools-2.10

 ./configure

make -j8

sudo make install

cd ~

rm -rf gperftools-2.10.tar.gz gperftools-2.10

2.使用

https://blog.shipengx.com/download/cpp_demo.zip C++ 工程 Demo 可点击这里下载

2.1 代码插桩

在使用 gperftools 进行代码性能分析前,需要进行代码插桩:

插入头文件:

#include

分析的代码块前插入 Profiler 开始语句:

ProfilerStart("file_name.prof");

file_name.prof 表示 .prof 文件的文件名。

在待分析的代码块后插入 Profiler 结束语句:

ProfilerStop();

完整的插桩代码:

#include "inc/func.hpp"

#includeint main()

{

    ProfilerStart("cpp_demo_perf.prof");



    PrintString("This's a demo.");

    Func();



    ProfilerStop();



    return 0;

}

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


网站栏目:使用gperftools进行C++代码分析-创新互联
标题URL:http://cqcxhl.cn/article/hcgho.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP