package magic-trace

  1. Overview
  2. Docs
Collects and displays high-resolution traces of what a process is doing

Install

Dune Dependency

Authors

Maintainers

Sources

v1.0.1.tar.gz
sha256=77b2e4b3bc769910656d0fdee4839250548aa49486fd3554f6c057f1d64abe99
sha512=1f111db6348673c22a110611182a92c8aa999668dc077c44bc4abcaa72ccb197899ff2577047888627b50fcc9890824de6c82b4fe9f06129190b8b487ec3f716

doc/src/magic-trace.magic_trace/magic_trace.ml.html

Source file magic_trace.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
open! Core

module Private = struct
  let stop_symbol = "magic_trace_stop_indicator"
end

external stop_indicator : int -> int -> unit = "magic_trace_stop_indicator" [@@noalloc]

let start_time = ref 0

let[@inline] tsc_int () =
  let tsc = Time_stamp_counter.now () in
  Time_stamp_counter.to_int63 tsc |> Int63.to_int_exn
;;

let mark_start () = start_time := tsc_int ()

module Min_duration = struct
  type t = int

  let of_ns ns =
    Time_stamp_counter.Span.of_ns
      (Int63.of_int ns)
      ~calibrator:(force Time_stamp_counter.calibrator)
    |> Time_stamp_counter.Span.to_int_exn
  ;;

  let over min =
    let span = tsc_int () - !start_time in
    span > min
  ;;
end

let take_snapshot_with_arg i = stop_indicator !start_time i

let take_snapshot_with_time_and_arg tsc i =
  let tsc_i = Time_stamp_counter.to_int63 tsc |> Int63.to_int_exn in
  stop_indicator tsc_i i
;;

let take_snapshot () = take_snapshot_with_arg 0
OCaml

Innovation. Community. Security.