💾 Archived View for blitter.com › apl-books › APLX50 › APLX-manual › www.microapl.com › apl_help › c… captured on 2024-08-18 at 20:34:22.

View Raw

More Information

⬅️ Previous capture (2022-07-17)

-=-=-=-=-=-=-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Performance Profiling</TITLE>
<META NAME="DESCRIPTION" CONTENT="APL language help page: Performance Profiling">
<META NAME="KEYWORDS" CONTENT="performance,profiling,CPU time,execution time,apl,aplx,apl help">
<!-- %%COMMON_HEAD%% -->
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK rel="stylesheet" type="text/css" href="http://www.microapl.com/styles_apl_help.css">
<!-- %%END%%-->
</HEAD>
<body>
<table>
<tr>
<td width="800" valign="top" colspan="2">
<center>Topic: <A HREF="ch.htm"><code>APLX Help</code></A> :  <A HREF="ch_202.htm"><code>Performance Profiling</code></A> 
</center>
<center>
[ <A HREF="ch.htm">Contents</A> | <A HREF="help_index.htm">Index</A>  | <A HREF="http://www.microapl.co.uk/apl/index.html">APL Home</A> ]</center>
<br></td>
</tr>
<tr>
<td width="120">
<a href="http://www.microapl.co.uk/apl/index.html"><img height="68" border="0" width="119" src="MicroAPL_logo.gif" alt="www.microapl.co.uk"></a>
</td>
<td align="left" valign="bottom">
<h1>Performance Profiling</h1>
</td>
</tr>
<tr>
<td width="800" valign="top" colspan="2">
<hr>
<H2>Overview</H2>

<p>Performance profiling can be used to find out which parts of your APL code take the most time to execute, or are executed most often, and so helps you to determine which functions to concentrate on when optimising performance.  You can view the performance data in a number of different ways, and easily 'drill down' to get more detail on exactly where execution time is spent. You can either use the very easy menu-based profiling described below, or for more detailed control use <A HREF="ch_020_070_655.htm"><code>&#9109;PROFILE</code> </A>.</p>

<H2>Profiling using the Tools menu</H2>

<p>For simple profiling you can enable profiling through the APLX Tools menu.  You then run the code to be profiled. When the code completes and APLX returns to desktop calculator mode, the profile is automatically shown in a Profile window.</p>

<p>When you select 'Performance Profiling' from the Tools menu, APLX brings up a dialog which offers you a choice of different methods for measuring the execution time:</p>

<center><img src="profiler1.jpg" width="384" height="329" border="0"></center>

<p>Depending on which platform you are using, one or more of the timing methods may not be available. For example, earlier versions of Windows cannot measure the number of CPU cycles used by an application. If the method specified is not available it will be disabled in the dialog.  Measuring CPU cycles, if available, usually gives the most accurate results.  (See the description of <A HREF="ch_020_070_655.htm"><code>&#9109;PROFILE</code> </A> for more details on the different measures.)</p>

<p>Once you click OK on this dialog, profiling is enabled.  You then run your APL code (a function, which in turn will typically call many other functions, and can ask for input from the user as part of its operation).  As soon as the function finally completes or is interrupted, and APL returns to desk calculator mode, profiling is automatically disabled and the results window will open.</p>

<p>In this example (based on the <tt>HELPOBJECTS</tt> workspace supplied with APLX in library 10), we have executed a function called <code>RUN</code> which has created various graphics objects in a rotating pattern, and displayed them.  On completion, the following window opens:</p>
<center><img src="profiler2.jpg" width="962" height="540" border="0"></center>

<p>As you can see, the results are displayed on five tabs.  The first tab ("By Line") tells you which individual function lines have taken the most CPU (or elapsed) time, as shown above.  They are initially sorted with the one which has taken the most time first, but you can change the sort criteria by clicking on the header of a column.</p>

<H3>CPU usage by line</H3>

<p>In our example, the function line which has been most CPU-intensive is line 6 of <code>SHAPE.Rotate</code>, i.e. the <code>Rotate</code> method of the <code>SHAPE</code> class.  This is highlighted in red in the above picture.  As a convenience, the corresponding line of code is shown in the second column; you will see that it is an inner product <code>B+.&#215;MAT</code> (highlighted in green).  This line has been called 13,646 times, and accounts for 37.63% of the total execution time, or in absolute terms 7.797 billion CPU cycles (highlighted in blue in the picture).  The next two most CPU-intensive lines were lines 7 and 13 of the <code>SHAPE.Draw</code> method, which took a further 10.94% and 10.29% of the total execution time respectively. In other words, nearly 60% of the total execution time was spent in just three lines of the application.  Clearly, therefore, if you were wanting to optimise the code, you would see if you can reduce the number of times these critical lines are executed, or write them in a more efficient way.</p>

<p>The critical information is usually in the column shown as 'Self Only'.  This relates to the CPU usage for the line itself, excluding any functions called by the line.  The next column ('Self+Children') displays the time taken both in the line itself and in any functions called.  In our example, line 12 of <code>STAR.GetPolygon</code> has taken 39.34% of the total time, if you include the functions called by it, but only 1.79% was spent in <code>STAR.GetPolygon[12]</code> itself (highlighted in brown).  In fact, most of that time was actually spent in the inner product highlighted at the top of the display.</p>

<p>By selecting the 'Graph By Line' tab, you can get an immediate graphical representation of which lines took the most CPU time:</p>

<center><img src="profiler7.jpg" width="770" height="532" border="0"></center>

<H3>CPU usage by function</H3>

<p>As well as looking at individual lines, you can also get an overview of which functions (and methods) took the most time, by selecting the second tab of the results window ('By Function'):</p>

<center><img src="profiler3.jpg" width="965" height="540" border="0"></center>

<p>From this display you can 'drill down' within a given function, to find out where the time is spent in that function, by clicking on the twist-down by the function name:</p>

<center><img src="profiler4.jpg" width="965" height="540" border="0"></center>

<p>The 'Graph By Function' tab shows the overview by function as a pie chart.</p>

<H3>CPU usage by Call Chain</H3>

<p>The third way of looking at the data is by <i>call chain</i>.  This is best shown by our example:</p>

<center><img src="profiler5.jpg" width="451" height="248" border="0"></center>

<p>This shows that, unsurprisingly, 100% of the time was spent in our top-level function <code>RUN</code> and in all the functions called by it.  We can now use the twist-downs to drill down into the the hierarchies of calls to see how that time was divided up:</p>

<center><img src="profiler6.jpg" width="448" height="259" border="0"></center>

<H3>Saving the profiling data as a web page</H3>

<P>As well as looking at the data in the APLX window, you can select 'Save As Web Page' from the File menu.  This saves a complete report (either as a summary of the most important items only, or of the whole application), as a web page which you can load in any standard browser.</p>
 
<hr>
</td>
</tr>
<tr>
<td width="800" valign="top" colspan="2">
<center>Topic: <A HREF="ch.htm"><code>APLX Help</code></A> :  <A HREF="ch_202.htm"><code>Performance Profiling</code></A> 
</center>
<center>
[ <A HREF="ch.htm">Contents</A> | <A HREF="help_index.htm">Index</A>  | <A HREF="http://www.microapl.co.uk/apl/index.html">APL Home</A> ]</center>
<br></td>
</tr>
</table>
<!-- %%COMMON_BODY_TAIL%% -->
<p class="copyright">Copyright &copy; 1996-2010 MicroAPL Ltd</p>
<!-- %%END%% -->
</body>
</html>