2014-06-10 14:38:26 +00:00
|
|
|
.\" Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com>
|
|
|
|
.\"
|
|
|
|
.\" %%%LICENSE_START(VERBATIM)
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
|
|
|
.\"
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
|
|
|
.\"
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\" %%%LICENSE_END
|
|
|
|
.\"
|
ldd.1, sprof.1, accept.2, alarm.2, bind.2, chdir.2, clock_nanosleep.2, close.2, connect.2, dup.2, execve.2, fsync.2, getgid.2, getpeername.2, getsid.2, getsockname.2, getsockopt.2, getuid.2, io_getevents.2, kill.2, listen.2, lseek.2, mmap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nice.2, pause.2, pipe.2, rmdir.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, select_tut.2, semctl.2, semop.2, setsid.2, shmctl.2, shmget.2, shmop.2, shutdown.2, sigaction.2, signal.2, socketpair.2, sync.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, times.2, truncate.2, umask.2, MB_CUR_MAX.3, a64l.3, abs.3, assert.3, atexit.3, atof.3, atoi.3, basename.3, bsearch.3, btowc.3, byteorder.3, catgets.3, catopen.3, clock.3, clock_getcpuclockid.3, closedir.3, confstr.3, crypt.3, ctermid.3, difftime.3, div.3, dladdr.3, dlerror.3, dlinfo.3, dlopen.3, dlsym.3, drand48.3, encrypt.3, exit.3, fclose.3, ffs.3, fgetc.3, fgetwc.3, fgetws.3, flockfile.3, fmtmsg.3, fnmatch.3, fopen.3, fpathconf.3, fpclassify.3, fputwc.3, fputws.3, fseek.3, fseeko.3, ftok.3, fwide.3, getdate.3, getenv.3, getgrent.3, getgrnam.3, gethostid.3, getlogin.3, getnetent.3, getopt.3, getpwent.3, getpwnam.3, getsubopt.3, getutent.3, getwchar.3, grantpt.3, hsearch.3, iconv.3, iconv_close.3, iconv_open.3, if_nameindex.3, inet.3, inet_ntop.3, inet_pton.3, insque.3, isatty.3, isgreater.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, lockf.3, longjmp.3, lsearch.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, memccpy.3, memchr.3, memcmp.3, memmove.3, memset.3, mktemp.3, mq_close.3, mq_getattr.3, mq_receive.3, mq_send.3, mq_unlink.3, offsetof.3, popen.3, posix_memalign.3, posix_openpt.3, printf.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstacksize.3, pthread_equal.3, pthread_exit.3, pthread_getcpuclockid.3, pthread_kill.3, pthread_self.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, pthread_sigmask.3, pthread_testcancel.3, ptsname.3, putenv.3, puts.3, putwchar.3, qsort.3, raise.3, random.3, readdir.3, regex.3, remove.3, rewinddir.3, seekdir.3, sem_destroy.3, sem_getvalue.3, sem_unlink.3, sem_wait.3, setenv.3, setjmp.3, setlocale.3, setlogmask.3, signbit.3, sigpause.3, sigset.3, sigsetops.3, sigwait.3, sleep.3, sockatmark.3, statvfs.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strlen.3, strpbrk.3, strptime.3, strspn.3, strstr.3, strtod.3, strtoimax.3, strtok.3, strtol.3, strtoul.3, strxfrm.3, swab.3, sysconf.3, system.3, tcgetpgrp.3, tcgetsid.3, telldir.3, tmpfile.3, towctrans.3, tsearch.3, ttyname.3, tzset.3, ungetwc.3, unlocked_stdio.3, unlockpt.3, wcrtomb.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstoimax.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wordexp.3, wprintf.3, fanotify.7, mq_overview.7, nptl.7, sem_overview.7, shm_overview.7, sigevent.7, symlink.7, ld.so.8: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2015-08-08 16:21:22 +00:00
|
|
|
.TH SPROF 1 2015-08-08 "Linux" "Linux User Manual"
|
2014-06-10 14:38:26 +00:00
|
|
|
.SH NAME
|
|
|
|
sprof \- read and display shared object profiling data
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
2014-08-30 13:45:00 +00:00
|
|
|
.BR sprof " [\fIoption\fP]... \fIshared-object-path\fP \
|
|
|
|
[\fIprofile-data-path\fP]"
|
2014-06-10 14:38:26 +00:00
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
|
|
|
The
|
|
|
|
.B sprof
|
|
|
|
command displays a profiling summary for the
|
2015-07-10 18:37:59 +00:00
|
|
|
shared object (shared library) specified as its first command-line argument.
|
2014-06-10 14:38:26 +00:00
|
|
|
The profiling summary is created using previously generated
|
|
|
|
profiling data in the (optional) second command-line argument.
|
|
|
|
If the profiling data pathname is omitted, then
|
|
|
|
.B sprof
|
|
|
|
will attempt to deduce it using the soname of the shared object,
|
|
|
|
looking for a file with the name
|
|
|
|
.IR <soname>.profile
|
|
|
|
in the current directory.
|
|
|
|
.SH OPTIONS
|
|
|
|
The following command-line options specify the profile output
|
|
|
|
to be produced:
|
|
|
|
.TP
|
|
|
|
.BR \-c ", " \-\-call\-pairs
|
|
|
|
Print a list of pairs of call paths for the interfaces exported
|
|
|
|
by the shared object,
|
|
|
|
along with the number of times each path is used.
|
|
|
|
.TP
|
|
|
|
.BR \-p ", " \-\-flat\-profile
|
|
|
|
Generate a flat profile of all of the functions in the monitored object,
|
|
|
|
with counts and ticks.
|
|
|
|
.TP
|
|
|
|
.BR \-q ", " \-\-graph
|
|
|
|
Generate a call graph.
|
|
|
|
.PP
|
|
|
|
If none of the above options is specified,
|
|
|
|
then the default behavior is to display a flat profile and a call graph.
|
|
|
|
.PP
|
|
|
|
The following additional command-line options are available:
|
|
|
|
.TP
|
|
|
|
.BR \-? ", " \-\-help
|
|
|
|
Display a summary of command-line options and arguments and exit.
|
|
|
|
.TP
|
|
|
|
.BR \-\-usage
|
|
|
|
Display a short usage message and exit.
|
|
|
|
.TP
|
|
|
|
.BR \-V ", " \-\-version
|
|
|
|
Display the program version and exit.
|
|
|
|
.SH CONFORMING TO
|
|
|
|
The
|
|
|
|
.B sprof
|
|
|
|
command is a GNU extension, not present in POSIX.1.
|
|
|
|
.SH EXAMPLE
|
|
|
|
The following example demonstrates the use of
|
|
|
|
.BR sprof .
|
|
|
|
The example consists of a main program that calls two functions
|
2015-07-10 18:37:59 +00:00
|
|
|
in a shared object.
|
2014-06-10 14:38:26 +00:00
|
|
|
First, the code of the main program:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBcat prog.c\fP
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
void x1(void);
|
|
|
|
void x2(void);
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
x1();
|
|
|
|
x2();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
The functions
|
|
|
|
.IR x1()
|
|
|
|
and
|
|
|
|
.IR x2()
|
|
|
|
are defined in the following source file that is used to
|
2015-07-10 18:37:59 +00:00
|
|
|
construct the shared object:
|
2014-06-10 14:38:26 +00:00
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBcat libdemo.c\fP
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
consumeCpu1(int lim)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < lim; j++)
|
|
|
|
getppid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
x1(void) {
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < 100; j++)
|
|
|
|
consumeCpu1(200000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
consumeCpu2(int lim)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < lim; j++)
|
|
|
|
getppid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
x2(void)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < 1000; j++)
|
|
|
|
consumeCpu2(10000);
|
|
|
|
}
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
2015-07-10 18:37:59 +00:00
|
|
|
Now we construct the shared object with the real name
|
2014-06-10 14:38:26 +00:00
|
|
|
.IR libdemo.so.1.0.1 ,
|
|
|
|
and the soname
|
|
|
|
.IR libdemo.so.1 :
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBcc \-g \-fPIC \-shared \-Wl,\-soname,libdemo.so.1 \e\fP
|
|
|
|
\fB\-o libdemo.so.1.0.1 libdemo.c\fP
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
Then we construct symbolic links for the library soname and
|
|
|
|
the library linker name:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBln \-sf libdemo.so.1.0.1 libdemo.so.1\fP
|
|
|
|
$ \fBln \-sf libdemo.so.1 libdemo.so\fP
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
2015-07-10 18:37:59 +00:00
|
|
|
Next, we compile the main program, linking it against the shared object,
|
2014-06-10 14:38:26 +00:00
|
|
|
and then list the dynamic dependencies of the program:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBcc \-g \-o prog prog.c \-L. \-ldemo\fP
|
|
|
|
$ \fBldd prog\fP
|
|
|
|
linux\-vdso.so.1 => (0x00007fff86d66000)
|
|
|
|
libdemo.so.1 => not found
|
|
|
|
libc.so.6 => /lib64/libc.so.6 (0x00007fd4dc138000)
|
|
|
|
/lib64/ld\-linux\-x86\-64.so.2 (0x00007fd4dc51f000)
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
2015-07-10 18:37:59 +00:00
|
|
|
In order to get profiling information for the shared object,
|
2014-06-10 14:38:26 +00:00
|
|
|
we define the environment variable
|
|
|
|
.BR LD_PROFILE
|
|
|
|
with the soname of the library:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBexport LD_PROFILE=libdemo.so.1\fP
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
We then define the environment variable
|
|
|
|
.BR LD_PROFILE_OUTPUT
|
|
|
|
with the pathname of the directory where profile output should be written,
|
|
|
|
and create that directory if it does not exist already:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBexport LD_PROFILE_OUTPUT=$(pwd)/prof_data\fP
|
|
|
|
$ \fBmkdir \-p $LD_PROFILE_OUTPUT\fP
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
.B LD_PROFILE
|
|
|
|
causes profiling output to be
|
|
|
|
.I appended
|
|
|
|
to the output file if it already exists,
|
|
|
|
so we ensure that there is no preexisting profiling data:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBrm \-f $LD_PROFILE_OUTPUT/$LD_PROFILE.profile\fP
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
We then run the program to produce the profiling output,
|
|
|
|
which is written to a file in the directory specified in
|
|
|
|
.BR LD_PROFILE_OUTPUT :
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBLD_LIBRARY_PATH=. ./prog\fP
|
|
|
|
$ \fBls prof_data\fP
|
|
|
|
libdemo.so.1.profile
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
We then use the
|
|
|
|
.BR "sprof \-p"
|
|
|
|
option to generate a flat profile with counts and ticks:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBsprof \-p libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile\fP
|
|
|
|
Flat profile:
|
|
|
|
|
|
|
|
Each sample counts as 0.01 seconds.
|
|
|
|
% cumulative self self total
|
|
|
|
time seconds seconds calls us/call us/call name
|
|
|
|
60.00 0.06 0.06 100 600.00 consumeCpu1
|
|
|
|
40.00 0.10 0.04 1000 40.00 consumeCpu2
|
|
|
|
0.00 0.10 0.00 1 0.00 x1
|
|
|
|
0.00 0.10 0.00 1 0.00 x2
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.BR "sprof \-q"
|
|
|
|
option generates a call graph:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBsprof \-q libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile\fP
|
|
|
|
|
|
|
|
index % time self children called name
|
|
|
|
|
|
|
|
0.00 0.00 100/100 x1 [1]
|
|
|
|
[0] 100.0 0.00 0.00 100 consumeCpu1 [0]
|
|
|
|
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
|
|
|
|
0.00 0.00 1/1 <UNKNOWN>
|
|
|
|
[1] 0.0 0.00 0.00 1 x1 [1]
|
|
|
|
0.00 0.00 100/100 consumeCpu1 [0]
|
|
|
|
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
|
|
|
|
0.00 0.00 1000/1000 x2 [3]
|
|
|
|
[2] 0.0 0.00 0.00 1000 consumeCpu2 [2]
|
|
|
|
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
|
|
|
|
0.00 0.00 1/1 <UNKNOWN>
|
|
|
|
[3] 0.0 0.00 0.00 1 x2 [3]
|
|
|
|
0.00 0.00 1000/1000 consumeCpu2 [2]
|
|
|
|
\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
Above and below, the "<UNKNOWN>" strings represent identifiers that
|
|
|
|
are outside of the profiled object (in this example, these are instances of
|
|
|
|
.IR main() ).
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.BR "sprof \-c"
|
|
|
|
option generates a list of call pairs and the number of their occurrences:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ \fBsprof \-c libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile\fP
|
|
|
|
<UNKNOWN> x1 1
|
|
|
|
x1 consumeCpu1 100
|
|
|
|
<UNKNOWN> x2 1
|
|
|
|
x2 consumeCpu2 1000
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.SH SEE ALSO
|
|
|
|
.BR gprof (1),
|
|
|
|
.BR ldd (1),
|
|
|
|
.BR ld.so (8)
|