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