version 2.11 becomes 2.12 automagically.
[unix-history] / usr / src / usr.bin / gprof / PSD.doc / profiling.me
CommitLineData
9f7329e7 1\" @(#)profiling.me 1.6 %G%
fa7270bc
PK
2.sh 1 "Types of Profiling"
3.pp
bded3f9b 4There are several different uses for program profiles,
fa7270bc
PK
5and each may require different information from the profiles,
6or different presentation of the information.
7We distinguish two broad categories of profiles:
8those that present counts of statement or routine invocations,
9and those that display timing information about statements
10or routines.
11Counts are typically presented in tabular form,
12often in parallel with a listing of the source code.
dc7f8b19 13Timing information could be similarly presented;
602c58f5
PK
14but more than one measure of time might be associated with each
15statement or routine.
dc7f8b19
PK
16For example,
17in the framework used by \fBgprof\fP
18each profiled segment would display two times:
fa7270bc
PK
19one for the time used by the segment itself, and another for the
20time inherited from code segments it invokes.
21.pp
bded3f9b 22Execution counts are used in many different contexts.
fa7270bc
PK
23The exact number of times a routine or statement is activated
24can be used to determine if an algorithm is performing as
25expected.
bded3f9b 26Cursory inspection of such counters may show algorithms whose
fa7270bc 27complexity is unsuited to the task at hand.
597923e1 28Careful interpretation of counters can often suggest
fa7270bc
PK
29improvements to acceptable algorithms.
30Precise examination can uncover subtle errors in an
31algorithm.
bded3f9b 32At this level, profiling counters are similar to
fa7270bc
PK
33debugging statements whose purpose is to show the number of times
34a piece of code is executed.
35Another view of such counters is as boolean values.
36One may be interested that a portion of code has executed at
dc7f8b19 37all, for exhaustive testing, or to check that one implementation
fa7270bc
PK
38of an abstraction completely replaces a previous one.
39.pp
40Execution counts are not necessarily proportional to the amount
41of time required to execute the routine or statement.
42Further, the execution time of a routine will not be the same for
43all calls on the routine.
dc7f8b19 44The criteria for establishing execution time
fa7270bc
PK
45must be decided.
46If a routine implements an abstraction by invoking other abstractions,
47the time spent in the routine will not accurately reflect the
48time required by the abstraction it implements.
bded3f9b 49Similarly, if an abstraction is implemented by several
597923e1 50routines the time required by the abstraction will be distributed
fa7270bc
PK
51across those routines.
52.pp
bded3f9b 53Given the execution time of individual routines,
fa7270bc 54\fBgprof\fP accounts to each routine the time spent
bded3f9b 55for it by the routines it invokes.
dc7f8b19 56This accounting is done by assembling a \fIcall graph\fP with nodes that
fa7270bc
PK
57are the routines of the program and directed arcs that represent
58calls from call sites to routines.
59We distinguish among three different call graphs for a program.
60The \fIcomplete call graph\fP incorporates all routines and all
61potential arcs,
62including arcs that represent calls to functional parameters
602c58f5 63or functional variables.
fa7270bc
PK
64This graph contains the other two graphs as subgraphs.
65The \fIstatic call graph\fP includes all routines and all possible arcs
66that are not calls to functional parameters or variables.
67The \fIdynamic call graph\fP includes only those routines and
68arcs traversed by the profiled execution of the program.
69This graph need not include all routines, nor need it include all
70potential arcs between the routines it covers.
71It may, however, include arcs to functional parameters or
72variables that the static call graph may omit.
73The static call graph can be determined from the (static) program text.
74The dynamic call graph is determined only by profiling an
75execution of the program.
76The complete call graph for a monolithic program could be determined
77by data flow analysis techniques.
78The complete call graph for programs that change
79during execution, by modifying themselves or dynamically loading
80or overlaying code, may never be determinable.
9f7329e7
PK
81Both the static call graph and the dynamic call graph are used
82by \fBgprof\fP, but it does not search for the complete call
83graph.