Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / ProfilingTheStack.adoc
CommitLineData
7f918cf1
CE
1ProfilingTheStack
2=================
3
4For all forms of <:Profiling:>, you can gather counts for all
5functions on the stack, not just the currently executing function. To
6do so, compile your program with `-profile-stack true`. For example,
7suppose that `list-rev.sml` contains the following.
8
9[source,sml]
10----
11sys::[./bin/InclGitFile.py mlton master doc/examples/profiling/list-rev.sml]
12----
13
14Compile with stack profiling and then run the program.
15----
16% mlton -profile alloc -profile-stack true list-rev.sml
17% ./list-rev
18----
19
20Display the profiling data.
21----
22% mlprof -show-line true list-rev mlmon.out
236,030,136 bytes allocated (108,336 bytes by GC)
24 function cur stack GC
25----------------------- ----- ----- ----
26append list-rev.sml: 1 97.6% 97.6% 1.4%
27<gc> 1.8% 0.0% 1.8%
28<main> 0.4% 98.2% 1.8%
29rev list-rev.sml: 6 0.2% 97.6% 1.8%
30----
31
32In the above table, we see that `rev`, defined on line 6 of
33`list-rev.sml`, is only responsible for 0.2% of the allocation, but is
34on the stack while 97.6% of the allocation is done by the user program
35and while 1.8% of the allocation is done by the garbage collector.
36
37The run-time performance impact of `-profile-stack true` can be
38noticeable since there is some extra bookkeeping at every nontail call
39and return.