package tracing

  1. Overview
  2. Docs
Tracing library

Install

Dune Dependency

Authors

Maintainers

Sources

v0.17.0.tar.gz
sha256=5621f8fd41d64521cc88295417e48174f525a7e6e4f8a72885ba89056d461a72

doc/src/tracing.tracing_destinations_unix/tracing_destinations_unix.ml.html

Source file tracing_destinations_unix.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
42
43
44
open! Core

module type Destination = Tracing_zero.Writer_intf.Destination

let fd_destination_from buf file ~do_close =
  let flush () =
    Iobuf.flip_lo buf;
    Iobuf_unix.write buf file;
    Iobuf.reset buf
  in
  let module Dest = struct
    let next_buf ~ensure_capacity =
      flush ();
      if ensure_capacity > Iobuf.length buf
      then failwith "Not enough buffer space in [direct_file_destination]";
      buf
    ;;

    let close () =
      flush ();
      if do_close then Core_unix.close file
    ;;
  end
  in
  (module Dest : Destination)
;;

let direct_file_destination ?(buffer_size = 4096 * 16) ~filename () =
  let buf = Iobuf.create ~len:buffer_size in
  let file = Core_unix.openfile ~mode:[ O_CREAT; O_TRUNC; O_RDWR ] filename in
  fd_destination_from buf file ~do_close:true
;;

let fd_destination ?(buffer_size = 4096 * 16) ~fd () =
  let buf = Iobuf.create ~len:buffer_size in
  fd_destination_from buf fd ~do_close:false
;;

let file_destination ~filename () = direct_file_destination ~filename ()

let file_writer ?num_temp_strs ~filename () =
  let destination = file_destination ~filename () in
  Tracing_zero.Writer.Expert.create ?num_temp_strs ~destination ()
;;
OCaml

Innovation. Community. Security.