catapult-sqlite

Sqlite-based backend for Catapult tracing
README

This is a tracing library for OCaml, based on the
Catapult/TEF
trace format.

The traces are .json files (or compressed .json.gz). They can be viewed in:

  • https://ui.perfetto.dev/

  • chrome://tracing in chrome/chromium

  • https://github.com/wolfpld/tracy after conversion (the tracy-import-chrome binary)

Usage

The core library is catapult. It's a small set of probes that can be
inserted in your code, by hand (with meaningful messages if needed).

Example: "basic"

A very stupid example (in examples/basic/basic.ml), is:

module Tr = Catapult.Tracing
let spf = Printf.sprintf

let rec fake_trace depth =
  if depth>=3 then ()
  else (
    (* the probe is here *)
    Tr.with_ "step" @@ fun () ->
    Thread.delay 0.1;
    Printf.printf "fake (depth=%d)\n%!" depth;
    fake_trace (depth+1);
    Thread.delay 0.2;
    Tr.instant "iteration.done" ~args:["depth", `Int depth];
  )

let () =
  Catapult_file.with_setup @@ fun () ->
  let n = try int_of_string (Sys.getenv "N") with _ -> 10 in
  Printf.printf "run %d iterations\n%!" n;

  for _i = 1 to n do
    fake_trace 0;
  done

If run with the TRACE=1 environment variable set, this will just produce a
basic trace in the file "trace.json" (otherwise probes will do nothing and keep
a minimal overhead).

Once opened in chrome://tracing, the trace looks like this:

Example: "heavy"

A more heavy example (used to benchmark a bit the tracing), is in examples/heavy.

In a terminal, run the daemon (if it's not already running):

$ ./daemon.sh

Then in another terminal:

$ ./heavy.sh -n=1 --mode=net -j 2
use net client tcp://127.0.0.1:6981
run 1 iterations
iteration 1
use net client tcp://127.0.0.1:6981
run 1 iterations
iteration 1

# list traces
$ catapult-conv
…
catapult-2022-2-16-16-36-18-pid-3229175.dbo

# convert last trace into a json.gz file
$ catapult-conv catapult-2022-2-16-16-36-18-pid-3229175.db

$ ls -lh trace.json.gz 
-rw-r--r-- 1 simon simon 374K Feb 16 11:38 trace.json.gz

Opened in chrome, the trace looks like that (focusing on a "step" event):

License

MIT

Install
Maintainers
Sources
v0.1.tar.gz
md5=a7bfa27c3ddd2d29c27173de09293149
sha512=49766ea38c57734918debd6218d95c62f11eb12a6fd3ef5f6a2c60344cea7c274436a46fab1e48abbe0d3f125f31705d2005ab7cae9e56d5f41778c1d2943d65
Dependencies
ocaml
>= "4.08"
odoc
with-doc
catapult
= version
sqlite3
>= "5.0"
dune
>= "2.0"
Reverse Dependencies