I am trying to profile a project with landmarks but I cannot get it to work. According to the documentation it seems there are two simple ways to do this with dune. One is to add the lines
to the dune file. When I do this, I get a “not found” error, even though the landmarks-ppx library is installed:
$ dune build
File "dune", line 4, characters 19-32:
4 | (preprocess (pps landmarks.ppx --auto)))
^^^^^^^^^^^^^
Error: Library "landmarks.ppx" not found.
-> required by _build/default/test.exe
-> required by alias all
-> required by alias default
$ opam install landmarks-ppx
[NOTE] Package landmarks-ppx is already installed (current version is 1.4).
The other way is to add the line
(instrumentation (backend landmarks))
and then compile the file with dune build --instrument-with landmarks. When I do this, it compiles successfully, but I cannot figure out how to generate the profiled output. I have tried
It seems that indeed you need to replace “landmarks.ppx” by “landmarks-ppx”.
The problem with the alternative approach is that you need to add “–instrument-with” to the “dune exec” command. If you do not do that, dune will rebuild without the instrumentation:
and if you do not have “[@landmark]”
and if you are not using the compilation flag “-linkall”
then the compiler will not link the landmarks library (because it will appear unused) which is in charge of reading the OCAML_LANDMARKS environment variable and dumping the profiling at exit.
For the second approach, I wonder whether the need to pass those two extra flags could be documented better somewhere? There’s nothing about either of them at Instrumentation — Dune documentation.