ProfilingMldonkey
Profiling Mldonkey
In order to see where Mldonkey spends its time during processing, one must compile the mlnet binary with profiling support:
./configure --enable-profile --enable-debug DEVFLAGSOPT=-S make
-S is needed so partial assembly code files, .s files, remain.
--enable-profile intruments the binary for profiling.
Run mlnet as usual. When it terminates, it will generate a file gmon.out. This is the profiling information in binary format.
Then do:
gprof mlnet > gprof.txt
The above command could fail in case that gmon.out is located in the current ./mldonkey directory. In this situation do:
gprof mlnet /home/username/.mldonkey/gmon.out > gprof.txt
this will generate a human readable report.
There will be lines like:
37.63 248.10 248.10 564784904 0.00 0.00 camlCommonSources__fun_2783
which says 37% of execution time is spent in camlCommonSources__fun_2783. This is an anonymous function in commonsources.ml
Non-anonymous functions have more readable names and are easier to find in the original source. Mldonkey has lots of anonymous functions however, and then you need some detective work to discover which part of the original ocaml source corresponds to the function in gprof.txt.
The function above, for instance, can be located in commonsources.s, which is assembly code generated from commonsources.ml. You have to look at the assembly code and match it with the the ocaml source, perhaps with the argument list, and the external function calls which are made in the body.