ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
gperftools时google开源的一款C++性能分析分析工具,[这里](https://github.com/gperftools)是其github项目地址。 ### 下载并编译 以2.7release版为例。 下载源代码: ~~~bash wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.7/gperftools-2.7.tar.gz ~~~ 解压: ~~~bash tar -zxf gperftools-2.7.tar.gz ~~~ 配置: ~~~ cd gperftools-2.7/ ./configure ~~~ 如果没有安装libunwind会出现如下提示: ~~~bash configure: WARNING: No frame pointers and no libunwind. Using experimental backtrace capturing via libgcc. Expect crashy cpu profiler. ~~~ 使用命令`apt-get install libunwind8-dev`安装libunwind。 重新执行`./configure`就没有了警告提示。 然后生成二进制文件并且安装: ~~~bash make make install ~~~ 还需要对库文件进行更新: ~~~bash ldconfig ~~~ 接下来我们就可以在程序中使用了。 ### 使用gpertools 1. 修改程序的源代码使得要profiler的代码段包含在`ProfilerStart("name");`和`ProfilerStop();`之间,例如 ~~~c++ #include"feagetter/feagetter.h" #include"spreader/spreader.h" #include"transparse/getTrans.h" #include"expand/expand.h" #include<gperftools/profiler.h> #include<time.h> #include<fstream> #include<string> #include<string.h> using namespace std; int main(int argc,char *argv[]) { ProfilerStart("epm03.prof"); ... while (fg.haveNext()) { obschange(fg.getobslg(),obs); vm.forward(obs); } ... char* ans=new char[4096]; getTrans(lattice,N,ans); cout<<vm.getDummyScore()<<endl; printf("%s\n", ans); ProfilerStop(); return 0; } ~~~ 2. 对源代码进行编译: ~~~bash g++ myapp -l profiler ~~~ 3. 运行程序就可以发现在所在文件夹下产生了名为name的文件。 4. 使用命令`pprof --pdf ./myapp name > pdfname`就可以将结果转化为pdf查看。 ### 问题 在ubuntu on windows下使用gperftools总是报错误: ~~~bash PROFILE: interrupts/evictions/bytes = 0/0/64 ~~~ 推测与windows的支持机制有关,目前只能在真正的linux上使用。