Unleashed v1.4
[unleashed.git] / share / man / man1 / prof.1
blob6c165958377c84c0e1b50da5877bc262c2244209
1 '\" te
2 .\" Copyright (c) 2009, Sun Microsystems, Inc.  All Rights Reserved
3 .\" Copyright 1989 AT&T
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
5 .\"  See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with
6 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH PROF 1 "Aug 25, 2009"
8 .SH NAME
9 prof \- display profile data
10 .SH SYNOPSIS
11 .LP
12 .nf
13 \fBprof\fR [\fB-ChsVz\fR] [\fB-a\fR | c | n | t] [\fB-o\fR | x] [\fB-g\fR | l] [\fB-m\fR \fImdata\fR]
14      [\fIprog\fR]
15 .fi
17 .SH DESCRIPTION
18 .sp
19 .LP
20 The \fBprof\fR command interprets a profile file produced by the \fBmonitor\fR
21 function.  The symbol table in the object file \fIprog\fR (\fBa.out\fR by
22 default) is read and correlated with a profile file (\fBmon.out\fR by default).
23 For each external text symbol the percentage of time spent executing between
24 the address of that symbol and the address of the next is printed, together
25 with the number of times that function was called and the average number of
26 milliseconds per call.
27 .SH OPTIONS
28 .sp
29 .LP
30 The mutually exclusive options \fB-a\fR, \fB-c\fR, \fB-n\fR, and \fB-t\fR
31 determine the type of sorting of the output lines:
32 .sp
33 .ne 2
34 .na
35 \fB\fB-a\fR\fR
36 .ad
37 .RS 6n
38 Sort by increasing symbol address.
39 .RE
41 .sp
42 .ne 2
43 .na
44 \fB\fB-c\fR\fR
45 .ad
46 .RS 6n
47 Sort by decreasing number of calls.
48 .RE
50 .sp
51 .ne 2
52 .na
53 \fB\fB-n\fR\fR
54 .ad
55 .RS 6n
56 Sort lexically by symbol name.
57 .RE
59 .sp
60 .ne 2
61 .na
62 \fB\fB-t\fR\fR
63 .ad
64 .RS 6n
65 Sort by decreasing percentage of total time (default).
66 .RE
68 .sp
69 .LP
70 The mutually exclusive options \fB-o\fR and  \fB-x\fR specify the printing of
71 the address of each symbol monitored:
72 .sp
73 .ne 2
74 .na
75 \fB\fB-o\fR\fR
76 .ad
77 .RS 6n
78 Print each symbol address (in octal) along with the symbol name.
79 .RE
81 .sp
82 .ne 2
83 .na
84 \fB\fB-x\fR\fR
85 .ad
86 .RS 6n
87 Print each symbol address (in hexadecimal) along with the symbol name.
88 .RE
90 .sp
91 .LP
92 The mutually exclusive options \fB-g\fR and \fB-l\fR control the type of
93 symbols to be reported. The  \fB-l\fR option must be used with care; it applies
94 the time spent in a static function to the preceding (in memory) global
95 function, instead of giving the static function a separate entry in the report.
96 If all static functions are properly located, this feature can be very useful.
97 If not, the resulting report may be misleading.
98 .sp
99 .LP
100 Assume that  \fBA\fR and \fBB\fR are global functions and only  \fBA\fR calls
101 static function  \fBS\fR. If  \fBS\fR is located immediately after  A in the
102 source code (that is, if  \fBS\fR is properly located), then, with the
103 \fB-l\fR option, the amount of time spent in  \fBA\fR can easily be determined,
104 including the time spent in  \fBS\fR. If, however, both  \fBA\fR and \fBB\fR
105 call  \fBS\fR, then, if the  \fB-l\fR option is used, the report will be
106 misleading; the time spent during  \fBB\fR's call to  \fBS\fR will be
107 attributed to  \fBA\fR, making it appear as if more time had been spent in
108 \fBA\fR than really had.  In this case, function  \fBS\fR cannot be properly
109 located.
111 .ne 2
113 \fB\fB-g\fR\fR
115 .RS 6n
116 List the time spent in static (non-global) functions separately. The \fB-g\fR
117 option function is the opposite of the  \fB-l\fR function.
121 .ne 2
123 \fB\fB-l\fR\fR
125 .RS 6n
126 Suppress printing statically declared functions.  If this option is given, time
127 spent executing in a static function is allocated to the closest global
128 function loaded before the static function in the executable.  This option is
129 the default.  It is the opposite of  the  \fB-g\fR function and should be used
130 with care.
135 The following options may be used in any combination:
137 .ne 2
139 \fB\fB-C\fR\fR
141 .RS 12n
142 Demangle C++ symbol names before printing them out.
146 .ne 2
148 \fB\fB-h\fR\fR
150 .RS 12n
151 Suppress the heading normally printed on the report. This is useful if the
152 report is to be processed further.
156 .ne 2
158 \fB\fB-m\fR \fImdata\fR\fR
160 .RS 12n
161 Use file \fImdata\fR instead of \fBmon.out\fR as the input profile file.
165 .ne 2
167 \fB\fB-s\fR\fR
169 .RS 12n
170 Print a summary of several of the monitoring parameters and statistics on the
171 standard error output.
175 .ne 2
177 \fB\fB-V\fR\fR
179 .RS 12n
180 Print  \fBprof\fR version information on the standard error output.
184 .ne 2
186 \fB\fB-z\fR\fR
188 .RS 12n
189 Include all symbols in the profile range, even if associated with zero number
190 of calls and zero time.
195 A single function may be split into subfunctions for profiling by means of the
196 \fBMARK\fR macro. See  \fBprof\fR(5).
197 .SH ENVIRONMENT VARIABLES
199 .ne 2
201 \fB\fBPROFDIR\fR\fR
203 .RS 11n
204 The name of the file created by a profiled program is controlled by the
205 environment variable \fBPROFDIR\fR. If \fBPROFDIR\fR is not set,  \fBmon.out\fR
206 is produced in the directory current when the program terminates. If
207 \fBPROFDIR\fR=\fIstring\fR, \fIstring\fR\fB/\fR\fIpid\fR\fB\&.\fR\fIprogname\fR
208 is produced, where  \fIprogname\fR consists of  \fBargv[0]\fR with any path
209 prefix removed, and \fIpid\fR is the process ID of the program.  If
210 \fBPROFDIR\fR is set, but null, no profiling output is produced.
213 .SH FILES
215 .ne 2
217 \fB\fBmon.out\fR\fR
219 .RS 11n
220 default profile file
224 .ne 2
226 \fB\fBa.out\fR\fR
228 .RS 11n
229 default namelist (object) file
232 .SH SEE ALSO
235 \fBgprof\fR(1), \fBexit\fR(2), \fBpcsample\fR(2), \fBprofil\fR(2),
236 \fBmalloc\fR(3C), \fBmalloc\fR(3MALLOC), \fBmonitor\fR(3C),
237 \fBattributes\fR(5), \fBprof\fR(5)
238 .SH NOTES
241 If the executable image has been stripped and does not have the \fB\&.symtab\fR
242 symbol table, \fBgprof\fR reads the global dynamic symbol tables
243 \fB\&.dynsym\fR and \fB\&.SUNW_ldynsym\fR, if present.  The symbols in the
244 dynamic symbol tables are a subset of the symbols that are found in
245 \fB\&.symtab\fR. The \fB\&.dynsym\fR symbol table contains the global symbols
246 used by the runtime linker. \fB\&.SUNW_ldynsym\fR augments the information in
247 \fB\&.dynsym\fR with local function symbols. In the case where \fB\&.dynsym\fR
248 is found and \fB\&.SUNW_ldynsym\fR is not, only the  information for the global
249 symbols is available. Without local symbols, the behavior is as described for
250 the  \fB-a\fR option.
253 The times reported in successive identical runs may show variances because of
254 varying cache-hit ratios that result from sharing the cache with other
255 processes. Even if a program seems to be the only one using the machine, hidden
256 background or asynchronous processes may blur the data. In rare cases, the
257 clock ticks initiating recording of the program counter may \fBbeat\fR with
258 loops in a program, grossly distorting measurements. Call counts are always
259 recorded precisely, however.
262 Only programs that call  \fBexit\fR or return from  \fBmain\fR are guaranteed
263 to produce a profile file, unless a final call to  \fBmonitor\fR is explicitly
264 coded.
267 The times for static functions are attributed to the preceding external text
268 symbol if the \fB-g\fR option is not used. However, the call counts for the
269 preceding function are still correct; that is, the static function call counts
270 are not added to the call counts of the external function.
273 If more than one of the options  \fB-t\fR, \fB-c\fR, \fB-a\fR,  and  \fB-n\fR
274 is specified, the last option specified is used and the user is warned.
277 \fBLD_LIBRARY_PATH\fR must not contain \fB/usr/lib\fR as a component when
278 compiling a program for profiling. If   \fBLD_LIBRARY_PATH\fR contains
279 \fB/usr/lib\fR, the program will not be linked correctly with the profiling
280 versions of the system libraries in \fB/usr/lib/libp\fR. See \fBgprof\fR(1).
283 Functions such as  \fBmcount()\fR, \fB_mcount()\fR, \fBmoncontrol()\fR,
284 \fB_moncontrol()\fR, \fBmonitor()\fR, and \fB_monitor()\fR may appear in the
285 \fBprof\fR report.  These functions are part of the profiling implementation
286 and thus account for some amount of the runtime overhead.  Since these
287 functions are not present in an unprofiled application, time accumulated and
288 call counts for these functions may be ignored when evaluating the performance
289 of an application.
290 .SS "64-bit profiling"
293 64-bit profiling may be used freely with dynamically linked executables, and
294 profiling information is collected for the shared objects if the objects are
295 compiled for profiling. Care must be applied to interpret the profile output,
296 since it is possible for symbols from different shared objects to have the same
297 name. If duplicate names are seen in the profile output, it is better to use
298 the \fB-s\fR (summary) option, which prefixes a module id before each symbol
299 that is duplicated. The symbols can then be mapped to appropriate modules by
300 looking at the modules information in the summary.
303 If the \fB-a\fR option is used with a dynamically linked executable, the
304 sorting occurs on a per-shared-object basis. Since there is a high likelihood
305 of symbols from differed shared objects to have the same value, this results in
306 an output that is more understandable. A blank line separates the symbols from
307 different shared objects, if the \fB-s\fR option is given.
308 .SS "32-bit profiling"
311 32-bit profiling may be used with dynamically linked executables, but care must
312 be applied. In 32-bit profiling, shared objects cannot be profiled with
313 \fBprof\fR. Thus, when a profiled, dynamically linked program is executed, only
314 the \fBmain\fR portion of the image is sampled. This means that all time spent
315 outside of the \fBmain\fR object, that is, time spent in a shared object, will
316 not be included in the profile summary; the total time reported for the program
317 may be less than the total time used by the program.
320 Because the time spent in a shared object cannot be accounted for, the use of
321 shared objects should be minimized whenever a program is profiled with
322 \fBprof\fR. If desired, the program should be linked to the profiled version of
323 a library (or to the standard archive version if no profiling version is
324 available), instead of the shared object to get profile information on the
325 functions of a library. Versions of profiled libraries may be supplied with the
326 system in the \fB/usr/lib/libp\fR directory. Refer to compiler driver
327 documentation on profiling.
330 Consider an extreme case. A profiled program dynamically linked with the shared
331 C library spends 100 units of time in some  \fBlibc\fR routine, say,
332 \fBmalloc()\fR. Suppose  \fBmalloc()\fR is called only from routine  \fBB\fR
333 and \fBB\fR consumes only 1 unit of time. Suppose further that routine  \fBA\fR
334 consumes 10 units of time, more than any other routine in the \fBmain\fR
335 (profiled) portion of the image. In this case,  \fBprof\fR will conclude that
336 most of the time is being spent in  \fBA\fR and almost no time is being spent
337 in  \fBB\fR. From this it will be almost impossible to tell that the greatest
338 improvement can be made by looking at routine  \fBB\fR and not routine
339 \fBA\fR. The value of the profiler in this case is severely degraded; the
340 solution is to use archives as much as possible for profiling.