LexiFi / landmarks

A Simple Profiling Library for OCaml
MIT License
129 stars 20 forks source link

Building with dune produces not working program #19

Closed zajer closed 4 years ago

zajer commented 4 years ago

I tried to build the following example:

open Landmark

let loop = register "loop"
let sleep = register "sleep"
let main = register "main"

let zzz () =
  enter sleep;
    Unix.sleep 1;
  exit sleep

let () =
  begin
    start_profiling ();
    enter main;
      enter loop;
        for _ = 1 to 9 do
          zzz ()
        done;
      exit loop;
      zzz ();
    exit main;
  end

With a dune file like:

(executable
 (name main)
 (libraries landmarks unix)
 (modes native)
 (preprocess (pps landmarks.ppx --auto))
)

Unfortunately when I run dune build from the project's root directory the generated program (main.exe) returns the following output:

Warning: landmark failure when closing 'load(bin/main)' (bin/main.ml:1), expecting 'ROOT' (src/landmark.ml).
Call graph './main.exe':
------------------------

Note: Nodes accounting for less than 1.00% of their parent have been ignored.

Aggregated table:
----------------
Name;        Filename;    Calls;     Time; Allocated bytes
ROOT; src/landmark.ml;        0;   69.01K;    59888
Fatal error: exception Landmark.LandmarkFailure("unable to recover from landmark failure when closing 'load(bin/main)' (bin/main.ml:1), expecting 'ROOT' (src/landmark.ml).")

Having said that, building the same program with ocamlfind ocamlc -o prog -package landmarks -package unix -linkpkg main.ml results with perfectly fine working program that produces the following output:

Call graph './prog':
--------------------
[   22.61G cycles in 1 calls ]     - 100.00% : main
[   20.35G cycles in 1 calls ]     |   - 90.00% : loop
[   20.35G cycles in 9 calls ]     |   |   - 100.00% : sleep
[    2.26G cycles in 1 calls ]     |   - 10.00% : sleep

Note: Nodes accounting for less than 1.00% of their parent have been ignored.

Aggregated table:
----------------
 Name;        Filename;    Calls;     Time; Allocated bytes
 ROOT; src/landmark.ml;        0;   22.61G;   113304
 main;         unknown;        1;   22.61G;     7456
sleep;         unknown;       10;   22.61G;     2720
 loop;         unknown;        1;   20.35G;     5472
zajer commented 4 years ago

It turns out that getting rid of --auto from the dune file solved the issue.