Profiling the Dune node¶
Memory profiling the OCaml heap¶
Install an OCaml switch with the statmemprof patch:
Enable loading statmemprof into the node.
statmemprof-emacspackage as a dependency to the main package, and add
let () = Statmemprof_emacs.start 1E-4 30 5to the
sampling_rateis the sampling rate of the profiler. Good value:
callstack_sizeis the size of the fragment of the call stack which is captured for each sampled allocation.
min_sample_printis the minimum number of samples under which the location of an allocation is not displayed.
Load sturgeon into emacs, by adding this to your
(let ((opam-share (ignore-errors (car (process-lines "opam" "config" "var" "share"))))) (when (and opam-share (file-directory-p opam-share)) (add-to-list 'load-path (expand-file-name "emacs/site-lisp" opam-share)))) (require 'sturgeon)
Launch the node then connect to it with sturgeon.
If the process is launched with pid
M-x sturgeon-connect dune-nodememprof.1234.sturgeon (tab-completion works for finding the socket name)
Memory profiling the C heap¶
valgrind --tool=massif dune-node run ...
- Stop with Ctrl-C then display with
Install perf (the
linux-perfpackage for debian).
If the package does not exist for your current kernel, a previous version can be used. Substitute the
perf_4.9if your kernel is 4.9).
Run the node, find the pid.
Attach perf with
perf record -p pid --call-stack dwarf.
Then stop capturing with
Ctrl-C. This can represent a lot of data. Don’t do that for too long. If this is too much you can remove the
--call-stack dwarfto get something more manageable, but interpreting the information can be harder.
display the result with