Skip to content

Commit

Permalink
Use Fiber.key
Browse files Browse the repository at this point in the history
  • Loading branch information
emberian committed Jan 10, 2024
1 parent 2b50e18 commit 99bb178
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/lib/o1trace/o1trace.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module Thread : sig
module Fiber : sig
type t = Thread.Fiber.t =
{ id : int; parent : t option; thread : Thread.t; key : string list }

val key : t -> string list
end

val iter_fibers : f:(Fiber.t -> unit) -> unit
Expand Down
2 changes: 2 additions & 0 deletions src/lib/o1trace/thread.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ module Fiber = struct
Execution_context.with_local ctx ctx_id (Some t)

let of_context ctx = Execution_context.find_local ctx ctx_id

let key { thread = { name; _ }; parent; _ } = fiber_key name parent
end

let of_context ctx =
Expand Down
17 changes: 6 additions & 11 deletions src/lib/o1trace/webkit_event/o1trace_webkit_event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ let new_event (k : event_kind) : event =
; tid = 0
}

let new_thread_event ?(include_name = false) thread_key tid event_kind =
{ (new_event event_kind) with
tid
; name = (if include_name then String.concat ~sep:"/" thread_key else "")
}
let new_thread_event ?(include_name = "") tid event_kind =
{ (new_event event_kind) with tid; name = include_name }

(*
Expand Down Expand Up @@ -95,13 +92,13 @@ module T = struct
let on_job_enter (fiber : O1trace.Thread.Fiber.t) =
if fiber.id <> !most_recent_id then (
most_recent_id := fiber.id ;
emit_event (new_thread_event fiber.key fiber.id Thread_switch) )
emit_event (new_thread_event fiber.id Thread_switch) )

let on_job_exit _fiber _time_elapsed = ()

let on_new_fiber (fiber : O1trace.Thread.Fiber.t) =
emit_event
(new_thread_event ~include_name:true fiber.key fiber.id New_thread)
let fullname = String.concat ~sep:"/" (O1trace.Thread.Fiber.key fiber) in
emit_event (new_thread_event ~include_name:fullname fiber.id New_thread)

let on_cycle_end () =
if !emitted_since_cycle_ended then emit_event (new_event Cycle_end) ;
Expand All @@ -114,9 +111,7 @@ let start_tracing wr =
else (
current_wr := Some wr ;
emit_event (new_event Pid_is) ;
O1trace.Thread.iter_fibers ~f:(fun fiber ->
emit_event
(new_thread_event ~include_name:true fiber.key fiber.id New_thread) ) ;
O1trace.Thread.iter_fibers ~f:T.on_new_fiber ;
O1trace.Plugins.enable_plugin (module T) )

let stop_tracing () =
Expand Down

0 comments on commit 99bb178

Please sign in to comment.