1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
<?xml version="1.0" encoding="latin1" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">
<erlref>
<header>
<copyright>
<year>2002</year>
<year>2011</year>
<holder>Ericsson AB, All Rights Reserved</holder>
</copyright>
<legalnotice>
The contents of this file are subject to the Erlang Public License,
Version 1.1, (the "License"); you may not use this file except in
compliance with the License. You should have received a copy of the
Erlang Public License along with this software. If not, it can be
retrieved online at http://www.erlang.org/.
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
the License for the specific language governing rights and limitations
under the License.
The Initial Developer of the Original Code is Ericsson AB.
</legalnotice>
<title>cprof</title>
<prepared>Raimo Niskanen</prepared>
<responsible>nobody</responsible>
<docno></docno>
<approved>nobody</approved>
<checked></checked>
<date>2002-09-12</date>
<rev>PA1</rev>
<file>cprof.sgml</file>
</header>
<module>cprof</module>
<modulesummary>A simple Call Count Profiling Tool using breakpoints for minimal runtime performance impact.</modulesummary>
<description>
<p>The <c>cprof</c> module is used to profile a program
to find out how many times different functions are called.
Breakpoints similar to local call trace, but containing a
counter, are used to minimise runtime performance impact.
</p>
<p>Since breakpoints are used there is no need for special
compilation of any module to be profiled. For now these
breakpoints can only be set on BEAM code so <term id="BIF"></term>s
cannot be call count traced.
</p>
<p>The size of the call counters is the host machine word
size. One bit is used when pausing the counter, so the maximum
counter value for a 32-bit host is 2147483647.
</p>
<p>The profiling result is delivered as a term containing a
sorted list of entries, one per module. Each module entry
contains a sorted list of functions. The sorting order in both
cases is of decreasing call count.
</p>
<p>Call count tracing is very lightweight compared to other forms
of tracing since no trace message has to be generated. Some
measurements indicates performance degradation in the vicinity
of 10 percent.
<marker id="analyse"></marker>
</p>
</description>
<funcs>
<func>
<name>analyse() -> {AllCallCount, ModAnalysisList}</name>
<name>analyse(Limit) -> {AllCallCount, ModAnalysisList}</name>
<name>analyse(Mod) -> ModAnlysis</name>
<name>analyse(Mod, Limit) -> ModAnalysis</name>
<fsummary>Collect and analyse call counters.</fsummary>
<type>
<v>Limit = integer()</v>
<v>Mod = atom()</v>
<v>AllCallCount = integer()</v>
<v>ModAnalysisList = [ModAnalysis]</v>
<v>ModAnalysis = {Mod, ModCallCount, FuncAnalysisList}</v>
<v>ModCallCount = integer()</v>
<v>FuncAnalysisList = [{{Mod, Func, Arity}, FuncCallCount}]</v>
<v>Func = atom()</v>
<v>Arity = integer()</v>
<v>FuncCallCount = integer()</v>
</type>
<desc>
<p>Collects and analyses the call counters presently in the
node for either module <c>Mod</c>, or for all modules
(except <c>cprof</c> itself), and returns: </p>
<taglist>
<tag><c>FuncAnalysisList</c></tag>
<item>A list of tuples, one for each function in a module, in
decreasing <c>FuncCallCount</c> order.</item>
<tag><c>ModCallCount</c></tag>
<item>The sum of <c>FuncCallCount</c> values for all
functions in module <c>Mod</c>.</item>
<tag><c>AllCallCount</c></tag>
<item>The sum of <c>ModCallCount</c> values for all modules
concerned in <c>ModAnalysisList</c>.</item>
<tag><c>ModAnalysisList</c></tag>
<item>A list of tuples, one for each module except
<c>cprof</c>, in decreasing <c>ModCallCount</c> order.</item>
</taglist>
<p>If call counters are still running while
<c>analyse/0..2</c> is executing, you might get an
inconsistent result. This happens if the process executing
<c>analyse/0..2</c> gets scheduled out so some other process
can increment the counters that are being analysed, Calling
<c>pause()</c> before analysing takes care of the problem.
</p>
<p>If the <c>Mod</c> argument is given, the result contains a
<c>ModAnalysis</c> tuple for module <c>Mod</c> only,
otherwise the result contains one <c>ModAnalysis</c> tuple
for all modules returned from <c>code:all_loaded()</c>
except <c>cprof</c> itself.
</p>
<p>All functions with a <c>FuncCallCount</c> lower than
<c>Limit</c> are excluded from <c>FuncAnalysisList</c>. They
are still included in <c>ModCallCount</c>, though.
The default value for <c>Limit</c> is <c>1</c>.
<marker id="pause_0"></marker>
</p>
</desc>
</func>
<func>
<name>pause() -> integer()</name>
<fsummary>Pause running call count trace for all functions.</fsummary>
<desc>
<p>Pause call count tracing for all functions in all modules
and stop it for all functions in modules to be
loaded. This is the same as
<c>(pause({'_','_','_'})+stop({on_load}))</c>.
</p>
<p>See also
<seealso marker="#pause">pause/1..3</seealso> below.
<marker id="pause"></marker>
</p>
</desc>
</func>
<func>
<name>pause(FuncSpec) -> integer()</name>
<name>pause(Mod, Func) -> integer()</name>
<name>pause(Mod, Func, Arity) -> integer()</name>
<fsummary>Pause running call count trace for matching functions.</fsummary>
<type>
<v>FuncSpec = Mod | {Mod,Func,Arity}, {FS}</v>
<v>Mod = atom()</v>
<v>Func = atom()</v>
<v>Arity = integer()</v>
<v>FS = term()</v>
</type>
<desc>
<p>Pause call counters for matching functions in matching
modules. The <c>FS</c> argument can be used to
specify the first argument to
<c>erlang:trace_pattern/3</c>. See erlang(3).
</p>
<p>The call counters for all matching functions that
has got call count breakpoints are paused at their current
count.
</p>
<p>Return the number of matching functions that can have
call count breakpoints, the same as
<c>start/0..3</c> with the same arguments would have
returned.
<marker id="restart"></marker>
</p>
</desc>
</func>
<func>
<name>restart() -> integer()</name>
<name>restart(FuncSpec) -> integer()</name>
<name>restart(Mod, Func) -> integer()</name>
<name>restart(Mod, Func, Arity) -> integer()</name>
<fsummary>Restart existing call counters for matching functions.</fsummary>
<type>
<v>FuncSpec = Mod | {Mod,Func,Arity}, {FS}</v>
<v>Mod = atom()</v>
<v>Func = atom()</v>
<v>Arity = integer()</v>
<v>FS = term()</v>
</type>
<desc>
<p>Restart call counters for the matching functions in
matching modules that are call count traced. The <c>FS</c>
argument can be used to specify the first argument to
<c>erlang:trace_pattern/3</c>. See erlang(3).
</p>
<p>The call counters for all matching functions that has got
call count breakpoints are set to zero and running.
</p>
<p>Return the number of matching functions that can have
call count breakpoints, the same as
<c>start/0..3</c> with the same arguments would have
returned.
<marker id="start_0"></marker>
</p>
</desc>
</func>
<func>
<name>start() -> integer()</name>
<fsummary>Start call count tracing for all functions.</fsummary>
<desc>
<p>Start call count tracing for all functions in all modules,
and also for all functions in modules to be
loaded. This is the same as
<c>(start({'_','_','_'})+start({on_load}))</c>.
</p>
<p>See also
<seealso marker="#start">start/1..3</seealso> below.
<marker id="start"></marker>
</p>
</desc>
</func>
<func>
<name>start(FuncSpec) -> integer()</name>
<name>start(Mod, Func) -> integer()</name>
<name>start(Mod, Func, Arity) -> integer()</name>
<fsummary>Start call count tracing for matching functions.</fsummary>
<type>
<v>FuncSpec = Mod | {Mod,Func,Arity}, {FS}</v>
<v>Mod = atom()</v>
<v>Func = atom()</v>
<v>Arity = integer()</v>
<v>FS = term()</v>
</type>
<desc>
<p>Start call count tracing for matching functions in matching
modules. The <c>FS</c> argument can be used to specify the
first argument to <c>erlang:trace_pattern/3</c>, for example
<c>on_load</c>. See erlang(3).
</p>
<p>Set call count breakpoints on the matching functions that
has no call count breakpoints. Call counters
are set to zero and running for all matching functions.
</p>
<p>Return the number of matching functions that has got
call count breakpoints.
<marker id="stop_0"></marker>
</p>
</desc>
</func>
<func>
<name>stop() -> integer()</name>
<fsummary>Stop call count tracing for all functions.</fsummary>
<desc>
<p>Stop call count tracing for all functions in all modules,
and also for all functions in modules to be
loaded. This is the same as
<c>(stop({'_','_','_'})+stop({on_load}))</c>.
</p>
<p>See also
<seealso marker="#stop">stop/1..3</seealso> below.
<marker id="stop"></marker>
</p>
</desc>
</func>
<func>
<name>stop(FuncSpec) -> integer()</name>
<name>stop(Mod, Func) -> integer()</name>
<name>stop(Mod, Func, Arity) -> integer()</name>
<fsummary>Stop call count tracing for matching functions.</fsummary>
<type>
<v>FuncSpec = Mod | {Mod,Func,Arity}, {FS}</v>
<v>Mod = atom()</v>
<v>Func = atom()</v>
<v>Arity = integer()</v>
<v>FS = term()</v>
</type>
<desc>
<p>Stop call count tracing for matching functions in matching
modules. The <c>FS</c> argument can be used to specify the
first argument to <c>erlang:trace_pattern/3</c>, for example
<c>on_load</c>. See erlang(3).
</p>
<p>Remove call count breakpoints from the matching functions that
has call count breakpoints.
</p>
<p>Return the number of matching functions that can have
call count breakpoints, the same as
<c>start/0..3</c> with the same arguments would have
returned.
</p>
</desc>
</func>
</funcs>
<section>
<title>See Also</title>
<p><seealso marker="eprof">eprof</seealso>(3),
<seealso marker="fprof">fprof</seealso>(3),
erlang(3),
<seealso marker="cprof_chapter">User's Guide</seealso></p>
</section>
</erlref>
|