使用gperftools进行pprof分析导致curl错误

12

我一直在做以下工作:

$ 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个回答

11

快速答案(以及解决我的问题的方法): 如果您选择使用环境变量运行分析器的方法1,gcc默认会忽略您的链接,因为您没有使用该库中的任何符号。您需要使用-Wl,--no-as-needed标志将其包含进来:

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

您可以在这里阅读更多相关信息。


对于其他可能存在的问题,以下是更详细的解答:

pprof 会查找一个名为 ls.prof 的本地文件,其中包含有关 /bin/ls 各个组件运行时的信息(这就是为什么要使用 -g 标志编译程序,以便它能看到符号)。

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

  1. 将环境变量 CPUPROFILE 定义为要转储概要文件的文件名。例如,要对 /usr/local/bin/my_binary_compiled_with_libprofiler_so 进行概要文件,请运行:

    % env CPUPROFILE=/tmp/mybin.prof /usr/local/bin/my_binary_compiled_with_libprofiler_so
    
  2. 在你的代码中,使用 ProfilerStart() 和 ProfilerStop() 函数调用来标记希望进行性能分析的代码块。(这些函数定义在 <gperftools/profiler.h> 中)。ProfilerStart() 函数将接受一个参数作为性能分析结果的文件名。

如果你按照上述步骤编译了ls并且链接了相应库,在每次运行时你会看到如下内容:

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

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

% pprof binary_compiled_with_lprofiler profile_file

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接