c++ - gperftools 与 CPUPROFILE_FREQUENCY 不准确

标签 c++ c gcc profiling gperftools

我有一个任务 gprof 似乎无法使用。 Callgrind 在这里提供了很多帮助,但是当找到更像 gprof 的解决方案时,我。例如,gperftools,深入其中进行尝试。

所以我写了一个虚拟程序并做了几次这样的试验:

0:10:1386682334:user@host:~$ time gcc test.c -o test -lprofiler -Lgperftools-2.
1/.libs/ -g

real    0m0.085s
user    0m0.048s
sys     0m0.032s
0:11:1386682357:user@host:~$ time CPUPROFILE_FREQUENCY=50 CPUPROFILE=~
/test_profile LD_LIBRARY_PATH=~/gperftools-2.1/.libs/ ./test && ~/gperftools-2.
1/src/pprof test test_profile --text

PROFILE: interrupts/evictions/bytes = 14/0/216

real    0m7.157s
user    0m0.008s
sys     0m0.672s
Using local file test.
Using local file test_profile.
Removing killpg from all stack traces.
Removing do_system from all stack traces.
Total: 14 samples
      14 100.0% 100.0%       14 100.0% do_system
       0   0.0% 100.0%       14 100.0% __libc_start_main
       0   0.0% 100.0%       14 100.0% _start
       0   0.0% 100.0%        2  14.3% bar
       0   0.0% 100.0%       14 100.0% foo
       0   0.0% 100.0%       14 100.0% main
0:12:1386682465:user@host:~$ time CPUPROFILE_FREQUENCY=50000 CPUPROFIL
E=~/test_profile LD_LIBRARY_PATH=~/gperftools-2.1/.libs/ ./test && ~/gperftools
-2.1/src/pprof test test_profile --text

PROFILE: interrupts/evictions/bytes = 80/0/520

real    0m7.199s
user    0m0.016s
sys     0m0.704s
Using local file test.
Using local file test_profile.
Removing killpg from all stack traces.
Total: 80 samples
      78  97.5%  97.5%       79  98.8% do_system
       1   1.2%  98.8%        1   1.2% __find_specmb
       1   1.2% 100.0%        1   1.2% __libc_waitpid
       0   0.0% 100.0%        1   1.2% _IO_vfprintf_internal
       0   0.0% 100.0%       80 100.0% __libc_start_main
       0   0.0% 100.0%        1   1.2% __printf
       0   0.0% 100.0%       80 100.0% _start
       0   0.0% 100.0%       27  33.8% bar
       0   0.0% 100.0%       79  98.8% foo
       0   0.0% 100.0%       80 100.0% main

CPUPROFILE_FREQUENCY 已记录 here默认为 100 并且 cpu-profiler 采样的中断数/秒。我对将它设置为 50 在 7 秒的虚拟程序中仅采样 14 次,而将其设置为 50000 仅采样 80 次感到陌生。

我想知道在需要时是否可以通过这个简单的环境更改获得更高的精度,以及 gperftools 中的 CPUPROFILE_FREQUENCY 是否被破坏。

最佳答案

您的程序只有 0.008 秒到 0.048 秒的用户执行时间。分析器仅分析用户空间执行所花费的时间,因此我认为您的结果是预期的。

尝试运行一个花费 7 秒进行实际计算的虚拟程序。例如,计算阿克曼函数。

关于c++ - gperftools 与 CPUPROFILE_FREQUENCY 不准确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20496365/

相关文章:

c - 使用 libevent 监控 couchbase 存储桶

c - 如何在不同的行中输入字符串?

c - 在旧 C 中使用前声明变量

c++ - 从文件 (C++) 中读取函数(和 "create")

c++ - SSE 内在函数导致正常的浮点运算返回 -1.#INV

c++ - 更好地理解 boost 的聊天客户端示例

c++ - 这两者中哪一个是实现 header 的正确方法?

c++ - 如何从 SQLite 数据库中读取数据?

c - 为什么将 double 赋值给 int 不会触发 gcc 警告?

gcc - GPU编程?