在Mac OS X上使用gperftools的问题
Problems with using gperftools on Mac OS X
我在这个话题上找到了几个相互矛盾的答案。这篇博客文章需要libuwind,但这在Mac OS X上不起作用。我在代码中包含了#include <google/profiler.h>
,但我的编译器(g++)找不到库。我通过自制软件安装了gperftools
。此外,我发现这个stackoverflow问题表明:
然后我运行approf生成输出:
[hidden ~]$ pprof --text ./a.out cpu.profile Using local file ./a.out. Using local file cpu.profile. Removing __sigtramp from all stack traces. Total: 282 samples 107 37.9% 37.9% 107 37.9% 0x000000010d72229e 16 5.7% 43.6% 16 5.7% 0x000000010d721a5f 12 4.3% 47.9% 12 4.3% 0x000000010d721de8 ...
运行该命令(不需要任何先前步骤)会得到以下信息:
[hidden]$ pprof --text ./a.out cpu.profile
Using remote profile at ./a.out.
Failed to get the number of symbols from http://cpu.profile/pprof/symbol
为什么它试图访问我机器上的互联网网站和他/她的本地文件?
尝试将lib profiler链接为与g++的试运行让我头疼:
[hidden]$ g++ -l libprofiler
ld: library not found for -llibprofiler
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我看过手册页、帮助选项文本、官方在线指南、博客文章和许多其他来源。
我现在很困惑。有人能帮我使用gperftools吗?
我与@osgx对话的结果是这个脚本。我试着把它清理一下。它可能也包含了不少不必要的选项
博客文章https://dudefrommangalore.wordpress.com/2012/02/09/profiling-c-code-using-google-performance-tools/dudefcommangalore 2012年的"使用谷歌性能工具评测C++代码"错过了关键一步。
您应该链接您的程序(您希望对其进行评测)与gperftools库的cpu评测器库。
查看官方手册:http://goog-perftools.sourceforge.net/doc/cpu_profiler.html,部分"图书馆链接">
将
-lprofiler
添加到可执行文件的链接时间步长中。(也可能在运行时使用LD_PRELOAD
添加探查器,但不一定推荐这样做。)
第二步是收集概要文件,在启用概要文件的情况下运行代码。在linux世界中,这是通过在运行之前设置控制环境变量CPUPROFILE
来完成的:
CPUPROFILE=name_of_profile ./program_to_be_profiled
第三步是使用pprof
(ubuntu世界中的google-pprof
)。检查是否没有生成空的name_of_profile
配置文件;如果没有这样的文件,pprof将尝试进行远程概要文件提取(您可以看到这样的尝试的输出)。
pprof ./program_to_be_profiled name_of_profile
首先,您需要在启用评测的情况下运行程序。
这通常是首先用libprofiler链接程序,然后用CPUPROFILE=cpu.profile运行它
即
$CPUPROFILE=cpu.profile my_program
我认为后面的步骤是你一直错过的。
程序将在退出时创建此cpu.profile文件。然后你可以在上面使用pprof(最好来自github.com/google/prof)来可视化/分析。
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 如何重构类层次结构以避免菱形问题
- 基于boost的程序的静态链接——zlib问题
- C++格式化输出问题
- 在Mac OS X上使用gperftools的问题