Sophie

Sophie

distrib > Fedora > 17 > i386 > media > updates > by-pkgid > 675c8c8167236dfcf8d66da674f931e8 > files > 1513

erlang-doc-R15B-03.3.fc17.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css">
<title>Erlang -- fprof - The File Trace Profiler</title>
</head>
<body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container">
<script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript">
            <!--
              function getWinHeight() {
                var myHeight = 0;
                if( typeof( window.innerHeight ) == 'number' ) {
                  //Non-IE
                  myHeight = window.innerHeight;
                } else if( document.documentElement && ( document.documentElement.clientWidth ||
                                                         document.documentElement.clientHeight ) ) {
                  //IE 6+ in 'standards compliant mode'
                  myHeight = document.documentElement.clientHeight;
                } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                  //IE 4 compatible
                  myHeight = document.body.clientHeight;
                }
                return myHeight;
              }

              function setscrollpos() {
                var objf=document.getElementById('loadscrollpos');
                 document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2;
              }

              function addEvent(obj, evType, fn){
                if (obj.addEventListener){
                obj.addEventListener(evType, fn, true);
                return true;
              } else if (obj.attachEvent){
                var r = obj.attachEvent("on"+evType, fn);
                return r;
              } else {
                return false;
              }
             }

             addEvent(window, 'load', setscrollpos);

             //--></script><div id="leftnav"><div class="innertube">
<img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/tools-2.6.8.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>Tools</strong><br><strong>User's Guide</strong><br><small>Version 2.6.8</small></p>
<br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Chapters</strong></small></p>
<ul class="flipMenu" imagepath="../../../../doc/js/flipmenu">
<li id="no" title="cover" expanded="false">cover<ul>
<li><a href="cover_chapter.html">
              Top of chapter
            </a></li>
<li title="Introduction"><a href="cover_chapter.html#id64809">Introduction</a></li>
<li title="Getting Started With Cover"><a href="cover_chapter.html#id62638">Getting Started With Cover</a></li>
<li title="Miscellaneous"><a href="cover_chapter.html#id60749">Miscellaneous</a></li>
<li title="Using the Web Based User Interface to Cover"><a href="cover_chapter.html#id63969">Using the Web Based User Interface to Cover</a></li>
</ul>
</li>
<li id="no" title="cprof - The Call Count Profiler" expanded="false">cprof - The Call Count Profiler<ul>
<li><a href="cprof_chapter.html">
              Top of chapter
            </a></li>
<li title="Example: Background work"><a href="cprof_chapter.html#id62155">Example: Background work</a></li>
<li title="Example: One module"><a href="cprof_chapter.html#id62215">Example: One module</a></li>
<li title="Example: In the code"><a href="cprof_chapter.html#id62262">Example: In the code</a></li>
</ul>
</li>
<li id="no" title="The Erlang mode for Emacs" expanded="false">The Erlang mode for Emacs<ul>
<li><a href="erlang_mode_chapter.html">
              Top of chapter
            </a></li>
<li title="Purpose"><a href="erlang_mode_chapter.html#id64082">Purpose</a></li>
<li title="Pre-requisites"><a href="erlang_mode_chapter.html#id64101">Pre-requisites</a></li>
<li title="Elisp"><a href="erlang_mode_chapter.html#id64113">Elisp</a></li>
<li title="Setup on UNIX"><a href="erlang_mode_chapter.html#id64126">Setup on UNIX</a></li>
<li title="Setup on Windows "><a href="erlang_mode_chapter.html#id64160">Setup on Windows </a></li>
<li title="Indentation"><a href="erlang_mode_chapter.html#id64228">Indentation</a></li>
<li title="Editing"><a href="erlang_mode_chapter.html#id64277">Editing</a></li>
<li title="Syntax highlighting"><a href="erlang_mode_chapter.html#id64373">Syntax highlighting</a></li>
<li title="Tags"><a href="erlang_mode_chapter.html#id64396">Tags</a></li>
<li title="Etags"><a href="erlang_mode_chapter.html#id64430">Etags</a></li>
<li title="Shell"><a href="erlang_mode_chapter.html#id64528">Shell</a></li>
<li title="Compilation"><a href="erlang_mode_chapter.html#id64585">Compilation</a></li>
</ul>
</li>
<li id="loadscrollpos" title="fprof - The File Trace Profiler" expanded="true">fprof - The File Trace Profiler<ul>
<li><a href="fprof_chapter.html">
              Top of chapter
            </a></li>
<li title="Profiling from the source code"><a href="fprof_chapter.html#id64914">Profiling from the source code</a></li>
<li title="Profiling a function"><a href="fprof_chapter.html#id64995">Profiling a function</a></li>
<li title="Immediate profiling"><a href="fprof_chapter.html#id65025">Immediate profiling</a></li>
</ul>
</li>
<li id="no" title="lcnt - The Lock Profiler" expanded="false">lcnt - The Lock Profiler<ul>
<li><a href="lcnt_chapter.html">
              Top of chapter
            </a></li>
<li title=" Enabling lock-counting "><a href="lcnt_chapter.html#id65145"> Enabling lock-counting </a></li>
<li title="Getting started"><a href="lcnt_chapter.html#id65194">Getting started</a></li>
<li title=" Example of usage "><a href="lcnt_chapter.html#id65262"> Example of usage </a></li>
<li title=" Example with Mnesia Transaction Benchmark "><a href="lcnt_chapter.html#id65351"> Example with Mnesia Transaction Benchmark </a></li>
<li title=" Deciphering the output "><a href="lcnt_chapter.html#id65488"> Deciphering the output </a></li>
<li title="See Also"><a href="lcnt_chapter.html#id65506">See Also</a></li>
</ul>
</li>
<li id="no" title="Xref - The Cross Reference Tool" expanded="false">Xref - The Cross Reference Tool<ul>
<li><a href="xref_chapter.html">
              Top of chapter
            </a></li>
<li title="Module Check"><a href="xref_chapter.html#id65613">Module Check</a></li>
<li title="Predefined Analysis"><a href="xref_chapter.html#id65693">Predefined Analysis</a></li>
<li title="Expressions"><a href="xref_chapter.html#id65996">Expressions</a></li>
<li title="Graph Analysis"><a href="xref_chapter.html#id66325">Graph Analysis</a></li>
</ul>
</li>
</ul>
</div></div>
<div id="content">
<div class="innertube">
<h1>4 fprof - The File Trace Profiler</h1>
  
  <p><span class="code">fprof</span> is a profiling tool that can be used to get a picture of
    how much processing time different functions consumes and in which
    processes.
    </p>
  <p><span class="code">fprof</span> uses tracing with timestamps to collect profiling
    data. Therfore there is no need for special compilation of any
    module to be profiled.
    </p>
  <p><span class="code">fprof</span> presents wall clock times from the host machine OS,
    with the assumption that OS scheduling will randomly load the
    profiled functions in a fair way. Both <strong>own time</strong> i.e the
    time used by a function for its own execution, and
    <strong>accumulated time</strong> i.e execution time including called
    functions. 
    </p>
  <p>Profiling is essentially done in 3 steps:</p>
  <dl>
    <dt><strong><span class="code">1</span></strong></dt>
    <dd>Tracing; to file, as mentioned in the previous paragraph.</dd>
    <dt><strong><span class="code">2</span></strong></dt>
    <dd>Profiling; the trace file is read and raw profile data is
     collected into an internal RAM storage on the node. During
     this step the trace data may be dumped in text format to file
     or console.</dd>
    <dt><strong><span class="code">3</span></strong></dt>
    <dd>Analysing; the raw profile data is sorted and dumped
     in text format either to file or console.</dd>
  </dl>
  <p>Since <span class="code">fprof</span> uses trace to file, the runtime performance 
    degradation is minimized, but still far from negligible, 
    especially not for programs that use the filesystem heavily 
    by themselves. Where you place the trace file is also important, 
    e.g on Solaris <span class="code">/tmp</span> is usually a good choice,
    while any NFS mounted disk is a lousy choice.
    </p>
  <p>Fprof can also skip the file step and trace to a tracer process
    of its own that does the profiling in runtime.
    </p>
  <p>The following sections show some examples of how to profile with
    Fprof. See also the reference manual 
    <span class="bold_code"><a href="fprof.html">fprof(3)</a></span>.
    </p>

  <h3><a name="id64914">4.1 
        Profiling from the source code</a></h3>
    
    <p>If you can edit and recompile the source code, it is convenient 
      to insert <span class="code">fprof:trace(start)</span> and 
      <span class="code">fprof:trace(stop)</span> before and after the code to be
      profiled. All spawned processes are also traced. If you want
      some other filename than the default try
      <span class="code">fprof:trace(start, "my_fprof.trace")</span>.
      </p>
    <p>Then read the trace file and create the raw profile data with 
      <span class="code">fprof:profile()</span>, or perhaps 
      <span class="code">fprof:profile(file, "my_fprof.trace")</span> for non-default
      filename. 
      </p>
    <p>Finally create an informative table dumped on the console with
      <span class="code">fprof:analyse()</span>, or on file with
      <span class="code">fprof:analyse(dest, [])</span>, or perhaps even 
      <span class="code">fprof:analyse([{dest, "my_fprof.analysis"}, {cols, 120}])</span>
      for a wider listing on non-default filename.
      </p>
    <p>See the <span class="bold_code"><a href="fprof.html">fprof(3)</a></span> manual page
      for more options and arguments to the functions
      <span class="bold_code"><a href="fprof.html#trace">trace</a></span>,
      <span class="bold_code"><a href="fprof.html#profile">profile</a></span>
      and 
      <span class="bold_code"><a href="fprof.html#analyse">analyse</a></span>.
      </p>
  

  <h3><a name="id64995">4.2 
        Profiling a function</a></h3>
    
    <p>If you have one function that does the task that you want to
      profile, and the function returns when the profiling should
      stop, it is convenient to use 
      <span class="code">fprof:apply(Module, Function, Args)</span> and related for the
      tracing step.
      </p>
    <p>If the tracing should continue after the function returns, for
      example if it is a start function that spawns processes to be
      profiled, you can use 
      <span class="code">fprof:apply(M, F, Args, [continue | OtherOpts])</span>. 
      The tracing has to be stopped at a suitable later time using
      <span class="code">fprof:trace(stop)</span>.
      </p>
  

  <h3><a name="id65025">4.3 
        Immediate profiling</a></h3>
    
    <p>It is also possible to trace immediately into the profiling
      process that creates the raw profile data, that is to short
      circuit the tracing and profiling steps so that the filesystem
      is not used.
      </p>
    <p>Do something like this:</p>
    <div class="example"><pre>
{ok, Tracer} = fprof:profile(start),
fprof:trace([start, {tracer, Tracer}]),
%% Code to profile
fprof:trace(stop);</pre></div>
    <p>This puts less load on the filesystem, but much more on the
      Erlang runtime system.
      </p>
  
</div>
<div class="footer">
<hr>
<p>Copyright © 1997-2012 Ericsson AB. All Rights Reserved.</p>
</div>
</div>
</div></body>
</html>