2014-10-29 114 views
4

所以我一直在做以下幾點:使用pprof與導致捲曲錯誤gperftools

$ 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 

我不知道這到底是怎麼goign上,因爲這是一個例子,他們在這裏展示: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,我得到類似的錯誤:

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 

回答

5

我只是運行到同一個問題,以爲我會回答你問題:

pprof查找名爲ls.prof本地文件,其中包含有關的/bin/ls各種組件(這就是爲什麼你在問題與-g標誌編譯程序,以便它可以看到符號)的運行信息。

現在,該文件爲什麼不在那裏?因爲它還沒有生成!您的/bin/ls尚未與-lprofiler標誌一起編譯。如果它已經和您的文檔中列出的兩種方法之一激活庫:

  1. Define the environment variable CPUPROFILE to the filename to dump the profile to. For instance, to profile /usr/local/bin/my_binary_compiled_with_libprofiler_so

    % env CPUPROFILE=/tmp/mybin.prof /usr/local/bin/my_binary_compiled_with_libprofiler_so 
    
  2. In your code, bracket the code you want profiled in calls to ProfilerStart() and ProfilerStop(). (These functions are declared in .) ProfilerStart() will take the profile-filename as an argument.

如果你做這類原因,與庫編譯ls,每次運行它的時候,你會看到像

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

這意味着配置文件已經生成了,你現在可以看看它與

% pprof binary_compiled_with_lprofiler profile_file 

有一點要注意,這是超重要,爲什麼我有這樣的麻煩。如果選擇使用環境變量運行Profiler的方法1,默認情況下,gcc只會忽略鏈接,因爲您沒有使用該庫中的任何符號。你需要與-Wl,--no-as-needed標誌,包括它像這樣:

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

你可以閱讀更多關於它here