Tracing as replacement for Landmarks

I’ve used Landmarks in the past, mostly because it was really easy to setup and instrument a run.

With the new OCaml tracing tools, I wonder what would be the simplest way to have something similar, that is: just a simple bar graph or something showing which functions take the longest time during execution.

Is this usage scenario appropriate for tracing tools? And between opentelemetry, tracy, chrome traces, etc, which would be the simplest to adapt?

1 Like

Note that if that’s really the only thing you are interested in then none of this is really needed. On MacOS I simply use:

xcrun xctrace record --template='Time Profiler' --launch -- MYTOOL ARG…

and on Linux there’s perf. See profiling in the manual.

2 Likes

We tried perf in the past, but its output contains a lot of “noise”, with low-level functions that are not always useful, as in this example:

Landmarks has the advantage of being “pure OCaml”, so it only reports OCaml-level functions, which is much more useful for some quick and simple profiling.

The trace mechanism seems like it might give the same “high-level” information.

1 Like

I’ll admit I tend to reach for perf + flamegraph for this kind of high level view, otherwise I instrument with trace and look at what the program does in perfetto. It depends a bit on the shape of the program though.

Out of curiosity, why are you looking for an alternative to Landmarks (if indeed you are) ?

Cheers,
Nicolas

Is there something equivalent to Landmarks’ automatic instrumentation? From my very quick glance at the documentation, even with trace_ppx, I need to add %trace to the let constructions that I wish to trace, is that it? For now I’d like some basic “function call instrumentation” as automatic as possible, and then later likely add some specific spans for more details.

Overall, my profiling needs are very basic and rare; so if it’s “almost free”, I end up doing it from time to time, but otherwise I just end up forgetting about it.

@nojb: I’m asking about an alternative to Landmarks mainly for the result visualization part. Maybe it’s already in Landmarks and I missed it, but currently I only have its text output in the terminal, or the landmarks-viewer in the browser; but I assume that with Chrome traces or some other format, I might be able to use other tools such as Perfetto.

1 Like

There isn’t automatic instrumentation yet (I suppose the ppx could do it, modulo the actual implementation work!). I think landmarks, too, could in theory be implemented in terms of trace (it also has enter/exit events after all).

I wonder if the landmarks format is documented? It’s described as simple, so maybe I could do a trace backend that emits it (at least for the biggest features).

1 Like