OCaml-tracy 
This repo contains bindings to Tracy, a profiler and trace visualizer. It's licensed, like Tracy, under BSD-3-Clause.
The bindings are pretty basic and go through the C API, not the C++ one (RAII is not compatible with having a function call to enter, and one to exit).
It depends on a C++ compiler to build, along with the dependencies of Tracy-client.
Feature table
| feature | supported |
|---|---|
| zones | |
| messages | |
| plots | |
| locks | |
| screenshots | |
| frames | |
| gpu |
In some cases the feature might not provide all options.
Example
The file examples/prof1.ml shows basic instrumentation on a program that computes
the Fibonacci function (yes, not representative) in a loop on 3 threads.
If Tracy is running and is waiting for a connection (press "connect"),
running dune exec ./examples/prof1.exe should start tracing
and display something like this: 
Usage
-
the
tracylibrary is a virtual dune library which provides the type signatures for instrumenting your code. It's very small and is ok to add to a library.For example in
prof1.ml, we start with:T.name_thread (Printf.sprintf "thread_%d" th_n);
to name the
n-th worker thread. Then later we have calls like:T.with_ ~file:__FILE__ ~line:__LINE__ ~name:"inner.fib" () @@ fun _sp -> T.set_color _sp 0xaa000f; (* rest of code in the span _sp *) …
to create a span in Tracy, with a custom color, and the name
inner.fib. One can also add text and values to the span. Alternatively,Tracy.enterandTracy.exitcan be used to delimit the span manually.To start, one needs to call
Tracy.enable(). -
the
tracy-clientpackage contains the actual C bindings (using a vendored copy of tracy), and implements the virtual library by providing actual instrumentation. -
the
tracy.nonelibrary (comes intracy) replaces all instrumentation calls with no-op, which might be inlined by ocamlopt. This is the default implementation and it means that just addingtracyto a library will not incur much at compile time and runtime.
