Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I haven't used gprof in a long time, but is -pg even a valid argument to <code>ar</code>? Does profiling work if you compile all of the objects with -pg, then create your archive without -pg? </p> <p>If you can't get gprof to work, <a href="http://code.google.com/p/gperftools/" rel="nofollow">gperftools</a> contains a CPU profiler which I think should work very well in this case. You don't need to compile your application with any special flags, and you don't need to try to change how your static library is linked.</p> <p>Before starting, there are two tradeoffs involved with using gperftools that you should be aware of:</p> <ul> <li>gperftools is a sampling profiler. As such, your results won't be 100% accurate, but they should be really good. The big upside to using a sampling profiler is that it won't really slow your application down.</li> <li>In multithreaded applications, in my experience, gperftools will only profile the main thread. The only way I've been able to successfully profile worker threads is by adding profiling code to my application. With that said, profiling the main thread shouldn't require any code changes.</li> </ul> <p>There are lots of different ways to use gperftools. My preferred way is to load the gperftools library with <code>$LD_PRELOAD</code>, specify a logging destination with <code>$CPUPROFILE</code>, and maybe bump up the sample frequency with <code>$CPUPROFILE_FREQUENCY</code> before starting my application up. Something like this:</p> <pre><code> export LD_PRELOAD=/usr/lib/libprofiler.so export CPUPROFILE=/tmp/prof.out export CPUPROFILE_FREQUENCY=10000 ./my_application </code></pre> <p>This will write a bunch of profiling information to /tmp/prof.out. You can run a post-processing script to convert this file into something human readable. There are lots of <a href="http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html" rel="nofollow">supported output formats</a> -- my preferred one is callgrind:</p> <pre><code>google-pprof --callgrind /path/to/my_application /tmp/prof.out &gt; callgrind.dat kcachegrind callgrind.dat &amp; </code></pre> <p>This should provide a nice view of where your program is spending its time.</p> <p>If you're interested, I spent some time over the weekend learning how to use gperftools to profile I/O bound applications, and I documented a lot of my findings <a href="http://jsaxton.com/profiling-io-bound-applications/" rel="nofollow">here</a>. There's a lot of overlap with what you're trying to do, so maybe it will be helpful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload