gprof: Replace BSD gprof and gprof4 with gnu gprof
[dragonfly.git] / usr.bin / gprof / PSD.doc / profiling.me
1 .\" Copyright (c) 1982, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)profiling.me        8.1 (Berkeley) 6/8/93
33 .\"
34 .sh 1 "Types of Profiling"
35 .pp
36 There are several different uses for program profiles,
37 and each may require different information from the profiles,
38 or different presentation of the information.
39 We distinguish two broad categories of profiles:
40 those that present counts of statement or routine invocations,
41 and those that display timing information about statements
42 or routines.
43 Counts are typically presented in tabular form,
44 often in parallel with a listing of the source code.
45 Timing information could be similarly presented;
46 but more than one measure of time might be associated with each
47 statement or routine.
48 For example,
49 in the framework used by \fBgprof\fP
50 each profiled segment would display two times:
51 one for the time used by the segment itself, and another for the
52 time inherited from code segments it invokes.
53 .pp
54 Execution counts are used in many different contexts.
55 The exact number of times a routine or statement is activated
56 can be used to determine if an algorithm is performing as 
57 expected.
58 Cursory inspection of such counters may show algorithms whose
59 complexity is unsuited to the task at hand.
60 Careful interpretation of counters can often suggest
61 improvements to acceptable algorithms.
62 Precise examination can uncover subtle errors in an
63 algorithm.
64 At this level, profiling counters are similar to
65 debugging statements whose purpose is to show the number of times
66 a piece of code is executed.
67 Another view of such counters is as boolean values.
68 One may be interested that a portion of code has executed at
69 all, for exhaustive testing, or to check that one implementation
70 of an abstraction completely replaces a previous one.
71 .pp
72 Execution counts are not necessarily proportional to the amount
73 of time required to execute the routine or statement.
74 Further, the execution time of a routine will not be the same for
75 all calls on the routine.
76 The criteria for establishing execution time
77 must be decided.
78 If a routine implements an abstraction by invoking other abstractions,
79 the time spent in the routine will not accurately reflect the
80 time required by the abstraction it implements.
81 Similarly, if an abstraction is implemented by several
82 routines the time required by the abstraction will be distributed
83 across those routines.
84 .pp
85 Given the execution time of individual routines,
86 \fBgprof\fP accounts to each routine the time spent
87 for it by the routines it invokes.
88 This accounting is done by assembling a \fIcall graph\fP with nodes that
89 are the routines of the program and directed arcs that represent
90 calls from call sites to routines.
91 We distinguish among three different call graphs for a program.
92 The \fIcomplete call graph\fP incorporates all routines and all
93 potential arcs,
94 including arcs that represent calls to functional parameters
95 or functional variables.
96 This graph contains the other two graphs as subgraphs.
97 The \fIstatic call graph\fP includes all routines and all possible arcs
98 that are not calls to functional parameters or variables.
99 The \fIdynamic call graph\fP includes only those routines and
100 arcs traversed by the profiled execution of the program.
101 This graph need not include all routines, nor need it include all
102 potential arcs between the routines it covers.
103 It may, however, include arcs to functional parameters or
104 variables that the static call graph may omit.
105 The static call graph can be determined from the (static) program text.
106 The dynamic call graph is determined only by profiling an
107 execution of the program.
108 The complete call graph for a monolithic program could be determined
109 by data flow analysis techniques.
110 The complete call graph for programs that change
111 during execution, by modifying themselves or dynamically loading
112 or overlaying code, may never be determinable.
113 Both the static call graph and the dynamic call graph are used
114 by \fBgprof\fP, but it does not search for the complete call
115 graph.