Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using pprof with gperftools resulting in curl error

So I have been doing the following:

$ 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

I'm not sure what is goign on here because this is one of the examples they show here: http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html

Now I understand ls isn't going to actually have information to it but I also know that it shouldn't be giving me an error about curl in this case it should be something else. What am I doing wrong here?

I have also tried doing this to a sample program that I created (eg: pprof --callgrind /home/user/csteifel/testing2/X86_64_DEBUG/el6/wtf ~/testing2/prof.out > callgrind.out and I get a similar error:

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
like image 837
csteifel Avatar asked Oct 29 '14 17:10

csteifel


1 Answers

Quick answer (and the fix to my problem): If you choose method 1 of running the profiler, with an environment variable, gcc by default just ignores your link, because you're not using any symbols from that library. You need to include it with the -Wl,--no-as-needed flag like so:

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

You can read more about it here.


A more thorough answer with hints for other potential problem:

pprof looks for a local file called ls.prof, which contains info about the runtime of various components of /bin/ls (this is why you compile the program in question with the -g flag, so that it can see the symbols).

Now, why is the file not there? Because it hasn't been generated! Your /bin/ls hasn't been compiled with the -lprofiler flag. If it had been, and you activated the library by one of the two ways listed in the documentation:

  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.

If you did either of those, compiled ls with the libraries, every time you run it you'll see something like

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

That means the profile file has been generated, and you can now look at it with

% pprof binary_compiled_with_lprofiler profile_file
like image 140
russianfool Avatar answered Oct 03 '22 10:10

russianfool