Subject: profile dynamically linked executables?
To: None <firstname.lastname@example.org>
From: Ian Dall <email@example.com>
Date: 07/13/1999 21:31:59
I wanted to figure out where a large program was spending
its time, so I compile with -pg right? Wrong!
Compiling with -pg effectively does a -static as well, but some
of the libraries are dynamically linked only. Also, the executable
manually loads modules with dlopen etc.
I was wondering what it would take to be able to profile a dynamically
linked executable. The catch seems to be the address space is extremely
large so that you need a very large buffer for profil(2).
One approach is to call profil with something like
VM_MAXUSER_ADDRESS/NBPG samples. Use the results of that run to figure
out which library is on the critical path. Recompile that with -pg
and relink. This time use standard sample buffer size.
This is clumsy though. What would it take to make a more capable profiling
method? If you could call profil(2) or something like it, for each of
the dynamically loaded modules/libraries. The main catch I see is you
need an efficient way of sticking the sampled PC in what is effectively
a sparse array. Also you would want some corresponding user land changes.