GPerfTools性能分析工具

404 阅读1分钟

安装

使用源码进行安装


sudo apt install autoconf
sudo apt install libtool

git clone https://github.com/gperftools/gperftools
cd gperftools
./autogen.sh
./configure
make
sudo make install

使用

在需要进行分析的函数中插入代码

#include <gperftools/profiler.h>

int main(int argc, char** argv)
{    
    ProfilerStart("./test.prof");

    function_need_to_analysis();

    ProfilerStop();

    return 0;
}

CMake使用方法

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lprofiler")
target_link_libraries(executable_name profiler)

直接编译时,加入-lprofiler编译参数。

生成报告

使用--gv--web--pdf生成不同类型的报告

pprof --pdf ./build/executable_name  ./test.prof > test.pdf