首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将pprof与gperftools一起使用会导致卷曲错误。

将pprof与gperftools一起使用会导致卷曲错误。
EN

Stack Overflow用户
提问于 2014-10-29 17:07:09
回答 1查看 4.4K关注 0票数 12

因此,我一直在做以下工作:

代码语言:javascript
复制
$ 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并没有真正的信息,但我也知道它不应该给我一个关于卷曲的错误,在这种情况下,它应该是其他的东西。我在这里做错什么了?

我还尝试对我创建的一个示例程序(例如:pprof --callgrind /home/user/csteifel/testing2/X86_64_DEBUG/el6/wtf ~/testing2/prof.out > callgrind.out和我得到一个类似的错误)这样做:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2014-11-11 04:14:17

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

代码语言:javascript
复制
-Wl,--no-as-needed -lprofiler -Wl,--as-needed

您可以阅读更多关于它的here

一个更彻底的答案,并暗示其他潜在的问题:

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

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

  1. 将环境变量CPUPROFILE定义为要将概要文件转储到的文件名。例如,要分析/usr/local/bin/my_binary_compiled_with_libprofiler_so %=/tmp/mybin.prof /usr/local/bin/my_binary_compiled_with_libprofiler_so
  2. 在您的代码中,对您希望在调用ProfilerStart()和ProfilerStop()中进行描述的代码进行括号。(这些函数在.中声明)ProfilerStart()将使用概要文件名作为参数。

如果您这样做了,使用库编译ls,每次运行它时,您都会看到如下所示

代码语言:javascript
复制
% ls -la ~
% <output>
% PROFILE: interrupts/evictions/bytes = 204/0/256

这意味着概要文件已经生成,现在您可以用

代码语言:javascript
复制
% pprof binary_compiled_with_lprofiler profile_file
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26636570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档