memtrace#
A streaming client for OCaml's Memprof, which generates compact traces of a program's memory use.
Installation#
Install with opam:
opam install nox-memtrace
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
opam update
opam install nox-memtrace
Usage#
To profile the memory use of a program, start by putting this line somewhere at the program startup:
Memtrace.trace_if_requested ()
If the --memtrace FILE command-line flag is passed or the MEMTRACE
environment variable is set, tracing begins to the specified file.
(If neither is present, nothing happens.)
The ~context parameter is optional and can be set to any string
that helps identify the trace file.
Memtrace.trace_if_requested ~context:"v1.2.3" ()
For Cmdliner-based CLIs, use Memtrace.term to integrate the flag
into your command line parser.
If the program daemonises, the call to trace_if_requested should
occur after the program forks, to ensure the right process is
traced.
The resulting trace files can be analysed with some simple command-line tools in bin/, but the recommended interface is the memtrace viewer, which lives in:
$ MEMTRACE=trace.ctf ./my-service
$ jane/app/memtrace_viewer trace.ctf