Node:Profiling, Next:Autoconf, Previous:Debugging, Up:GMP Basics
Running a program under a profiler is a good way to find where it's spending most time and where improvements can be best sought.
Depending on the system, it may be possible to get a flat profile, meaning
simple timer sampling of the program counter, with no special GMP build
options, just a -p
when compiling the mainline. This is a good way to
ensure minimum interference with normal operation. The necessary symbol type
and size information exists in most of the GMP assembler code.
The --enable-profiling
build option can be used to add suitable
compiler flags, either for prof
(-p
) or gprof
(-pg
), see Build Options. Which of the two is available and what
they do will depend on the system, and possibly on support available in
libc
. For some systems appropriate corresponding mcount
calls
are added to the assembler code too.
On x86 systems prof
gives call counting, so that average time spent
in a function can be determined. gprof
, where supported, adds call
graph construction, so for instance calls to mpn_add_n
from
mpz_add
and from mpz_mul
can be differentiated.
On x86 and 68k systems -pg
and -fomit-frame-pointer
are
incompatible, so the latter is not used when gprof
profiling is
selected, which may result in poorer code generation. If prof
profiling is selected instead it should still be possible to use
gprof
, but only the gprof -p
flat profile and call counts can
be expected to be valid, not the gprof -q
call graph.