Tag Archives: fprof

Profiling a Running Erlang Server

Say you want to profile a running (may be even production) Erlang server. You would do it with fprof. It is relatively easy to profile a function, just follow documentation, let’s see how to profile application.

  1. Start profiling for all processes of interest
    fprof:trace([start, {procs, [whereis(pid1), whereis(pid2)]}]).
    pid1, pid2 etc – registered processes. Fprof will profile them and all spawned processes, so depending on your architecture it is enough to include single process which listens on socket and accepts connections. Documentation states that whereis is not necessary, but it doesn’t work for me otherwise.
  2. After a while stop profiling. Note that trace files are really big, and processing them in consequent steps takes quite awhile, so the the first time you wouldn’t want to run profiling for the whole day 🙂 Just try 30-60 seconds to begin with. Also keep in mind that load will increase 5-10 times, so if you test in on production server, make sure you have enough resources 🙂
    fprof:trace([stop]).
  3. Process data. This will process raw data and save result to ‘fprof.trace’ file, or you can give it other name so you can find and load it later.
    fprof:profile().
  4. Analyse and save data to human readable text file – ‘fprof.analysis’
    fprof:analyse([totals, {dest, "fprof.analysis"}]).
  5. Clear all memory. This makes sense if you want to let server continue.
    fprof:stop().

I will not explain how to read resulting text file, they are a bit cryptic and you have to read fprof documentation, frankly speaking I don’t understand it fully 🙂

Advertisements