使用pprof和gperftools会导致卷曲错误

时间:2014-10-29 17:07:10

标签: profiling gperftools pprof

所以我一直在做以下事情:

$ pprof /bin/ls ls.prof
Using local file /bin/ls.
Gathering CPU profile from http://ls.prof/pprof/profile?seconds=30 for 30 seconds to
  /home/user/csteifel/pprof/ls.1414597606.ls.prof
Be patient...

curl: (7) couldn't connect to host
Failed to get profile: curl 'http://ls.prof/pprof/profile?seconds=30' > /home/user/csteifel/pprof/.tmp.ls.1414597606.ls.prof: No such file or directory

我不确定这里是什么,因为这是他们在这里展示的一个例子:http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html

现在我明白ls实际上并没有信息,但我也知道它不应该给我一个关于curl的错误,在这种情况下它应该是别的东西。我在这里做错了什么?

我也尝试过这样做我创建的示例程序(例如:pprof --callgrind /home/user/csteifel/testing2/X86_64_DEBUG/el6/wtf ~/testing2/prof.out > callgrind.out,我得到了类似的错误:

Using local file /home/user/csteifel/testing2/X86_64_DEBUG/el6/wtf.
Use of uninitialized value $host in substitution (s///) at /home/user/csteifel/usr/local/lib/bin/pprof line 3195.
Use of uninitialized value $hostport in concatenation (.) or string at /home/user/csteifel/usr/local/lib/bin/pprof line 3197.
Use of uninitialized value $prefix in concatenation (.) or string at /home/user/csteifel/usr/local/lib/bin/pprof line 3197.
Use of uninitialized value $host in substitution (s///) at /home/user/csteifel/usr/local/lib/bin/pprof line 3195.
Use of uninitialized value $hostport in concatenation (.) or string at /home/user/csteifel/usr/local/lib/bin/pprof line 3197.
Use of uninitialized value $prefix in concatenation (.) or string at /home/user/csteifel/usr/local/lib/bin/pprof line 3197.
Use of uninitialized value $host in sprintf at /home/user/csteifel/usr/local/lib/bin/pprof line 3364.
Gathering CPU profile from http:///pprof/profile?seconds=30 for 30 seconds to
  /home/user/csteifel/pprof/wtf.1414597016.
Be patient...

curl: (6) Couldn't resolve host 'http:'
Failed to get profile: curl 'http:///pprof/profile?seconds=30' > /home/user/csteifel/pprof/.tmp.wtf.1414597016.: No such file or directory

1 个答案:

答案 0 :(得分:7)

快速回答(以及解决我的问题): 如果选择使用环境变量运行探查器的方法1,默认情况下gcc会忽略您的链接,因为您不使用该库中的任何符号。您需要将-Wl,--no-as-needed标志包含在内,如下所示:

-Wl,--no-as-needed -lprofiler -Wl,--as-needed

您可以详细了解here


有关其他潜在问题的提示的更全面的答案:

pprof查找名为ls.prof的本地文件,其中包含有关/bin/ls各种组件的运行时的信息(这就是为什么用{{1}编译有问题的程序的原因标志,以便它可以看到符号)。

现在,为什么文件不存在?因为它还没有生成!您的-g尚未使用/bin/ls标记进行编译。如果已经存在,并且您通过文档中列出的两种方法之一激活了库:

  
      
  1. 将环境变量CPUPROFILE定义为要将配置文件转储到的文件名。例如,要分析/ usr / local / bin / my_binary_compiled_with_libprofiler_so

    -lprofiler
  2.   
  3. 在您的代码中,将您想要的代码括在调用ProfilerStart()和ProfilerStop()中。 (这些函数在声明中。)ProfilerStart()将profile-filename作为参数。

  4.   

如果你做了其中任何一个,用库编译% env CPUPROFILE=/tmp/mybin.prof /usr/local/bin/my_binary_compiled_with_libprofiler_so ,每次运行它都会看到像

这样的东西
ls

这意味着已生成配置文件,现在您可以使用

查看它
% ls -la ~
% <output>
% PROFILE: interrupts/evictions/bytes = 204/0/256