package mirage-profile

  1. Overview
  2. Docs
Collect runtime profiling information in CTF format

Install

Dune Dependency

Authors

Maintainers

Sources

mirage-profile-0.8.2.tbz
sha256=0680a8545f64eabe9496ce9f52c20ecff82c18a4159fceca4e91890e525fe2c4
md5=7f094bcb0b81746a712326ea583b2e76

Description

This library can be used to trace execution of OCaml/Lwt programs (such as Mirage unikernels) at the level of Lwt threads. The traces can be viewed using JavaScript or GTK viewers provided by [mirage-trace-viewer][] or processed by tools supporting the [Common Trace Format (CTF)][ctf]. Some example traces can be found in the blog post Visualising an Asynchronous Monad.

Libraries can use the functions mirage-profile provides to annotate the traces with extra information. When compiled against a normal version of Lwt, mirage-profile's functions are null-ops (or call the underlying untraced operation, as appropriate) and OCaml's cross-module inlining will optimise these calls away, meaning there should be no overhead in the non-profiling case.

Published: 23 Nov 2017

README

mirage-profile -- collect runtime profiling information in CTF format

This library can be used to trace execution of OCaml/Lwt programs (such as Mirage unikernels) at the level of Lwt threads. The traces can be viewed using JavaScript or GTK viewers provided by mirage-trace-viewer or processed by tools supporting the Common Trace Format (CTF). Some example traces can be found in the blog post Visualising an Asynchronous Monad.

Libraries can use the functions mirage-profile provides to annotate the traces with extra information. When compiled against a normal version of Lwt, mirage-profile's functions are null-ops (or call the underlying untraced operation, as appropriate) and OCaml's cross-module inlining will optimise these calls away, meaning there should be no overhead in the non-profiling case.

Use with Mirage

See http://openmirage.org/wiki/profiling for instructions.

Recording traces manually

To record traces you need to pin a version of Lwt with tracing support (this provides the lwt.tracing findlib module):

$ opam pin add lwt 'https://github.com/mirage/lwt.git#tracing'

This will cause mirage-profile and any programs using it to be recompiled with tracing enabled.

To trace a Unix process, use MProf_unix.mmap_buffer to write to an mmapped file:

let () =
  let buffer = MProf_unix.mmap_buffer ~size:1000000 "trace.ctf" in
  let trace_config = MProf.Trace.Control.make buffer MProf_unix.timestamper in
  MProf.Trace.Control.start trace_config

You'll also need to link with the mirage-profile and mirage-profile-unix libraries.

To begin tracing a Xen unikernel, create a buffer and call MProf.Trace.Control.start:

let trace_pages = MProf_xen.make_shared_buffer ~size:1000000
let () = 
  let buffer = trace_pages |> Io_page.to_cstruct |> Cstruct.to_bigarray in
  let trace_config = MProf.Trace.Control.make buffer MProf_xen.timestamper in
  MProf.Trace.Control.start trace_config

To share the buffer with dom0, do this somewhere in your initialisation code:

MProf_xen.share_with (module Gnt.Gntshr) (module OS.Xs) ~domid:0 trace_pages

You'll also need to link with the mirage-profile and mirage-profile-xen libraries.

Viewing traces

To view the trace you should, ideally, call MProf.Trace.Control.stop before reading the buffer to avoid race conditions, but in practice reading the trace at any time usually works.

If your program crashes, you can still read the trace buffer. On Xen, you can ensure that the buffer doesn't disappear by adding these lines to your guest's config file:

on_crash = 'preserve'
on_poweroff = 'preserve'

mirage-trace-viewer contains tools for saving and viewing traces, as well as a metadata description of the format, which allows the traces to be read using e.g. babeltrace.

Recording extra trace data

Programs and libraries are encouraged to record extra useful information using the MProf module. As using these functions generally has no overhead when a regular Lwt is used, there should be no need to use conditional compilation for this. See the MProf.Trace and MProf.Counter modules for documentation about what can be recorded.

Dependencies (7)

  1. ocaml-migrate-parsetree < "2.0.0"
  2. lwt
  3. ocplib-endian
  4. ppx_cstruct
  5. cstruct >= "3.0.0"
  6. jbuilder >= "1.0+beta9"
  7. ocaml >= "4.03.0"

Dev Dependencies

None

Used by (21)

  1. arp-mirage >= "2.0.0"
  2. dns >= "0.15.0" & < "1.0.0"
  3. dns-lwt
  4. ethernet < "3.2.0"
  5. jitsu
  6. mirage-dns >= "2.6.0"
  7. mirage-logs < "1.3.0"
  8. mirage-net-solo5 < "0.2.0"
  9. mirage-net-xen >= "1.2.0" & < "1.7.1"
  10. mirage-profile-unix >= "0.8.2"
  11. mirage-profile-xen = "0.8.2"
  12. mirage-solo5 < "0.2.0"
  13. mirage-unix >= "2.1.0" & < "3.0.8"
  14. mirage-vnetif < "0.6.1"
  15. mirage-vnetif-stack < "0.6.1"
  16. mirage-xen >= "2.1.0" & < "8.0.3"
  17. netchannel
  18. shared-memory-ring >= "1.1.1" & < "3.2.1"
  19. shared-memory-ring-lwt < "3.2.1"
  20. tcpip = "2.1.0" | >= "3.1.4" & < "8.0.0"
  21. xen-gnt >= "2.1.0" & < "4.0.2"

Conflicts

None

OCaml

Innovation. Community. Security.