/usr/share/doc/mlton/guide/ProfilingTime is in mlton-doc 20100608-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="robots" content="index,nofollow">
<title>ProfilingTime - MLton Standard ML Compiler (SML Compiler)</title>
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="all" href="common.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="screen" href="screen.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="print" href="print.css">
<link rel="Start" href="Home">
</head>
<body lang="en" dir="ltr">
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-833377-1";
urchinTracker();
</script>
<table bgcolor = lightblue cellspacing = 0 style = "border: 0px;" width = 100%>
<tr>
<td style = "
border: 0px;
color: darkblue;
font-size: 150%;
text-align: left;">
<a class = mltona href="Home">MLton MLTONWIKIVERSION</a>
<td style = "
border: 0px;
font-size: 150%;
text-align: center;
width: 50%;">
ProfilingTime
<td style = "
border: 0px;
text-align: right;">
<table cellspacing = 0 style = "border: 0px">
<tr style = "vertical-align: middle;">
</table>
<tr style = "background-color: white;">
<td colspan = 3
style = "
border: 0px;
font-size:70%;
text-align: right;">
<a href = "Home">Home</a>
<a href = "TitleIndex">Index</a>
</table>
<div id="content" lang="en" dir="ltr">
With MLton and <tt>mlprof</tt>, you can <a href="Profiling">profile</a> your program to find out how much time is spent in each function over an entire run of the program. To do so, compile your program with <tt>-profile time</tt>. For example, suppose that <tt>tak.sml</tt> contains the following. <p>
<pre class=code><B><FONT COLOR="#0000FF">structure</FONT></B> Tak =
<B><FONT COLOR="#0000FF">struct</FONT></B>
<B><FONT COLOR="#A020F0">fun</FONT></B> tak1 (x, y, z) =
<B><FONT COLOR="#A020F0">let</FONT></B>
<B><FONT COLOR="#A020F0">fun</FONT></B> tak2 (x, y, z) =
<B><FONT COLOR="#A020F0">if</FONT></B> y >= x
<B><FONT COLOR="#A020F0">then</FONT></B> z
<B><FONT COLOR="#A020F0">else</FONT></B>
tak1 (tak2 (x - <B><FONT COLOR="#5F9EA0">1</FONT></B>, y, z),
tak2 (y - <B><FONT COLOR="#5F9EA0">1</FONT></B>, z, x),
tak2 (z - <B><FONT COLOR="#5F9EA0">1</FONT></B>, x, y))
<B><FONT COLOR="#A020F0">in</FONT></B>
<B><FONT COLOR="#A020F0">if</FONT></B> y >= x
<B><FONT COLOR="#A020F0">then</FONT></B> z
<B><FONT COLOR="#A020F0">else</FONT></B>
tak1 (tak2 (x - <B><FONT COLOR="#5F9EA0">1</FONT></B>, y, z),
tak2 (y - <B><FONT COLOR="#5F9EA0">1</FONT></B>, z, x),
tak2 (z - <B><FONT COLOR="#5F9EA0">1</FONT></B>, x, y))
<B><FONT COLOR="#A020F0">end</FONT></B>
<B><FONT COLOR="#0000FF">end</FONT></B>
<B><FONT COLOR="#A020F0">val</FONT></B> <B><FONT COLOR="#A020F0">rec</FONT></B> f =
<B><FONT COLOR="#A020F0">fn</FONT></B> <B><FONT COLOR="#5F9EA0">0</FONT></B> => ()
| ~<B><FONT COLOR="#5F9EA0">1</FONT></B> => print <B><FONT COLOR="#BC8F8F">"this branch is not taken\n"</FONT></B>
| n => (Tak.tak1 (<B><FONT COLOR="#5F9EA0">18</FONT></B>, <B><FONT COLOR="#5F9EA0">12</FONT></B>, <B><FONT COLOR="#5F9EA0">6</FONT></B>) ; f (n-<B><FONT COLOR="#5F9EA0">1</FONT></B>))
<B><FONT COLOR="#A020F0">val</FONT></B> _ = f <B><FONT COLOR="#5F9EA0">5000</FONT></B>
<B><FONT COLOR="#A020F0">fun</FONT></B> uncalled () = ()
</PRE>
</p>
<p>
Compile with time profiling and run the program.
<pre>% mlton -profile time tak.sml
% ./tak
</pre>
</p>
<p>
Display the profiling data.
</p>
<pre>% mlprof tak mlmon.out
6.00 seconds of CPU time (0.00 seconds GC)
function cur
------------- -----
Tak.tak1.tak2 75.8%
Tak.tak1 24.2%
</pre><p>
This example shows how <tt>mlprof</tt> indicates lexical nesting: as a sequence of period-separated names indicating the structures and functions in which a function definition is nested. The profiling data shows that roughly three-quarters of the time is spent in the <tt>Tak.tak1.tak2</tt> function, while the rest is spent in <tt>Tak.tak1</tt>.
</p>
<p>
Display raw counts in addition to percentages with <tt>-raw true</tt>.
<pre>% mlprof -raw true tak mlmon.out
6.00 seconds of CPU time (0.00 seconds GC)
function cur raw
------------- ----- -------
Tak.tak1.tak2 75.8% (4.55s)
Tak.tak1 24.2% (1.45s)
</pre>
</p>
<p>
Display the file name and line number for each function in addition to its name with <tt>-show-line true</tt>.
<pre>% mlprof -show-line true tak mlmon.out
6.00 seconds of CPU time (0.00 seconds GC)
function cur
------------------------- -----
Tak.tak1.tak2 tak.sml: 5 75.8%
Tak.tak1 tak.sml: 3 24.2%
</pre>
</p>
<p>
Time profiling is designed to have a very small performance impact. However, in some cases there will be a run-time performance cost, which may perturb the results. There is more likely to be an impact with <tt>-codegen c</tt> than <tt>-codegen native</tt>.
</p>
<p>
You can also compile with <tt>-profile time -profile-branch true</tt> to find out how much time is spent in each branch of a function; see <a href="ProfilingCounts">ProfilingCounts</a> for more details on <tt>-profile-branch</tt>.
</p>
<h2 id="head-bcaa33a7ae44bd5042c37a9cdbea7f843b1cf7c8">Caveats</h2>
<p>
With <tt>-profile time</tt>, use of the following in your program will cause a run-time error, since they would interfere with the profiler signal handler.
</p>
<ul>
<li>
<p>
<tt>MLton.Itimer.set (MLton.Itimer.Prof, ...)</tt>
</p>
</li>
<li>
<p>
<tt>MLton.Signal.setHandler (MLton.Signal.prof, ...)</tt>
</p>
</li>
</ul>
<p>
Also, because of the random sampling used to implement <tt>-profile time</tt>, it is best to have a long running program (at least tens of seconds) in order to get reasonable time
</p>
</div>
<p>
<hr>
Last edited on 2006-11-02 17:38:19 by <span title="76.16.241.4"><a href="MatthewFluet">MatthewFluet</a></span>.
</body></html>
|