gperftools与CPUPROFILE_FREQUENCY不一致

gperftools inexactitudes with CPUPROFILE_FREQUENCY

本文关键字:FREQUENCY 不一致 CPUPROFILE gperftools      更新时间:2023-10-16

我有一个任务似乎无法使用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在这里被记录为默认值100,并且是cpu探查器采样的每秒中断次数。我对在7秒的模拟程序中将其设置为50只进行了14次采样感到疏远,而将其设置为50000只进行了80次采样。

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

您的程序只有0.008s到0.048s的用户执行时间。探查器只评测在用户空间中执行的时间,所以我认为您的结果是意料之中的。

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