Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Ctf to Trace and tidy #634

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ We can run the previous code with tracing enabled (writing to a new `trace.ctf`

```ocaml
# let () =
Eio_unix.Ctf.with_tracing "trace.ctf" @@ fun () ->
Eio_unix.Trace.with_tracing "trace.ctf" @@ fun () ->
Eio_main.run main;;
+x = 1
+y = 1
Expand Down
6 changes: 3 additions & 3 deletions lib_eio/core/cancel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type t = {
domain : Domain.id; (* Prevent access from other domains *)
}
and fiber_context = {
tid : Ctf.id;
tid : Trace.id;
mutable cancel_context : t;
mutable cancel_node : fiber_context Lwt_dllist.node option; (* Our entry in [cancel_context.fibers] *)
mutable cancel_fn : exn -> unit; (* Encourage the current operation to finish *)
Expand Down Expand Up @@ -194,8 +194,8 @@ module Fiber_context = struct
t.cancel_fn <- ignore

let make ~cc ~vars =
let tid = Ctf.mint_id () in
Ctf.note_created tid Ctf.Task;
let tid = Trace.mint_id () in
Trace.create tid Fiber;
let t = { tid; cancel_context = cc; cancel_node = None; cancel_fn = ignore; vars } in
t.cancel_node <- Some (Lwt_dllist.add_r t cc.fibers);
t
Expand Down
110 changes: 0 additions & 110 deletions lib_eio/core/ctf.mli

This file was deleted.

2 changes: 1 addition & 1 deletion lib_eio/core/debug.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let default_traceln ?__POS__:pos fmt =
Format.pp_close_box f ();
Format.pp_print_flush f ();
let msg = Buffer.contents b in
Ctf.label msg;
Trace.label msg;
let lines = String.split_on_char '\n' msg in
Mutex.lock traceln_mutex;
Fun.protect ~finally:(fun () -> Mutex.unlock traceln_mutex) @@ fun () ->
Expand Down
2 changes: 1 addition & 1 deletion lib_eio/core/eio__core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Private = struct
module Suspend = Suspend
module Cells = Cells
module Broadcast = Broadcast
module Ctf = Ctf
module Trace = Trace
module Fiber_context = Cancel.Fiber_context
module Debug = Debug

Expand Down
4 changes: 2 additions & 2 deletions lib_eio/core/eio__core.mli
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ end

(** @canonical Eio.Private *)
module Private : sig
module Ctf = Ctf
module Trace = Trace

module Cells = Cells
module Broadcast = Broadcast
Expand All @@ -586,7 +586,7 @@ module Private : sig
val destroy : t -> unit
(** [destroy t] removes [t] from its cancellation context. *)

val tid : t -> Ctf.id
val tid : t -> Trace.id

(** {2 Cancellation}

Expand Down
10 changes: 5 additions & 5 deletions lib_eio/core/fiber.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ let fork ~sw f =
Switch.with_op sw @@ fun () ->
match f () with
| () ->
Ctf.note_resolved (Cancel.Fiber_context.tid new_fiber) ~ex:None
Trace.resolve (Cancel.Fiber_context.tid new_fiber) ~ex:None
| exception ex ->
Switch.fail sw ex; (* The [with_op] ensures this will succeed *)
Ctf.note_resolved (Cancel.Fiber_context.tid new_fiber) ~ex:(Some ex)
Trace.resolve (Cancel.Fiber_context.tid new_fiber) ~ex:(Some ex)
) (* else the fiber should report the error to [sw], but [sw] is failed anyway *)

let fork_daemon ~sw f =
Expand All @@ -35,13 +35,13 @@ let fork_daemon ~sw f =
match f () with
| `Stop_daemon ->
(* The daemon asked to stop. *)
Ctf.note_resolved (Cancel.Fiber_context.tid new_fiber) ~ex:None
Trace.resolve (Cancel.Fiber_context.tid new_fiber) ~ex:None
| exception Cancel.Cancelled Exit when not (Cancel.is_on sw.cancel) ->
(* The daemon was cancelled because all non-daemon fibers are finished. *)
Ctf.note_resolved (Cancel.Fiber_context.tid new_fiber) ~ex:None
Trace.resolve (Cancel.Fiber_context.tid new_fiber) ~ex:None
| exception ex ->
Switch.fail sw ex; (* The [with_daemon] ensures this will succeed *)
Ctf.note_resolved (Cancel.Fiber_context.tid new_fiber) ~ex:(Some ex)
Trace.resolve (Cancel.Fiber_context.tid new_fiber) ~ex:(Some ex)
) (* else the fiber should report the error to [sw], but [sw] is failed anyway *)

let fork_promise ~sw f =
Expand Down
18 changes: 9 additions & 9 deletions lib_eio/core/promise.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type 'a state =
| Unresolved of Broadcast.t

type !'a promise = {
id : Ctf.id;
id : Trace.id;
state : 'a state Atomic.t; (* Note: we always switch to Resolved before broadcasting *)
}

Expand All @@ -25,20 +25,20 @@ let create_with_id id =
to_public_promise t, to_public_resolver t

let create ?label () =
let id = Ctf.mint_id () in
Ctf.note_created ?label id Ctf.Promise;
let id = Trace.mint_id () in
Trace.create ?label id Promise;
create_with_id id

let create_resolved x =
let id = Ctf.mint_id () in
Ctf.note_created id Ctf.Promise;
let id = Trace.mint_id () in
Trace.create id Promise;
to_public_promise { id; state = Atomic.make (Resolved x) }

let await t =
let t = of_public_promise t in
match Atomic.get t.state with
| Resolved x ->
Ctf.note_read t.id;
Trace.read t.id;
x
| Unresolved b ->
Suspend.enter (fun ctx enqueue ->
Expand All @@ -53,15 +53,15 @@ let await t =
| Unresolved _ ->
(* We observed the promise to be still unresolved after registering a waiter.
Therefore any resolution must happen after we were registered and we will be notified. *)
Ctf.note_try_read t.id;
Trace.try_read t.id;
Cancel.Fiber_context.set_cancel_fn ctx (fun ex ->
if Broadcast.cancel request then enqueue (Error ex)
(* else already resumed *)
)
);
match Atomic.get t.state with
| Resolved x ->
Ctf.note_read t.id;
Trace.read t.id;
x
| Unresolved _ -> assert false

Expand All @@ -76,7 +76,7 @@ let resolve t v =
| Resolved _ -> invalid_arg "Can't resolve already-resolved promise"
| Unresolved b as prev ->
if Atomic.compare_and_set t.state prev (Resolved v) then (
Ctf.note_resolved t.id ~ex:None;
Trace.resolve t.id ~ex:None;
Broadcast.resume_all b
) else (
(* Otherwise, the promise was already resolved. Retry (to get the error). *)
Expand Down
2 changes: 1 addition & 1 deletion lib_eio/core/single_waiter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ let await t id =
t.wake <- (fun x ->
Cancel.Fiber_context.clear_cancel_fn ctx;
t.wake <- ignore;
Ctf.note_read ~reader:id ctx.tid;
Trace.read ~reader:id ctx.tid;
enqueue x
)
14 changes: 7 additions & 7 deletions lib_eio/core/switch.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type t = {
id : Ctf.id;
id : Trace.id;
mutable fibers : int; (* Total, including daemon_fibers and the main function *)
mutable daemon_fibers : int;
mutable exs : (exn * Printexc.raw_backtrace) option;
Expand Down Expand Up @@ -51,7 +51,7 @@ let combine_exn ex = function
let fail ?(bt=Printexc.get_raw_backtrace ()) t ex =
check_our_domain t;
if t.exs = None then
Ctf.note_resolved t.id ~ex:(Some ex);
Trace.resolve t.id ~ex:(Some ex);
t.exs <- Some (combine_exn (ex, bt) t.exs);
try
Cancel.cancel t.cancel ex
Expand Down Expand Up @@ -91,7 +91,7 @@ let or_raise = function
let rec await_idle t =
(* Wait for fibers to finish: *)
while t.fibers > 0 do
Ctf.note_try_read t.id;
Trace.try_read t.id;
Single_waiter.await t.waiter t.id
done;
(* Call on_release handlers: *)
Expand All @@ -118,8 +118,8 @@ let maybe_raise_exs t =
| Some (ex, bt) -> Printexc.raise_with_backtrace ex bt

let create cancel =
let id = Ctf.mint_id () in
Ctf.note_created id Ctf.Switch;
let id = Trace.mint_id () in
Trace.create id Switch;
{
id;
fibers = 1; (* The main function counts as a fiber *)
Expand All @@ -135,7 +135,7 @@ let run_internal t fn =
| v ->
dec_fibers t;
await_idle t;
Ctf.note_read t.id;
Trace.read t.id;
maybe_raise_exs t; (* Check for failure while finishing *)
(* Success. *)
v
Expand All @@ -146,7 +146,7 @@ let run_internal t fn =
dec_fibers t;
fail ~bt t ex;
await_idle t;
Ctf.note_read t.id;
Trace.read t.id;
maybe_raise_exs t;
assert false

Expand Down
Loading
Loading