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