google-perftools
1.google-perftools简介
简介略
2.ubuntu下的安装
默认安装路径为/usr/local/,头文件和库文件分别在/usr/local/inlcude/google/和/usr/local/lib/下
- 1 从github上下载源码https://github.com/gperftools/gperftools
git clone https://github.com/gperftools/gperftools
- 2 进入源码目录,执行autogen.sh
./autogen.sh
若是出现错误
错误:autogen.sh: line 3: autoreconf: command not found
解决办法:
方法1:sudo apt install autoconf automake libtool
或者
方法2:安装autoconf
wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
tar zxvf autoconf-2.69.tar.gz
- 3
./configure --prefix="安装的路径,最好在个人账户上"
- 4.
make
若是出现错误
错误: *** No targets specified and no makefile found. Stop.
解决办法:
1.安装libunwind
sudo apt-get install libunwind8-dev
2.更新软件
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install gcc build-essential
./configure
make
其他方法安装libunwind
在http://download.savannah.gnu.org/releases/libunwind 下载相应的libunwind版本
[root@localhost home]# tar zxvf libunwind-0.99-alpha.tar.gz
[root@localhost home]# cd libunwind-0.99-alpha/
[root@localhost libunwind-0.99-alpha]# CFLAGS=-fPIC ./configure
[root@localhost libunwind-0.99-alpha]# make CFLAGS=-fPIC
[root@localhost libunwind-0.99-alpha]# make CFLAGS=-fPIC install
- 5.
make install
- 6 添加环境变量
vi ~/.bashrc
添加export PATH=$PATH:你的安装路径
3.使用
使用步骤
编辑test.cpp文件,添加申请地址的代码
g++ test.cpp -L/~myapp/gpreftools/lib/ -ltcmalloc -o a
HEAPCHECK=normal ./a
使用时出现的错误清康
1.若是出现错误提示如下
错误:./test: error while loading shared libraries: libtcmalloc.so.4: cannot open shared object file: No such file or directory
解决办法:“#”表示命令前面的用户
# su root
# vim /etc/ld.so.conf 添加新的一行 /usr/local/lib
# ldconfig 使生效
# exit 退出
2.若是运行提示命令,但是显示dot :not command,则需要安装grapthviz
安装步骤如下:
去官网下载安装包
wget https://www2.graphviz.org/Packages/stable/portable_source/graphviz-2.42.1.tar.gz
参考文献
参考1 编译安装google-perftools工具,以及单独安装组件tcmalloc记录
参考2 Google Perftools简介与使用
参考3 在Linux安装autoconf-2.69版本