Eio-trace 0.1 and Eio 0.15

With Eio 0.15 just released, I’d like to announce also the first release of the eio-trace tool, which can be used to visualise the behaviour of any Eio program (no need for a special instrumented build). For eample, here is one of Eio’s tutorial examples:

  (fun () -> for x = 1 to 3 do traceln "x = %d" x; Fiber.yield () done)
  (fun () -> for y = 1 to 3 do traceln "y = %d" y; Fiber.yield () done)
dune build ./examples
eio-trace run -- ./_build/default/examples/both/main.exe

will open a window showing:

The upper horizontal bar is the initial fiber, and the brackets show Fiber.both creating a second fiber. The green segments show when each fiber is running. Note that the output from traceln appears in the trace as well as on the console. In the eio-trace window, scrolling with the mouse or touchpad will zoom in or out of the diagram.

This should make it easier to see what’s going on, and to find performance problems. For example, we can see that the first output above took quite a bit longer than the others. You can then use e.g. magic-trace to get very fine-grained traces at this point (and we can see that e.g. the Linux write system call takes a lot longer the first time).

eio-trace can trace mutliple domains, and shows the various stages of garbage collection. Here we have two domains running; the yellow regions show when the OCaml code is stopped due to garbage collection or polling the OS:

So far, eio-trace has also uncovered two bugs in OCaml: #12948 and #12897. For example, the trace below shows a process freezing for around 45ms during Domain.join, due to a problem waiting for OCaml’s tick thread to stop:

Particular thanks are due to @patricoferris and @Lortex for their work on Eio tracing.

There have also been lots of other recent improvements to Eio, including:

  • Eio.Executor_pool for submitting jobs to a pool of worker domains (thanks to @asemio_sgrondin).
  • Eio.Pool for managing pools of resources (like Lwt_pool). And note that you can now attach resources to a switch from any domain, which makes pools more useful.
  • Eio.Lazy is like Stdlib.Lazy but multi-domain safe.
  • There are lots more operations in Eio.Path (stat, rmtree, mkdirs, etc).
  • FD-passing over Unix-domain sockets.
  • The Eio_posix backend now uses file descriptors for directories (Eio_linux already did this), which avoids races with symlinks and is faster. It also means that Eio now works with Capsicum OS sandboxing.
  • run_in_systhread now uses a pool of sys-threads for performance.

For full details, see the release notes, and feel free to join the developer meetings every two weeks.