Merge branch 'xml-fixes' of https://github.com/myeisha/mono into myeisha-xml-fixes
[mono.git] / man / mprof-report.1
1 .TH mprof-report 1 "" 
2 .SH The Mono log profiler
3 .PP
4 The Mono \f[I]log\f[] profiler can be used to collect a lot of
5 information about a program running in the Mono runtime.
6 This data can be used (both while the process is running and later)
7 to do analyses of the program behaviour, determine resource usage,
8 performance issues or even look for particular execution patterns.
9 .PP
10 This is accomplished by logging the events provided by the Mono
11 runtime through the profiling interface and periodically writing
12 them to a file which can be later inspected with the command line
13 \f[I]mprof-report\f[] program or with a GUI (not developed yet).
14 .PP
15 The events collected include (among others):
16 .IP \[bu] 2
17 method enter and leave
18 .IP \[bu] 2
19 object allocation
20 .IP \[bu] 2
21 garbage collection
22 .IP \[bu] 2
23 JIT compilation
24 .IP \[bu] 2
25 metadata loading
26 .IP \[bu] 2
27 lock contention
28 .IP \[bu] 2
29 exceptions
30 .PP
31 In addition, the profiler can periodically collect info about all
32 the objects present in the heap at the end of a garbage collection
33 (this is called heap shot and currently implemented only for the
34 sgen garbage collector).
35 .SS Basic profiler usage
36 .PP
37 The simpler way to use the profiler is the following:
38 .PP
39 \f[B]mono\ --profile=log\ program.exe\f[]
40 .PP
41 At the end of the execution the file \f[I]output.mlpd\f[] will be
42 found in the current directory.
43 A summary report of the data can be printed by running:
44 .PP
45 \f[B]mprof-report\ output.mlpd\f[]
46 .PP
47 With this invocation a huge amount of data is collected about the
48 program execution and collecting and saving this data can
49 significantly slow down program execution.
50 If saving the profiling data is not needed, a report can be
51 generated directly with:
52 .PP
53 \f[B]mono\ --profile=log:report\ program.exe\f[]
54 .PP
55 If the information about allocations is not of interest, it can be
56 excluded:
57 .PP
58 \f[B]mono\ --profile=log:noalloc\ program.exe\f[]
59 .PP
60 On the other hand, if method call timing is not important, while
61 allocations are, the needed info can be gathered with:
62 .PP
63 \f[B]mono\ --profile=log:nocalls\ program.exe\f[]
64 .PP
65 You will still be able to inspect information about the sequence of
66 calls that lead to each allocation because at each object
67 allocation a stack trace is collected as well.
68 .PP
69 To periodically collect heap shots (and exclude method and
70 allocation events) use the following options (making sure you run
71 with the sgen garbage collector):
72 .PP
73 \f[B]mono\ --gc=sgen\ --profile=log:heapshot\ program.exe\f[]
74 .SS Profiler option documentation
75 .PP
76 By default the \f[I]log\f[] profiler will gather all the events
77 provided by the Mono runtime and write them to a file named
78 \f[I]output.mlpd\f[].
79 When no option is specified, it is equivalent to using:
80 .PP
81 \f[B]--profile=log:calls,alloc,output=output.mlpd,maxframes=8,calldepth=100\f[]
82 .PP
83 The following options can be used to modify this default behaviour.
84 Each option is separated from the next by a \f[B],\f[] character,
85 with no spaces and all the options are included after the
86 \f[I]log:\f[] profile module specifier.
87 .IP \[bu] 2
88 \f[I]help\f[]: display concise help info about each available
89 option
90 .IP \[bu] 2
91 \f[I][no]alloc\f[]: \f[I]noalloc\f[] disables collecting object
92 allocation info, \f[I]alloc\f[] enables it if it was disabled by
93 another option like \f[I]heapshot\f[].
94 .IP \[bu] 2
95 \f[I][no]calls\f[]: \f[I]nocalls\f[] disables collecting method
96 enter and leave events.
97 When this option is used at each object allocation and at some
98 other events (like lock contentions and exception throws) a stack
99 trace is collected by default.
100 See the \f[I]maxframes\f[] option to control this behaviour.
101 \f[I]calls\f[] enables method enter/leave events if they were
102 disabled by another option like \f[I]heapshot\f[].
103 .IP \[bu] 2
104 \f[I]heapshot[=MODE]\f[]: collect heap shot data at each major
105 collection.
106 The frequency of the heap shots can be changed with the
107 \f[I]MODE\f[] parameter.
108 When this option is used allocation events and method enter/leave
109 events are not recorded by default: if they are needed, they need
110 to be enabled explicitly.
111 The optional parameter \f[I]MODE\f[] can modify the default heap
112 shot frequency.
113 heapshot can be used multiple times with different modes: in that
114 case a heap shot is taken if either of the conditions are met.
115 MODE can be one of:
116 .RS 2
117 .IP \[bu] 2
118 \f[I]NUM\f[]ms: perform a heap shot if at least \f[I]NUM\f[]
119 milliseconds passed since the last one.
120 .IP \[bu] 2
121 \f[I]NUM\f[]gc: perform a heap shot every \f[I]NUM\f[] garbage
122 collections (either minor or major).
123 .RE
124 .IP \[bu] 2
125 \f[I]time=TIMER\f[]: use the TIMER timestamp mode.
126 TIMER can have the following values:
127 .RS 2
128 .IP \[bu] 2
129 \f[I]fast\f[]: a usually faster but possibly more inaccurate timer
130 .RE
131 .IP \[bu] 2
132 \f[I]maxframes=NUM\f[]: when a stack trace needs to be performed,
133 collect \f[I]NUM\f[] frames at the most.
134 The default is 8.
135 .IP \[bu] 2
136 \f[I]calldepth=NUM\f[]: ignore method enter/leave events when the
137 call chain depth is bigger than NUM.
138 .IP \[bu] 2
139 \f[I]zip\f[]: automatically compress the output data in gzip
140 format.
141 .IP \[bu] 2
142 \f[I]output=OUTSPEC\f[]: instead of writing the profiling data to
143 the output.mlpd file, substitute \f[I]%p\f[] in \f[I]OUTSPEC\f[]
144 with the current process id and \f[I]%t\f[] with the current date
145 and time, then do according to \f[I]OUTSPEC\f[]:
146 .RS 2
147 .IP \[bu] 2
148 if \f[I]OUTSPEC\f[] begins with a \f[I]|\f[] character, execute the
149 rest as a program and feed the data to its standard input
150 .IP \[bu] 2
151 if \f[I]OUTSPEC\f[] begins with a \f[I]-\f[] character, use the
152 rest of OUTSPEC as the filename, but force overwrite any existing
153 file by that name
154 .IP \[bu] 2
155 otherwise write the data the the named file: note that is a file by
156 that name already exists, a warning is issued and profiling is
157 disabled.
158 .RE
159 .IP \[bu] 2
160 \f[I]report\f[]: the profiling data is sent to mprof-report, which
161 will print a summary report.
162 This is equivalent to the option: \f[B]output=mprof-report\ -\f[].
163 If the \f[I]output\f[] option is specified as well, the report will
164 be written to the output file instead of the console.
165 .SS Analyzing the profile data
166 .PP
167 Currently there is a command line program (\f[I]mprof-report\f[])
168 to analyze the data produced by the profiler.
169 This is ran automatically when the \f[I]report\f[] profiler option
170 is used.
171 Simply run:
172 .PP
173 \f[B]mprof-report\ output.mlpd\f[]
174 .PP
175 to see a summary report of the data included in the file.
176 .SS Trace information for events
177 .PP
178 Often it is important for some events, like allocations, lock
179 contention and exception throws to know where they happened.
180 Or we may want to see what sequence of calls leads to a particular
181 method invocation.
182 To see this info invoke mprof-report as follows:
183 .PP
184 \f[B]mprof-report\ --traces\ output.mlpd\f[]
185 .PP
186 The maximum number of methods in each stack trace can be specified
187 with the \f[I]\[em]maxframes=NUM\f[] option:
188 .PP
189 \f[B]mprof-report\ --traces\ --maxframes=4\ output.mlpd\f[]
190 .PP
191 The stack trace info will be available if method enter/leave events
192 have been recorded or if stack trace collection wasn't explicitly
193 disabled with the \f[I]maxframes=0\f[] profiler option.
194 Note that the profiler will collect up to 8 frames by default at
195 specific events when the \f[I]nocalls\f[] option is used, so in
196 that case, if more stack frames are required in mprof-report, a
197 bigger value for maxframes when profiling must be used, too.
198 .PP
199 The \f[I]\[em]traces\f[] option also controls the reverse reference
200 feature in the heapshot report: for each class it reports how many
201 references to objects of that class come from other classes.
202 .SS Sort order for methods and allocations
203 .PP
204 When a list of methods is printed the default sort order is based
205 on the total time spent in the method.
206 This time is wall clock time (that is, it includes the time spent,
207 for example, in a sleep call, even if actual cpu time would be
208 basically 0).
209 Also, if the method has been ran on different threads, the time
210 will be a sum of the time used in each thread.
211 .PP
212 To change the sort order, use the option:
213 .PP
214 \f[B]--method-sort=MODE\f[]
215 .PP
216 where \f[I]MODE\f[] can be:
217 .IP \[bu] 2
218 \f[I]self\f[]: amount of time spent in the method itself and not in
219 its callees
220 .IP \[bu] 2
221 \f[I]calls\f[]: the number of method invocations
222 .IP \[bu] 2
223 \f[I]total\f[]: the total time spent in the method.
224 .PP
225 Object allocation lists are sorted by default depending on the
226 total amount of bytes used by each type.
227 .PP
228 To change the sort order of object allocations, use the option:
229 .PP
230 \f[B]--alloc-sort=MODE\f[]
231 .PP
232 where \f[I]MODE\f[] can be:
233 .IP \[bu] 2
234 \f[I]count\f[]: the number of allocated objects of the given type
235 .IP \[bu] 2
236 \f[I]bytes\f[]: the total number of bytes used by objects of the
237 given type
238 .SS Selecting what data to report
239 .PP
240 The profiler by default collects data about many runtime subsystems
241 and mprof-report prints a summary of all the subsystems that are
242 found in the data file.
243 It is possible to tell mprof-report to only show information about
244 some of them with the following option:
245 .PP
246 \f[B]--reports=R1[,R2...]\f[]
247 .PP
248 where the report names R1, R2 etc.
249 can be:
250 .IP \[bu] 2
251 \f[I]gc\f[]: garbage collection information
252 .IP \[bu] 2
253 \f[I]alloc\f[]: object allocation information
254 .IP \[bu] 2
255 \f[I]call\f[]: method profiling information
256 .IP \[bu] 2
257 \f[I]metadata\f[]: metadata events like image loads
258 .IP \[bu] 2
259 \f[I]exception\f[]: exception throw and handling information
260 .IP \[bu] 2
261 \f[I]monitor\f[]: lock contention information
262 .IP \[bu] 2
263 \f[I]thread\f[]: thread information
264 .IP \[bu] 2
265 \f[I]heapshot\f[]: live heap usage at heap shots
266 .PP
267 It is possible to limit some of the data displayed to a timeframe
268 of the program execution with the option:
269 .PP
270 \f[B]--time=FROM-TO\f[]
271 .PP
272 where \f[I]FROM\f[] and \f[I]TO\f[] are seconds since application
273 startup (they can be floating point numbers).
274 .PP
275 Another interesting option is to consider only events happening on
276 a particular thread with the following option:
277 .PP
278 \f[B]--thread=THREADID\f[]
279 .PP
280 where \f[I]THREADID\f[] is one of the numbers listed in the thread
281 summary report (or a thread name when present).
282 .PP
283 By default long lists of methods or other information like object
284 allocations are limited to the most important data.
285 To increase the amount of information printed you can use the
286 option:
287 .PP
288 \f[B]--verbose\f[]
289 .SS Track individual objects
290 .PP
291 Instead of printing the usual reports from the profiler data, it is
292 possible to track some interesting information about some specific
293 object addresses.
294 The objects are selected based on their address with the
295 \f[I]\[em]track\f[] option as follows:
296 .PP
297 \f[B]--track=0xaddr1[,0xaddr2,...]\f[]
298 .PP
299 The reported info (if available in the data file), will be class
300 name, size, creation time, stack trace of creation (with the
301 \f[I]\[em]traces\f[] option), etc.
302 If heapshot data is available it will be possible to also track
303 what other objects reference one of the listed addresses.
304 .PP
305 The object addresses can be gathered either from the profiler
306 report in some cases (like in the monitor lock report), from the
307 live application or they can be selected with the
308 \f[I]\[em]find=FINDSPEC\f[] option.
309 FINDSPEC can be one of the following:
310 .IP \[bu] 2
311 \f[I]S:SIZE\f[]: where the object is selected if it's size is at
312 least \f[I]SIZE\f[]
313 .IP \[bu] 2
314 \f[I]T:NAME\f[]: where the object is selected if \f[I]NAME\f[]
315 partially matches its class name
316 .PP
317 This option can be specified multiple times with one of the
318 different kinds of FINDSPEC.
319 For example, the following:
320 .PP
321 \f[B]--find=S:10000\ --find=T:Byte[]\f[]
322 .PP
323 will find all the byte arrays that are at least 10000 bytes in
324 size.
325 .SS Saving a profiler report
326 .PP
327 By default mprof-report will print the summary data to the console.
328 To print it to a file, instead, use the option:
329 .PP
330 \f[B]--out=FILENAME\f[]
331 .SS Dealing with profiler slowness
332 .PP
333 If the profiler needs to collect lots of data, the execution of the
334 program will slow down significantly, usually 10 to 20 times
335 slower.
336 There are several ways to reduce the impact of the profiler on the
337 program execution.
338 .SS Collect less data
339 .PP
340 Collecting method enter/leave events can be very expensive,
341 especially in programs that perform many millions of tiny calls.
342 The profiler option \f[I]nocalls\f[] can be used to avoid
343 collecting this data or it can be limited to only a few call levels
344 with the \f[I]calldepth\f[] option.
345 .PP
346 Object allocation information is expensive as well, though much
347 less than method enter/leave events.
348 If it's not needed, it can be skipped with the \f[I]noalloc\f[]
349 profiler option.
350 Note that when method enter/leave events are discarded, by default
351 stack traces are collected at each allocation and this can be
352 expensive as well.
353 The impact of stack trace information can be reduced by setting a
354 low value with the \f[I]maxframes\f[] option or by eliminating them
355 completely, by setting it to 0.
356 .PP
357 The other major source of data is the heapshot profiler option:
358 especially if the managed heap is big, since every object needs to
359 be inspected.
360 The \f[I]MODE\f[] parameter of the \f[I]heapshot\f[] option can be
361 used to reduce the frequency of the heap shots.
362 .SS Reduce the timestamp overhead
363 .PP
364 On many operating systems or architectures what actually slows down
365 profiling is the function provided by the system to get timestamp
366 information.
367 The \f[I]time=fast\f[] profiler option can be usually used to speed
368 up this operation, but, depending on the system, time accounting
369 may have some level of approximation (though statistically the data
370 should be still fairly valuable).
371 .SS Use a statistical profiler instead
372 .PP
373 See the mono manpage for the use of a statistical (sampling)
374 profiler.
375 The \f[I]log\f[] profiler will be enhanced to provide sampling info
376 in the future.
377 .SS Dealing with the size of the data files
378 .PP
379 When collecting a lot of information about a profiled program, huge
380 data files can be generated.
381 There are a few ways to minimize the amount of data, for example by
382 not collecting some of the more space-consuming information or by
383 compressing the information on the fly or by just generating a
384 summary report.
385 .SS Reducing the amount of data
386 .PP
387 Method enter/leave events can be excluded completely with the
388 \f[I]nocalls\f[] option or they can be limited to just a few levels
389 of calls with the \f[I]calldepth\f[] option.
390 For example, the option:
391 .PP
392 \f[B]calldepth=10\f[]
393 .PP
394 will ignore the method events when there are more than 10 managed
395 stack frames.
396 This is very useful for programs that have deep recursion or for
397 programs that perform many millions of tiny calls deep enough in
398 the call stack.
399 The optimal number for the calldepth option depends on the program
400 and it needs to be balanced between providing enough profiling
401 information and allowing fast execution speed.
402 .PP
403 Note that by default, if method events are not recorded at all, the
404 profiler will collect stack trace information at events like
405 allocations.
406 To avoid gathering this data, use the \f[I]maxframes=0\f[] profiler
407 option.
408 .PP
409 Allocation events can be eliminated with the \f[I]noalloc\f[]
410 option.
411 .PP
412 Heap shot data can also be huge: by default it is collected at each
413 major collection.
414 To reduce the frequency, you can specify a heapshot mode: for
415 example to collect every 5 collections (including major and minor):
416 .PP
417 \f[B]heapshot=5gc\f[]
418 .PP
419 or when at least 5 seconds passed since the last heap shot:
420 .PP
421 \f[B]heapshot=5000ms\f[]
422 .SS Compressing the data
423 .PP
424 To reduce the amout of disk space used by the data, the data can be
425 compressed either after it has been generated with the gzip
426 command:
427 .PP
428 \f[B]gzip\ -9\ output.mlpd\f[]
429 .PP
430 or it can be compressed automatically by using the \f[I]zip\f[]
431 profiler option.
432 Note that in this case there could be a significant slowdown of the
433 profiled program.
434 .PP
435 The mprof-report program will tranparently deal with either
436 compressed or uncompressed data files.
437 .SS Generating only a summary report
438 .PP
439 Often it's enough to look at the profiler summary report to
440 diagnose an issue and in this case it's possible to avoid saving
441 the profiler data file to disk.
442 This can be accomplished with the \f[I]report\f[] profiler option,
443 which will basically send the data to the mprof-report program for
444 display.
445 .PP
446 To have more control of what summary information is reported (or to
447 use a completely different program to decode the profiler data),
448 the \f[I]output\f[] profiler option can be used, with \f[B]|\f[] as
449 the first character: the rest of the output name will be executed
450 as a program with the data fed in on the standard input.
451 .PP
452 For example, to print only the Monitor summary with stack trace
453 information, you could use it like this:
454 .PP
455 \f[B]output=|mprof-report\ --reports=monitor\ --traces\ -\f[]
456 .SH WEB SITE
457 http://www.mono-project.com/Profiler
458 .SH SEE ALSO
459 .PP
460 mono(1)
461 .SH AUTHORS
462 Paolo Molaro.
463