<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>callstats &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/callstats/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 03 Oct 2012 18:00:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>Undocumented Profiler options part 4</title>
		<link>https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-4?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=undocumented-profiler-options-part-4</link>
					<comments>https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-4#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 03 Oct 2012 18:00:54 +0000</pubDate>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[callstats]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Profiler]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3206</guid>

					<description><![CDATA[<p>Several undocumented features of the Matlab Profiler can make it much more useful - part 4 of series. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-4">Undocumented Profiler options part 4</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-3" rel="bookmark" title="Undocumented Profiler options part 3">Undocumented Profiler options part 3 </a> <small>An undocumented feature of the Matlab Profiler can report call history timeline - part 3 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options" rel="bookmark" title="Undocumented profiler options">Undocumented profiler options </a> <small>The Matlab profiler has some undocumented options that facilitate debugging memory bottlenecks and JIT (Just-In-Time Java compilation) problems....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-2" rel="bookmark" title="Undocumented Profiler options part 2">Undocumented Profiler options part 2 </a> <small>Several undocumented features of the Matlab Profiler can make it much more useful - part 2 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/buggy-profiler-option" rel="bookmark" title="Buggy Profiler option">Buggy Profiler option </a> <small>a bug exists in the profiler that prevents usage of its documented CPU timing functionality. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Today&#8217;s article concludes my series on undocumented features of the Matlab Profiler. Past articles explained how to <a target="_blank" href="/articles/undocumented-profiler-options/">profile memory</a>, <a target="_blank" href="/articles/undocumented-profiler-options-part-2/">improve timing resolution and fix a font issue</a>, and <a target="_blank" href="/articles/undocumented-profiler-options-part-3">display the call history</a>. Today&#8217;s article will explain undocumented switches of the <i><b>profile</b></i> function that can be used to profile built-in functions, to report and remove the profiling overhead, plus a couple of as-yet-unsolved mysteries.</p>
<h3 id="builtins">Profiling built-in functions</h3>
<p>Built-in functions (e.g., <i><b>isempty, length, find</b></i>) are not monitored or displayed in the profiling summary by default. They are also not linkable to a detailed profiling report in the detailed report of any user function. So, if we have a code line such as the following, we cannot know how much time is spent in <i><b>length, find</b></i> as opposed to being spent in <i>userFunction</i>:</p>
<pre lang='matlab'>numResults = length(find(userFunction()));</pre>
<p>However, we can tell the profile to monitor and display built-in functions using the undocumented optional <code>-detail builtin</code> switch of the <i><b>profile</b></i> function:</p>
<pre lang='matlab'>
profile on –detail builtin
profile('on','-detail','builtin')   % an equivalent alternative
</pre>
<p>Alternately, we can use the undocumented built-in function <i><b>callstats</b></i> directly (as I already explained, the <i><b>profile</b></i> function is simply a convenient wrapper function to <i><b>callstats</b></i>):</p>
<pre lang='matlab'>callstats('level', 2);  % 1=mmex, 2=builtin</pre>
<p>The built-in functions will now be reported in the profiling summary and detailed reports, and will be linkable within the code lines of the detailed report.<br />
Note: old MATLAB releases also supported the &#8216;operator&#8217; detail level, which provided profiling information about built-in operators such as +. However, this level of detail is no longer supported in the latest MATLAB releases.<br />
The <i>-detail</i> switch can also be used with other <i><b>profile</b></i> switches. For example:</p>
<pre lang='matlab'>>> profile('on','-detail','builtin','-timestamp'); surf(peaks); profile('off')</pre>
<p>To return to the standard profiling level (&#8216;mmex&#8217;), run one of the following:</p>
<pre lang='matlab'>
profile on –detail mmex
profile('on','-detail','mmex')   % an equivalent alternative
callstats('level', 1);           % an equivalent alternative
</pre>
<h3 id="overhead">Profiling overhead removal</h3>
<p>The <code>-remove_overhead</code> switch checks the profiler&#8217;s own overhead and knows to remove this overhead from all relevant timing values. This is normally off by default, and returns <code>profData.overhead=0</code>. When turned on, it stores the computed profiling overhead in <code>profData.overhead</code>:<br />
<span id="more-3206"></span></p>
<pre lang='matlab'>
profile -remove_overhead on
profile('-remove_overhead','on')        % equivalent alternative
callstats('remove_sample_overhead',1);  % equivalent alternative
</pre>
<p>We need to make a small fix to the <i><b>profview</b></i> function (<i>%matlabroot%/toolbox/matlab/codetools/profview.m</i>), otherwise the profiling report will croak on an error. The fix is simple: replace the following code segment (lines #351-355 in the <i>profview.m</i> file of R2012a)</p>
<pre lang='matlab' escaped="true">
if profileInfo.Overhead==0
    s{end+1} = sprintf(['&lt;p&gt;<a name="selftimedef"></a>', getString(message('MATLAB:profiler:SelfTime1st')) ' ']);
else
    s{end+1} = sprintf(['&lt;p&gt;<a name="selftimedef"></a>', getString(message('MATLAB:profiler:SelfTime2nd', profileInfo.Overhead))]);
end
</pre>
<p>with this (changed line highlighted &#8211; note the extra <i><b>num2str</b></i>):</p>
<pre lang='matlab' escaped="true" highlight="4">
if profileInfo.Overhead==0
    s{end+1} = sprintf(['&lt;p&gt;<a name="selftimedef"></a>', getString(message('MATLAB:profiler:SelfTime1st')) ' ']);
else
    s{end+1} = sprintf(['&lt;p&gt;<a name="selftimedef"></a>', getString(message('MATLAB:profiler:SelfTime2nd', num2str(profileInfo.Overhead)))]);
end
</pre>
<p>Turning the overhead switch on causes the message at the bottom of the profiling summary report to change, from something that says:</p>
<blockquote><p>Self time is the time spent in a function excluding the time spent in its child functions. Self time also includes overhead resulting from the process of profiling. </p></blockquote>
<p>To this (the numeric value is the computed overhead, also reported in <code>profData.overhead</code>):</p>
<blockquote><p>Self time is the time spent in a function excluding both the time spent in its child functions and most of the overhead resulting from the process of profiling. <br />In the present run, self time excludes 0.80601 seconds of profiling overhead. The amount of remaining overhead reflected in self time cannot be determined.</p></blockquote>
<p>A similar customization needs to be done to fix an error arising from the use of the undocumented <i><b>profile -timer none</b></i> option. I don&#8217;t really see great value in running a Profiler without timing information, so I&#8217;ll skip this part here. If anyone has an idea what this could be used for, I&#8217;d be happy to hear.</p>
<h3 id="mysteries">[As-yet] unsolved mysteries</h3>
<p>To conclude my series on undocumented profiling options, a couple of unsolved mysteries:</p>
<h4 id="HW">hardware profiling</h4>
<p>The <i><b>profview.m</b></i> function has several references to hardware performance counter data, which, if available as fields in <code>profData.FunctionTable</code>, are displayed as separate columns to the left of the time column field in the code section, and also enabled for the sorting and highlighting drop-downs in the detailed profiling report. Separate monitored hardware events are stored in separate fields named <code>profData.FunctionTable.HW<i>event</i></code> (see the <i>getHwFields()</i> sub-function on lines 1557-1564). The mystery: how can we tell the Profiler to start hardware monitoring in a way that would add these HW fields to the collected <code>profData.FunctionTable</code>? Lines 1652-1653 give a hint:</p>
<pre lang='matlab'>
hw_events = callstats('hw_events');
match = strcmpi(['hw_' str],hw_events);
</pre>
<p>Unfortunately, at least on my system, <code>callstats('hw_events')</code> returns an empty cell array:</p>
<pre lang='matlab'>
>> hw_events = callstats('hw_events')
hw_events =
   Empty cell array: 1-by-0
</pre>
<p>So if anyone has an idea how to use these HW events, I&#8217;d be happy to hear &#8211; please leave a <a href="/articles/undocumented-profiler-options-part-4#respond">comment</a> below.</p>
<h4 id="parallel">parallel profiling</h4>
<p>Another mystery relates to the question of how to profile parallel Matlab code. The underlying Java object of the Profiler tool (<code>com.mathworks.mde.profiler.Profiler.getInstance</code>) contains the following tell-tale methods:<br />
<i></p>
<ul>
<li>getHtmlTextParallel(), setHtmlTextParallel()</li>
<li>getInstanceWithParallelOpts()</li>
<li>getSelectedLabsFromHtml()</li>
<li>setNumLabs()</li>
<li>setNumLabsParallel()</li>
<li>setSelectedLab()</li>
</ul>
<p></i><br />
I would have expected the parallel-enabled Profiler to be started using <code>com.mathworks.mde.profiler.Profiler.getInstanceWithParallelOpts.invoke()</code>. This does indeed start the Profiler, but I can&#8217;t see any difference between its output and that of the normal Profiler, even when I run parallel (<i><b>parfor</b></i>) code. It  definitely does not look like output from the Parallel Computing Toolbox (PCT)&#8217;s <i><b>mpiprofile</b></i> function.<br />
Perhaps these methods are used by <i><b>mpiprofile</b></i> internally? It could make sense for both <i><b>profile</b></i> and <i><b>mpiprofile</b></i> to share the same underlying profiler tool. On the other hand, if this were indeed the case then why would there be a reason for a separate <i><b>mpiprofile</b></i> function? Wouldn&#8217;t the standard <i><b>profile</b></i> function be sufficient?<br />
Anyway, if anyone has an idea how to use these methods in the standard profiler, perhaps to profile parallel applications without the need for <i><b>pmode</b></i>, I&#8217;d be happy to hear &#8211; please leave a <a href="/articles/undocumented-profiler-options-part-4#respond">comment</a> below.</p>
<h3 id="conclusion">Conclusion</h3>
<p>The Matlab Profiler has quite a few important features, which for some unknown reason have not been made public. Matlab&#8217;s Profiler has remained stagnant since Matlab 7 was released last decade. In fact, some functionality, like the <a target="_blank" href="/articles/undocumented-profiler-options/">JIT information feature</a>, was actually removed. Hopefully, future Matlab releases will improve the Profiler, by making these undocumented features officially supported, as well as by adding other important functionality.<br />
This concludes my series on undocumented profiling features in Matlab. If anyone knows any other Profiler tricks, please share them in a <a href="/articles/undocumented-profiler-options-part-4#respond">comment</a> below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-4">Undocumented Profiler options part 4</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-3" rel="bookmark" title="Undocumented Profiler options part 3">Undocumented Profiler options part 3 </a> <small>An undocumented feature of the Matlab Profiler can report call history timeline - part 3 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options" rel="bookmark" title="Undocumented profiler options">Undocumented profiler options </a> <small>The Matlab profiler has some undocumented options that facilitate debugging memory bottlenecks and JIT (Just-In-Time Java compilation) problems....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-2" rel="bookmark" title="Undocumented Profiler options part 2">Undocumented Profiler options part 2 </a> <small>Several undocumented features of the Matlab Profiler can make it much more useful - part 2 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/buggy-profiler-option" rel="bookmark" title="Buggy Profiler option">Buggy Profiler option </a> <small>a bug exists in the profiler that prevents usage of its documented CPU timing functionality. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-4/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Undocumented Profiler options part 3</title>
		<link>https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-3?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=undocumented-profiler-options-part-3</link>
					<comments>https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-3#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 26 Sep 2012 18:00:02 +0000</pubDate>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[callstats]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Profiler]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3158</guid>

					<description><![CDATA[<p>An undocumented feature of the Matlab Profiler can report call history timeline - part 3 of series. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-3">Undocumented Profiler options part 3</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-4" rel="bookmark" title="Undocumented Profiler options part 4">Undocumented Profiler options part 4 </a> <small>Several undocumented features of the Matlab Profiler can make it much more useful - part 4 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options" rel="bookmark" title="Undocumented profiler options">Undocumented profiler options </a> <small>The Matlab profiler has some undocumented options that facilitate debugging memory bottlenecks and JIT (Just-In-Time Java compilation) problems....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-2" rel="bookmark" title="Undocumented Profiler options part 2">Undocumented Profiler options part 2 </a> <small>Several undocumented features of the Matlab Profiler can make it much more useful - part 2 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/buggy-profiler-option" rel="bookmark" title="Buggy Profiler option">Buggy Profiler option </a> <small>a bug exists in the profiler that prevents usage of its documented CPU timing functionality. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Today&#8217;s article continues my series on undocumented features of the Matlab Profiler. Past articles explained how to <a target="_blank" href="/articles/undocumented-profiler-options/">profile memory</a>, <a target="_blank" href="/articles/undocumented-profiler-options-part-2/">improve timing resolution and fix a font issue</a>. Today&#8217;s article will explain undocumented switches of the <i><b>profile</b></i> function that can be used to provide detailed history timeline of the function calls. Next week&#8217;s article will conclude the series by explaining undocumented switches of the profile function that can be used to profile built-in functions, to report and remove the profiling overhead, plus a couple of as-yet-unsolved mysteries.</p>
<h3 id="history">Simple call history</h3>
<p>One of the features that the programmatic profiling interface provides, and which is not represented in the Profiler GUI, is a report of the exact order in which different functions were called during the profiling session. This profiling history can be turned on using the <code>–history</code> switch. There is also an optional switch of <code>–historysize</code>, which enables us to modify the history size from a default maximum of 1 million function entry and exit items. Here is a sample usage of this history feature:</p>
<pre lang='matlab'>
>> profile('on','-history'); surf(peaks); profile('off')
>> profData = profile('info');
>> history = profData.FunctionHistory
history =
  Columns 1 through 11
     0     0     0     1     0     1     0     1     1     1     0
    19     1    17    17    17    17    18    18     1    19     5
  ...
</pre>
<p>The history data is actually a numeric matrix, where the first row contains the values 0 (=function entry) or 1 (=function exit), and the second row is the corresponding index into <code>profData.FunctionTable</code>, indicating the called function. We can easily convert this matrix into human-readable form using the following code snippet:</p>
<pre lang='matlab'>
offset = cumsum(1-2*history(1,:)) - 1;  % calling depth
entryIdx = history(1,:)==1;     % history items of function entries
funcIdx = history(2,entryIdx);  % indexes of relevant functions
funcNames = {profData.FunctionTable(funcIdx).FunctionName};
for idx = 1: length(funcNames);
   disp([repmat(' ',1,offset(idx)) funcNames{idx}]);
end
</pre>
<p>which generates the following calling list in the MATLAB Command Window:</p>
<pre lang='matlab'>
isempty
 isempty
  transpose
 meshgrid
  peaks
 nargchk
  error
 ishg2parent
...
</pre>
<p>Unfortunately, the history information does not by default contain specific timing of each function entry/exit, but we can still make good use of it by looking at the sequence in which the functions were called from each other.</p>
<h3 id="detailed">Detailed call history, with timing information</h3>
<p>In order to retrieve actual history timing information, we can run profile with the undocumented/unsupported <code>–timestamp</code> switch, which stores the CPU clock next to the history information. The reported history matrix now has 4 rows rather than 2, where the extra rows represents the timestamp of each function entry/exit:<br />
<span id="more-3158"></span></p>
<pre lang='matlab'>
>> profile('on','-timestamp'); surf(peaks); profile('off')
>> profData = profile('info');
>> profData.FunctionHistory(:,1:3)
ans =
                0                0                1
                1                2                2
       1347473710       1347473710       1347473710
           453000           453000           468000
</pre>
<p>In this report, the 3rd row represents the timestamp in seconds, while the 4th row represents the fractional portion of the timestamp, in microseconds. In the example above, the first timestamp item corresponds to 1347473710.453 seconds.<br />
The seconds value appears to be related to the number of seconds since midnight Jan 1, 1970 (so-called <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Unix_time"><i>Epoch</i></a>), which is a standard time representation in computing systems. However, the actual value appears to be off by slightly over a day from the expected value (which is retrievable via <code>getTime(java.util.Date)</code>) for some unknown reason. Since we are only interested in <i>relative</i>, rather than <i>absolute</i> times when profiling, this minor difference does not affect us.<br />
The timeline of the profiling session can be visualized as follows:</p>
<pre lang='matlab'>
histData = profData.FunctionHistory;
startTime     = histData(3,1) + histData(4,1)/1e6;
relativeTimes = histData(3,:) + histData(4,:)/1e6 - startTime;
plot(relativeTimes);
</pre>
<p><center><figure style="width: 494px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" alt="Profiling history timeline" src="https://undocumentedmatlab.com/images/Profiler2.png" title="Profiling history timeline" width="494" height="385" /><figcaption class="wp-caption-text">Profiling history timeline</figcaption></figure></center><br />
This report helps us see that a particular set of function calls, around the 100th call mark, is responsible for about 0.5 seconds, a prime candidate for tuning investigation. If we only relied on the standard profiling report we might have missed this because it might have been meshed into the same &#8220;bucket&#8221; as other invocations of the same function. As illustration, take the following simulated example:</p>
<pre lang='matlab'>
Invocation  #1 of func():  0.500 secs
Invocation  #2 of func():  0.013 secs
Invocation  #3 of func():  0.011 secs
   ...
Invocation #10 of func():  0.012 secs
_____________________________________
Total invocation time:     0.600 secs
</pre>
<p>In this simulation, we would not have known that the 0.6 secs invocation time of <i>func()</i> is not really evenly distributed across all 10 invocations, and this would lead us to incorrect conclusions. For example, we could spend time unnecessarily on tuning the steady-state run-time performance of the function, whereas we should really have concentrated on only the first invocation. By looking at the actual timestamps we could see the large run-time used by the first invocation and this information can possibly be used to tune this first invocation and significantly reduce the overall time taken by the function.<br />
Note: instead of using <i><b>profile -timestamp</b></i>, we could also have used the undocumented built-in function <i><b>callstats</b></i>, which is the underlying profiling engine (the <i><b>profile</b></i> function is simply a convenient wrapper function to <i><b>callstats</b></i> – take a look within <i>profile.m</i>):</p>
<pre lang='matlab'>callstats('history',2);  % 0 = -nohistory, 1 = -history, 2 = -timestamp</pre>
<p>History collection has an overhead, so if you don&#8217;t need it then you should turn it off:</p>
<pre lang='matlab'>
profile -nohistory
profile('-nohistory')    % equivalent alternative
callstats('history',0);  % equivalent alternative
</pre>
<p><b><u>Addendum</u> (June 16th, 2014):</b> I have created a utility (<code>profile_history</code>, available on the <a href="http://www.mathworks.com/matlabcentral/fileexchange/46976-profile-history-display-graphical-profiling-timline-data" rel="nofollow" target="_blank">Matlab File Exchange</a>) that parses all this profile data and presents it in an interactive GUI. See <a href="/articles/function-call-timeline-profiling" target="_blank">this article</a> for details.<br />
<center><a target="_blank" href="/images/profile_history.png"><img decoding="async" alt="Function call timeline profiling (click for full-size image)" src="https://undocumentedmatlab.com/images/profile_history.png" title="Function call timeline profiling (click for full-size image)" width="100%" style="max-width: 658px;" /></a><br />
Function call timeline profiling (click for full-size image)</center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-3">Undocumented Profiler options part 3</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-4" rel="bookmark" title="Undocumented Profiler options part 4">Undocumented Profiler options part 4 </a> <small>Several undocumented features of the Matlab Profiler can make it much more useful - part 4 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options" rel="bookmark" title="Undocumented profiler options">Undocumented profiler options </a> <small>The Matlab profiler has some undocumented options that facilitate debugging memory bottlenecks and JIT (Just-In-Time Java compilation) problems....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-2" rel="bookmark" title="Undocumented Profiler options part 2">Undocumented Profiler options part 2 </a> <small>Several undocumented features of the Matlab Profiler can make it much more useful - part 2 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/buggy-profiler-option" rel="bookmark" title="Buggy Profiler option">Buggy Profiler option </a> <small>a bug exists in the profiler that prevents usage of its documented CPU timing functionality. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-3/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Undocumented profiler options</title>
		<link>https://undocumentedmatlab.com/articles/undocumented-profiler-options?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=undocumented-profiler-options</link>
					<comments>https://undocumentedmatlab.com/articles/undocumented-profiler-options#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 02 Apr 2009 22:24:25 +0000</pubDate>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[callstats]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Profiler]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=143</guid>

					<description><![CDATA[<p>The Matlab profiler has some undocumented options that facilitate debugging memory bottlenecks and JIT (Just-In-Time Java compilation) problems.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/undocumented-profiler-options">Undocumented profiler options</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-3" rel="bookmark" title="Undocumented Profiler options part 3">Undocumented Profiler options part 3 </a> <small>An undocumented feature of the Matlab Profiler can report call history timeline - part 3 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-2" rel="bookmark" title="Undocumented Profiler options part 2">Undocumented Profiler options part 2 </a> <small>Several undocumented features of the Matlab Profiler can make it much more useful - part 2 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-4" rel="bookmark" title="Undocumented Profiler options part 4">Undocumented Profiler options part 4 </a> <small>Several undocumented features of the Matlab Profiler can make it much more useful - part 4 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/buggy-profiler-option" rel="bookmark" title="Buggy Profiler option">Buggy Profiler option </a> <small>a bug exists in the profiler that prevents usage of its documented CPU timing functionality. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>The Matlab profiler is a powerful tool for debugging performance-related issues in Matlab applications. However, it also has some undocumented options that facilitate other forms of debugging, namely memory bottlenecks and JIT (Just-In-Time compilation) problems.<br />
To turn on memory stats in the profile report, run this (only once is necessary &#8211; will be remembered for future profiling runs):</p>
<blockquote>
<pre>profile -memory on;
profile(<span style="color: #800080;">'-memory','on'</span>);  <span style="color: #008000;">% an alternative</span></pre>
</blockquote>
<p>To turn on JIT information, run this (again, only once is necessary, prior to profile report):</p>
<blockquote>
<pre>setpref(<span style="color: #800080;">'profiler','showJitLines'</span>,1);</pre>
</blockquote>
<p>You will then see additional JIT and memory (allocated, freed and peak) information displayed in the profile report, as well as the options to sort by allocated, freed and peak memory:<br />
<figure style="width: 450px" class="wp-caption aligncenter"><br />
<img decoding="async" title="Profile report with memory &amp; JIT info" src="https://undocumentedmatlab.com/images/profile2d_450.png" alt="Profile report with memory &amp; JIT info" width="450" /><img decoding="async" title="Profile report with memory &amp; JIT info" src="https://undocumentedmatlab.com/images/profile2c_450.png" alt="Profile report with memory &amp; JIT info" width="450" /><br />
<img decoding="async" title="Profile report with memory &amp; JIT info" src="https://undocumentedmatlab.com/images/profile2.png" alt="Profile report with memory &amp; JIT info" width="416" /><br />
<figcaption class="wp-caption-text">Profile report with memory &amp; JIT info</figcaption></figure><br />
For those interested, the references to these two options appear within the code of profview.m (line 1199 on R2007b), for the JIT option:</p>
<blockquote>
<pre>showJitLines = getpref(<span style="color: #800080;">'profiler','showJitLines'</span>,false);</pre>
</blockquote>
<p>&#8230;and profile.m (lines 163-165 on R2007b), for the memory option:</p>
<blockquote>
<pre><span style="color: #0000ff;">if</span> memory ~= -1
    callstats(<span style="color: #800080;">'memory'</span>, memory);
<span style="color: #0000ff;">end</span></pre>
</blockquote>
<p>Note that there appears to be two undocumented additional memory-related options in profile.m (lines 311-312):</p>
<blockquote>
<pre>options = {<span style="color: #800080;">'detail', 'timer', 'history', 'nohistory', 'historysize'</span>, ...
           <span style="color: #800080;">'timestamp', 'memory', 'callmemory', 'nomemory'</span> };</pre>
</blockquote>
<p>However, &#8216;-nomemory&#8217; appears to simply turn the memory stats collection off, and &#8216;-callmemory&#8217; is not recognized because of a bug in line 349, which looks for &#8216;call<strong>no</strong>memory&#8217;&#8230;:</p>
<blockquote>
<pre>    <span style="color: #0000ff;">case </span><span style="color: #800080;">'callnomemory'</span>   <span style="color: #008000;">% should be 'callmemory'</span>
           memory = 2;</pre>
</blockquote>
<p>When this bug is fixed, we see that we get only partial memory information, so the &#8216;-callmemory&#8217; option is really not useful &#8211; use &#8216;-memory&#8217; instead.<br />
<b><u>Addendum (Jan 31, 2011):</u> JIT information has been removed in Matlab 7.12 (R2011a). I assume that this was done so that programmers will not attempt to depend on JITC functionality in their code (see <a href="/articles/undocumented-profiler-options/#comment-64">Michelle Hirsch&#8217;s comment</a> below). It&#8217;s a good thing that the memory options remain, since these are quite useful in profiling memory-related bottlenecks.</b></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/undocumented-profiler-options">Undocumented profiler options</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-3" rel="bookmark" title="Undocumented Profiler options part 3">Undocumented Profiler options part 3 </a> <small>An undocumented feature of the Matlab Profiler can report call history timeline - part 3 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-2" rel="bookmark" title="Undocumented Profiler options part 2">Undocumented Profiler options part 2 </a> <small>Several undocumented features of the Matlab Profiler can make it much more useful - part 2 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-profiler-options-part-4" rel="bookmark" title="Undocumented Profiler options part 4">Undocumented Profiler options part 4 </a> <small>Several undocumented features of the Matlab Profiler can make it much more useful - part 4 of series. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/buggy-profiler-option" rel="bookmark" title="Buggy Profiler option">Buggy Profiler option </a> <small>a bug exists in the profiler that prevents usage of its documented CPU timing functionality. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/undocumented-profiler-options/feed</wfw:commentRss>
			<slash:comments>23</slash:comments>
		
		
			</item>
	</channel>
</rss>
