390 lines
11 KiB
HTML
390 lines
11 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of SPROF</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>SPROF</H1>
|
|
Section: Linux User Manual (1)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
sprof - read and display shared object profiling data
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>sprof</B> [<I>option</I>]... <I>shared-object-path</I> [<I>profile-data-path</I>]
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>sprof</B>
|
|
|
|
command displays a profiling summary for the
|
|
shared object (shared library) specified as its first command-line argument.
|
|
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</B>
|
|
|
|
will attempt to deduce it using the soname of the shared object,
|
|
looking for a file with the name
|
|
<I><soname>.profile</I>
|
|
|
|
in the current directory.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>OPTIONS</H2>
|
|
|
|
The following command-line options specify the profile output
|
|
to be produced:
|
|
<DL COMPACT>
|
|
<DT id="1"><B>-c</B>, <B>--call-pairs</B>
|
|
|
|
<DD>
|
|
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.
|
|
<DT id="2"><B>-p</B>, <B>--flat-profile</B>
|
|
|
|
<DD>
|
|
Generate a flat profile of all of the functions in the monitored object,
|
|
with counts and ticks.
|
|
<DT id="3"><B>-q</B>, <B>--graph</B>
|
|
|
|
<DD>
|
|
Generate a call graph.
|
|
</DL>
|
|
<P>
|
|
|
|
If none of the above options is specified,
|
|
then the default behavior is to display a flat profile and a call graph.
|
|
<P>
|
|
|
|
The following additional command-line options are available:
|
|
<DL COMPACT>
|
|
<DT id="4"><B>-?</B>, <B>--help</B>
|
|
|
|
<DD>
|
|
Display a summary of command-line options and arguments and exit.
|
|
<DT id="5"><B>--usage</B>
|
|
|
|
<DD>
|
|
Display a short usage message and exit.
|
|
<DT id="6"><B>-V</B>, <B>--version</B>
|
|
|
|
<DD>
|
|
Display the program version and exit.
|
|
</DL>
|
|
<A NAME="lbAF"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
The
|
|
<B>sprof</B>
|
|
|
|
command is a GNU extension, not present in POSIX.1.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
The following example demonstrates the use of
|
|
<B>sprof</B>.
|
|
|
|
The example consists of a main program that calls two functions
|
|
in a shared object.
|
|
First, the code of the main program:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>cat prog.c</B>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
<P>
|
|
void x1(void);
|
|
void x2(void);
|
|
<P>
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
<BR> x1();
|
|
<BR> x2();
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
|
|
<P>
|
|
|
|
The functions
|
|
<I>x1</I>()
|
|
|
|
and
|
|
<I>x2</I>()
|
|
|
|
are defined in the following source file that is used to
|
|
construct the shared object:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>cat libdemo.c</B>
|
|
#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>>
|
|
<P>
|
|
void
|
|
consumeCpu1(int lim)
|
|
{
|
|
<BR> int j;
|
|
<P>
|
|
<BR> for (j = 0; j < lim; j++)
|
|
<TT> </TT>getppid();<BR>
|
|
}
|
|
<P>
|
|
void
|
|
x1(void) {
|
|
<BR> int j;
|
|
<P>
|
|
<BR> for (j = 0; j < 100; j++)
|
|
<TT> </TT>consumeCpu1(200000);<BR>
|
|
}
|
|
<P>
|
|
void
|
|
consumeCpu2(int lim)
|
|
{
|
|
<BR> int j;
|
|
<P>
|
|
<BR> for (j = 0; j < lim; j++)
|
|
<TT> </TT>getppid();<BR>
|
|
}
|
|
<P>
|
|
void
|
|
x2(void)
|
|
{
|
|
<BR> int j;
|
|
<P>
|
|
<BR> for (j = 0; j < 1000; j++)
|
|
<TT> </TT>consumeCpu2(10000);<BR>
|
|
}
|
|
|
|
|
|
<P>
|
|
|
|
Now we construct the shared object with the real name
|
|
<I>libdemo.so.1.0.1</I>,
|
|
|
|
and the soname
|
|
<I>libdemo.so.1</I>:
|
|
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>cc -g -fPIC -shared -Wl,-soname,libdemo.so.1 \</B>
|
|
<BR> <B>-o libdemo.so.1.0.1 libdemo.c</B>
|
|
|
|
|
|
<P>
|
|
|
|
Then we construct symbolic links for the library soname and
|
|
the library linker name:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>ln -sf libdemo.so.1.0.1 libdemo.so.1</B>
|
|
$ <B>ln -sf libdemo.so.1 libdemo.so</B>
|
|
|
|
|
|
<P>
|
|
|
|
Next, we compile the main program, linking it against the shared object,
|
|
and then list the dynamic dependencies of the program:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>cc -g -o prog prog.c -L. -ldemo</B>
|
|
$ <B>ldd prog</B>
|
|
<TT> </TT>linux-vdso.so.1 => (0x00007fff86d66000)<BR>
|
|
<TT> </TT>libdemo.so.1 => not found<BR>
|
|
<TT> </TT>libc.so.6 => /lib64/libc.so.6 (0x00007fd4dc138000)<BR>
|
|
<TT> </TT>/lib64/ld-linux-x86-64.so.2 (0x00007fd4dc51f000)<BR>
|
|
|
|
|
|
<P>
|
|
|
|
In order to get profiling information for the shared object,
|
|
we define the environment variable
|
|
<B>LD_PROFILE</B>
|
|
|
|
with the soname of the library:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>export LD_PROFILE=libdemo.so.1</B>
|
|
|
|
|
|
<P>
|
|
|
|
We then define the environment variable
|
|
<B>LD_PROFILE_OUTPUT</B>
|
|
|
|
with the pathname of the directory where profile output should be written,
|
|
and create that directory if it does not exist already:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>export LD_PROFILE_OUTPUT=$(pwd)/prof_data</B>
|
|
$ <B>mkdir -p $LD_PROFILE_OUTPUT</B>
|
|
|
|
|
|
<P>
|
|
|
|
<B>LD_PROFILE</B>
|
|
|
|
causes profiling output to be
|
|
<I>appended</I>
|
|
|
|
to the output file if it already exists,
|
|
so we ensure that there is no preexisting profiling data:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>rm -f $LD_PROFILE_OUTPUT/$LD_PROFILE.profile</B>
|
|
|
|
|
|
<P>
|
|
|
|
We then run the program to produce the profiling output,
|
|
which is written to a file in the directory specified in
|
|
<B>LD_PROFILE_OUTPUT</B>:
|
|
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>LD_LIBRARY_PATH=. ./prog</B>
|
|
$ <B>ls prof_data</B>
|
|
libdemo.so.1.profile
|
|
|
|
|
|
<P>
|
|
|
|
We then use the
|
|
<B>sprof -p</B>
|
|
|
|
option to generate a flat profile with counts and ticks:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>sprof -p libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile</B>
|
|
Flat profile:
|
|
<P>
|
|
Each sample counts as 0.01 seconds.
|
|
<BR> % cumulative self self total
|
|
<BR> time seconds seconds calls us/call us/call name
|
|
<BR> 60.00 0.06 0.06 100 600.00 consumeCpu1
|
|
<BR> 40.00 0.10 0.04 1000 40.00 consumeCpu2
|
|
<BR> 0.00 0.10 0.00 1 0.00 x1
|
|
<BR> 0.00 0.10 0.00 1 0.00 x2
|
|
|
|
|
|
<P>
|
|
|
|
The
|
|
<B>sprof -q</B>
|
|
|
|
option generates a call graph:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>sprof -q libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile</B>
|
|
<P>
|
|
index % time self children called name
|
|
<P>
|
|
<BR> 0.00 0.00 100/100 x1 [1]
|
|
[0] 100.0 0.00 0.00 100 consumeCpu1 [0]
|
|
-----------------------------------------------
|
|
<BR> 0.00 0.00 1/1 <UNKNOWN>
|
|
[1] 0.0 0.00 0.00 1 x1 [1]
|
|
<BR> 0.00 0.00 100/100 consumeCpu1 [0]
|
|
-----------------------------------------------
|
|
<BR> 0.00 0.00 1000/1000 x2 [3]
|
|
[2] 0.0 0.00 0.00 1000 consumeCpu2 [2]
|
|
-----------------------------------------------
|
|
<BR> 0.00 0.00 1/1 <UNKNOWN>
|
|
[3] 0.0 0.00 0.00 1 x2 [3]
|
|
<BR> 0.00 0.00 1000/1000 consumeCpu2 [2]
|
|
-----------------------------------------------
|
|
|
|
|
|
<P>
|
|
|
|
Above and below, the "<UNKNOWN>" strings represent identifiers that
|
|
are outside of the profiled object (in this example, these are instances of
|
|
<I>main()</I>).
|
|
|
|
<P>
|
|
|
|
The
|
|
<B>sprof -c</B>
|
|
|
|
option generates a list of call pairs and the number of their occurrences:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>sprof -c libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile</B>
|
|
<UNKNOWN> x1 1
|
|
x1 consumeCpu1 100
|
|
<UNKNOWN> x2 1
|
|
x2 consumeCpu2 1000
|
|
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+gprof">gprof</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+ldd">ldd</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+ld.so">ld.so</A></B>(8)
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="7"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="8"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="9"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="10"><A HREF="#lbAE">OPTIONS</A><DD>
|
|
<DT id="11"><A HREF="#lbAF">CONFORMING TO</A><DD>
|
|
<DT id="12"><A HREF="#lbAG">EXAMPLE</A><DD>
|
|
<DT id="13"><A HREF="#lbAH">SEE ALSO</A><DD>
|
|
<DT id="14"><A HREF="#lbAI">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:27 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|