[Xorp-hackers] PATCH: Enable compiling with gprof support
Bruce Simpson
bms at incunabulum.net
Sat Nov 28 18:48:19 PST 2009
Hi Ben,
I'll clean up the scons build args patch and commit it separately.
Ben Greear wrote:
> Also, this allows writing config vars to a file so an external program
> (maybe a packager or installer), can use them automatically.
gprof requires that all programs are statically linked, so I'll add a
warning to that effect. The gprof style profiling will try to use
profiled versions of libc, libstdc++, etc.
When I tried running call_xrl, and other binaries, they immediately
dumped core. This was at -O1 optimization.
fnccheck, kprof etc are dead as alternatives due to bit-rot.
A better approach (and tool set) seems to be to use Valgrind's
'callgrind' tool, with KCacheGrind.
This is non-invasive at binary level, because it uses Valgrind, however
that does come with a corresponding speed penalty, due to Valgrind
emulating an x86. All of these tools have compromises -- they have to be
run or triggered somehow.
KCacheGrind can't use gprof's output, but it *can* use the Google
Performance Tools (pprof) CPU profiler output.
I've added basic support for linking against the pprof library, but it
needs to be explicitly enabled by an environment variable,
CPUPROFILE=/path/to/output, when the binaries are run, in order to get a
trace.
If the process being profiled isn't very busy, then CPUPROFILE_FREQUENCY
could get tweaked up.
Explicitly putting it into the link line is preferred to LD_PRELOAD,
because there are then stronger guarantees about when _init() and
_fini() will get called for the libprofiler.so shared library.
This method is also preferable because calling their ProfilerStart() API
function means putting their headers, calls etc into the files; it also
needs to be given an explicit file name for the profiler output data if
this approach is used.
I just tested this, and it seems to work fine, although to get source
with the profiler hits, don't forget to add the XORP svn checkout base
directory in KCacheGrind's configuration dialog.
I've committed support for gprof and pprof in SVN rev 11629.
thanks,
BMS
More information about the Xorp-hackers
mailing list