[erlang-questions] profile question

Raimo Niskanen raimo+erlang-questions@REDACTED
Wed Jan 28 09:17:25 CET 2009


On Tue, Jan 27, 2009 at 11:00:10PM -0500, Kaiduan Xie wrote:
> Hi, all,
> 
> I have a question on how to find the hot spot of large base Erlang system.
> For example, after running cprof.start(), cprof.pause(), cprof.analyze(), I
> got the following results (only the first item is listed below),
> 
> {1847012003,
>  [{io_lib_format,722457356,
>                  [{{io_lib_format,pcount,2},109483111},
>                   {{io_lib_format,collect,2},109483111},
>                   {{io_lib_format,build,3},109483111},
>                   {{io_lib_format,iolist_to_chars,1},83312743},
>                   {{io_lib_format,indentation,2},60014886},
>                   {{io_lib_format,field_value,2},26618934},
>                   {{io_lib_format,field_value,3},17824836},
>                   {{io_lib_format,precision,2},17706522},
>                   {{io_lib_format,pad_char,2},17706522},
>                   {{io_lib_format,field_width,3},17706522},
>                   {{io_lib_format,field_width,2},17706522},
>                   {{io_lib_format,decr_pc,2},17706522},
>                   {{io_lib_format,control,7},17706522},
>                   {{io_lib_format,collect_cseq,2},17706522},
>                   {{io_lib_format,collect_cc,2},17706522},
>                   {{io_lib_format,print,7},14402937},
>                   {{io_lib_format,chars,2},8912422},
>                   {{io_lib_format,term,5},8912417},
>                   {{io_lib_format,min|...},8912416},
>                   {{io_lib_format|...},8912416},
>                   {{...}|...},
>                   {...}|...]},
> 
> So here comes the question, how can we find which part calls
> (io_lib_format,pcount,2) most? I tried to use fprof(), but it seems that you
> need to know the arguments of the function first.
> 
> What is the best practice to address this problem? Or did I do something
> wrong?

No, you are on track. This is the curse of cprof - it only gives you
the call count but with minimal strain on your system. The curse of
fprof is that it gives you lots of information for the price of
a very high system load.

Now you can read some code. The module io_lib_format is an internal
module for io_lib and io. So the user code calls either io:format/1,2,3,
io:fwrite/1,2,3, io_lib:format/2 or io_lib:fwrite/2. You can search
for those in your source and see which are suspicious.

You can also hand craft a trace by tracing only the io and io_lib functions
in the previous paragraph using the match spec function {caller}.
This you might do with the dbg module, maybe some other trace tool,
or write one yourself. That would give you an idea of who is to blame.

> 
> Thanks,
> 
> kaiduan

> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list