Ocaml 3.09.3 with memory profiling support version 1.3 ------------------------------------------ This patch was originally designed by Fabrice Le Fessant. ChangeLog: * version 1.4: - Updated for OCaml 3.10.0 by Samuel Mimram. * version 1.3: - Updated for OCaml 3.09.3 by Samuel Mimram. * version 1.2: - Updated for OCaml 3.08.3 by spiralvoice. * version 1.1: - Draw simple graphs using hp2ps (see HOW TO USE version 1.1). * version 1.0: - See HOW TO USE version 1.0. INTRODUCTION: ------------- This is a beta version, just a few days of work, so be indulgent! Use an image of the memory of the application saved on disk to display informations about how the memory is used by the application. Note that you need more memory on your computer than the memory used by the application (i.e. my application uses 70 MB of memory, I needed at least 250 MB to load the image in memory for analysis). The information given is pretty simple. The memory retained by every identified root (memory can be retained by several roots at a time), and space used by every identified type. The main interest of the approach is that profiling your program memory is done without any cost on the program execution speed or memory usage. The algorithms used are very simple, far from optimal. Lot of work is needed (1) to implement optimal graph algorithms (2) to display the _interesting_ information so that it can be used to improve the program (3) to modify the compiler to get more information (4) to interface with gnuplot to have nice drawings. HOW TO USE version 1.0 ---------------------- * Patch a clean image of ocaml: In ocaml-3.07: patch -p1 < ocaml-3.07-memprof.patch * Compile ocaml and install. Don't forget the target "opt.opt": ./configure make world An error should appear while compiling "expunge". No problem, it's normal. This error looks like this: Error while linking boot/stdlib.cma(Gc): The external function `caml_dump_heap' is not available make bootstrap make bootstrap make world make opt opt.opt make install installopt The analyser is compiled and install with ocaml, its sources are in the hp/ subdirectory. * Compile the software you want to profile in NATIVE CODE (ie with ocamlopt or ocamlopt.opt). Somewhere in the code, you should use Gc.dump_heap () to dump an image of the memory on the disk. You can do that using a signal: when receiving a HUP signal, the application will dump its memory on disk for future profiling. Sys.set_signal Sys.sighup (Sys.Signal_handle (fun _ -> Gc.dump_heap ())); * A memory image on disk looks like: heap.dump..' where is the number of your program pid, and heapstats.opt will output two files, 'blocks_per_type..hp' and 'sizes_per_type..hp'. Now, you run hp2ps on every .hp file, to obtain the corresponding .ps file, that you can view using gv -seascape blocks_per_type..ps for example.