HP-UX Reference (11i v1 05/09) - 1 User Commands A-M (vol 1)

g
gprof(1) gprof(1)
EXAMPLES
To profile a.out and libtest.so
on Itanium-based systems:
$ cat > test.c
void a()
{
printf("I in a\n");
}
$ cc -c +Z -G test.c
$ ld -b -o libtest.so.1 test.o
$ ln -s ./libtest.so.1 libtest.so
$ cat > main.c
extern void a();
main()
{
printf("Hello world\n");
a();
}
$ cc -G main.c -L. -ltest
$ export LD_PROFILE=a.out:libtest.so
$ export LD_PROFILEBUCKET_SIZE=16
$ ./a.out
hello world
Iina
$ unset LD_PROFILE
$ unset LD_PROFILEBUCKET_SIZE
$ ls gmon.out
gmon.out
$ gprof
To profile
libc.sl on PA-RISC systems:
$ cat > test.c
main()
{
printf("hello world\n");
}
$ cc test.c -lc
$ ldd a.out
/usr/lib/libc.2 => /usr/lib/libc.2
/usr/lib/libdld.2 => /usr/lib/libdld.2
/usr/lib/libc.2 => /usr/lib/libc.2
$ export LD_PROFILE=/usr/lib/libc.2
$ ./a.out
hello world
$ unset LD_PROFILE
$ ls libc.2.profile
libc.2.profile
$ gprof /usr/lib/libc.2 libc.2.profile
WARNINGS
Beware of quantization errors. The granularity of the sampling is shown, but remains statistical at best. It
is assumed that the time for each execution of a function can be expressed by the total time for the func-
tion, divided by the number of times the function is called. Thus the time propagated along the call graph
arcs to parents of that function is directly proportional to the number of times that arc is traversed.
HP-UX 11i Version 1: September 2005 3 Hewlett-Packard Company Section 1349