[erlang-questions] How to profile a running erlang production server with fprof?

Roux Viljoen roux.viljoen@REDACTED
Fri Jan 30 12:25:43 CET 2009

Kaiduan Xie <kaiduanx <at> gmail.com> writes:

> The production server is structured as an OTP application, and an Erlang 
shell is attached. How to profile the WHOLE system with fprof from the shell? 
Detailed command sequence  is highly appreciated.Thanks a lot for help,kaiduan

Kaiduan Xie,

Fprof is part of the tools library found in OTP, so first you need to make sure
 its loaded with your application by adding it to your release. 
Add this to the list of applications in the release file, just change the 
version to match yours:
{tools, '2.6.2'}

Now you can use the fprof application. There is alot of ways to use fprof, but 
the following should be fine. First start a trace by entering:

fprof:trace([start, {file, "/home/kaiduanxie/first.trace"}, verbose, 

Now you can run whichever processes you want to profile and then when you're 
done, stop the trace by entering:


The trace file can now be profiled and analyzed:

fprof:profile({file, "/home/kaiduanxie/first.trace"}).
fprof:analyse([totals, {dest, "/home/kaiduanxie/first.analysis"}]).

This will produce the first.analysis file which will contain all the data 
you want. Just be aware that fprof has many configuration options available, 
this was just a simplistic example. 

Also, in this example we used the {procs,all} option when we started the trace, 
this allowed fprof to trace ALL processes. This can cause the trace and 
analysis files to be huge if you're gonna run alot of processes, so just make 
sure you have enough disk space. 

Please consult the documentation for the configuration options if this example 
does not produce the desired results.

Good luck,

Roux Viljoen
Erlang Training & Consulting

More information about the erlang-questions mailing list