-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate sqlite, client, and daemon to
Trace_core
- Loading branch information
Showing
25 changed files
with
130 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
(executable | ||
(name heavy) | ||
(optional) | ||
(libraries threads.posix unix catapult catapult-file catapult-sqlite | ||
(libraries threads.posix trace unix catapult catapult-sqlite | ||
catapult-client)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
module type ARG = sig | ||
val conn : Connections.t | ||
end | ||
|
||
module Make (_ : ARG) : Catapult.BACKEND | ||
val make : Connection.t -> Catapult.backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,14 @@ | ||
module P = Catapult | ||
module Endpoint_address = Catapult_utils.Endpoint_address | ||
|
||
let trace_id = ref (try Sys.getenv "TRACE_ID" with _ -> "") | ||
let set_trace_id s = trace_id := s | ||
|
||
(* try to make a non-stupid default id, based on PID + date. | ||
This is not perfect, use a UUID4 if possible. *) | ||
let[@inline never] invent_trace_id_ () : string = | ||
let pid = Unix.getpid () in | ||
let now = Unix.gettimeofday () in | ||
let tm = Unix.gmtime now in | ||
Printf.sprintf "catapult-%d-%02d-%02d-%02d-%02d-%02d-pid-%d" | ||
(1900 + tm.tm_year) (tm.tm_mon + 1) tm.tm_mday tm.tm_hour tm.tm_min | ||
tm.tm_sec pid | ||
(** Backend for Catapult, using a connection to the daemon. | ||
*) | ||
|
||
let[@inline] get_trace_id () = | ||
if !trace_id = "" then trace_id := invent_trace_id_ (); | ||
!trace_id | ||
module Endpoint_address = Catapult_utils.Endpoint_address | ||
module Backend = Backend | ||
module Connection = Connection | ||
|
||
let default_endpoint = Endpoint_address.default | ||
let with_conn = Connection.with_ | ||
let backend_of_conn : Connection.t -> Catapult.backend = Backend.make | ||
|
||
let endpoint = | ||
ref | ||
(try Endpoint_address.of_string_exn (Sys.getenv "TRACE_ENDPOINT") | ||
with _ -> default_endpoint) | ||
|
||
let set_endpoint e = endpoint := e | ||
let get_endpoint () = !endpoint | ||
let set_tcp_endpoint h p = set_endpoint (Endpoint_address.Tcp (h, p)) | ||
let set_ipc_endpoint file = set_endpoint (Endpoint_address.Unix file) | ||
let tef_in_env () = List.mem (Sys.getenv_opt "TRACE") [ Some "1"; Some "true" ] | ||
|
||
let mk_lazy_enable getenv = | ||
let r = ref false in | ||
let enabled_thunk = lazy (!r || getenv ()) in | ||
let[@inline] enabled () = Lazy.force enabled_thunk in | ||
let enable () = if not !r then r := true in | ||
enable, enabled | ||
|
||
let enable, enabled = mk_lazy_enable tef_in_env | ||
|
||
(* FIXME: with_ … *) | ||
let setup_ = | ||
lazy | ||
(if enabled () then ( | ||
at_exit P.Control.teardown; | ||
let trace_id = get_trace_id () in | ||
let conn = Connections.create ~addr:!endpoint ~trace_id () in | ||
let module B = Backend.Make (struct | ||
let conn = conn | ||
end) in | ||
let backend = (module B : P.BACKEND) in | ||
P.Control.setup (Some backend) | ||
)) | ||
|
||
let setup () = Lazy.force setup_ | ||
let teardown = P.Tracing.Control.teardown | ||
|
||
let with_setup f = | ||
setup (); | ||
try | ||
let x = f () in | ||
teardown (); | ||
x | ||
with e -> | ||
teardown (); | ||
raise e | ||
(** Obtain a trace collector from a network connection *) | ||
let trace_collector_of_conn : Connection.t -> Trace_core.collector = | ||
fun conn -> backend_of_conn conn |> Catapult.trace_collector_of_backend |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
open Catapult_utils | ||
|
||
type t | ||
|
||
val default_addr : Endpoint_address.t | ||
val create : addr:Endpoint_address.t -> ?trace_id:string -> unit -> t | ||
val send_msg : t -> pid:int -> now:float -> Ser.Event.t -> unit | ||
val close : t -> unit | ||
|
||
val with_ : | ||
addr:Endpoint_address.t -> ?trace_id:string -> unit -> (t -> 'a) -> 'a |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.