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

cst*_*fel 6 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
Run Code Online (Sandbox Code Playgroud)

我不确定这里是什么,因为这是他们在这里展示的一个例子: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
Run Code Online (Sandbox Code Playgroud)

rus*_*ool 7

我刚刚遇到同样的问题,以为我会回答你的问题:

gcc查找一个名为的本地文件-Wl,--no-as-needed,其中包含有关各种组件运行时的信息pprof(这就是为什么用-g标志编译有问题的程序,以便它可以看到符号).

现在,为什么文件不存在?因为它还没有生成!你ls.prof还没有用/bin/ls旗帜编译.如果是,并且您通过文档中列出的两种方法之一激活了库:

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

    -Wl,--no-as-needed -lprofiler -Wl,--as-needed
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在您的代码中,将您想要的代码括在调用ProfilerStart()和ProfilerStop()中.(这些函数在声明中.)ProfilerStart()将profile-filename作为参数.

如果您-g使用库中的任何一个编译,每次运行它时都会看到类似的东西

% env CPUPROFILE=/tmp/mybin.prof /usr/local/bin/my_binary_compiled_with_libprofiler_so
Run Code Online (Sandbox Code Playgroud)

这意味着已经生成了配置文件,现在您可以使用它来查看它

% ls -la ~
% <output>
% PROFILE: interrupts/evictions/bytes = 204/0/256
Run Code Online (Sandbox Code Playgroud)

有一点需要注意,这是非常重要的,以及为什么我遇到这样的麻烦.如果您选择使用环境变量运行探查器的方法1,则/bin/ls默认情况下只会忽略您的链接,因为您没有使用该库中的任何符号.您需要将其包含在-lprofiler标志中,如下所示:

% pprof binary_compiled_with_lprofiler profile_file
Run Code Online (Sandbox Code Playgroud)

你可以在这里阅读更多相关信息.