@@ -16,7 +16,7 @@ let next_tef_pid = ref 0
1616module Make (Name : Name ): S =
1717struct
1818 let enabled_dls = Domain.DLS. new_key (fun () -> false )
19- let options_dls = Domain.DLS. new_key ( fun () -> dummy_options)
19+ let options = ref dummy_options
2020 let tef_pid =
2121 let tef_pid = ! next_tef_pid in
2222 incr next_tef_pid;
@@ -55,12 +55,11 @@ struct
5555 let current_allocated = Gc. allocated_bytes
5656
5757 let create_frame tree =
58- let options = Domain.DLS. get options_dls in
5958 {
6059 tree;
61- start_cputime = if options.cputime then current_cputime () else 0.0 ;
62- start_walltime = if options.walltime then current_walltime () else 0.0 ;
63- start_allocated = if options.allocated then current_allocated () else 0.0 ;
60+ start_cputime = if ! options.cputime then current_cputime () else 0.0 ;
61+ start_walltime = if ! options.walltime then current_walltime () else 0.0 ;
62+ start_allocated = if ! options.allocated then current_allocated () else 0.0 ;
6463 }
6564
6665 (* * Stack of currently active timing frames. *)
8079 )
8180
8281 let start options' =
83- Domain.DLS. set options_dls options';
84- let options = Domain.DLS. get options_dls in
85- if options.tef then (
82+ options := options';
83+ if ! options.tef then (
8684 (* Override TEF process and thread name for track rendering. *)
8785 Catapult.Tracing. emit ~pid: tef_pid " thread_name" ~cat: [" __firefox_profiler_hack__" ] ~args: [(" name" , `String Name. name)] Catapult.Event_type. M ;
8886 (* First event must have category, otherwise Firefox Profiler refuses to open. *)
9694 Domain.DLS. set enabled_dls false
9795
9896 let enter ?args name =
99- let options = Domain.DLS. get options_dls in
10097 (* Find the right tree. *)
10198 let tree: tree =
10299 let {tree; _} = Stack. top (Domain.DLS. get current) in
@@ -112,33 +109,31 @@ struct
112109 loop tree.children
113110 in
114111 Stack. push (create_frame tree) (Domain.DLS. get current);
115- if options.tef then
112+ if ! options.tef then
116113 Catapult.Tracing. begin ' ~pid: tef_pid ?args name
117114
118115 (* * Add current frame measurements to tree node accumulators. *)
119116 let add_frame_to_tree frame tree =
120- let options = Domain.DLS. get options_dls in
121- if options.cputime then (
117+ if ! options.cputime then (
122118 let diff = current_cputime () -. frame.start_cputime in
123119 tree.cputime < - tree.cputime +. diff
124120 );
125- if options.walltime then (
121+ if ! options.walltime then (
126122 let diff = current_walltime () -. frame.start_walltime in
127123 tree.walltime < - tree.walltime +. diff
128124 );
129- if options.allocated then (
125+ if ! options.allocated then (
130126 let diff = current_allocated () -. frame.start_allocated in
131127 tree.allocated < - tree.allocated +. diff
132128 );
133- if options.count then
129+ if ! options.count then
134130 tree.count < - tree.count + 1
135131
136132 let exit name =
137- let options = Domain.DLS. get options_dls in
138133 let {tree; _} as frame = Stack. pop (Domain.DLS. get current) in
139134 assert (tree.name = name);
140135 add_frame_to_tree frame tree;
141- if options.tef then
136+ if ! options.tef then
142137 Catapult.Tracing. exit' ~pid: tef_pid name
143138
144139 let wrap ?args name f x =
@@ -186,30 +181,28 @@ struct
186181 tree_with_current current_rev root
187182
188183 let rec pp_tree ppf node =
189- let options = Domain.DLS. get options_dls in
190184 Format. fprintf ppf " @[<v 2>%-25s " node.name;
191- if options.cputime then
185+ if ! options.cputime then
192186 Format. fprintf ppf " %9.3fs" node.cputime;
193- if options.walltime then
187+ if ! options.walltime then
194188 Format. fprintf ppf " %10.3fs" node.walltime;
195- if options.allocated then
189+ if ! options.allocated then
196190 Format. fprintf ppf " %10.2fMB" (node.allocated /. 1_000_000.0 ); (* TODO: or should it be 1024-based (MiB)? *)
197- if options.count then
191+ if ! options.count then
198192 Format. fprintf ppf " %7d×" node.count;
199193 (* cut also before first child *)
200194 List. iter (Format. fprintf ppf " @,%a" pp_tree) (List. rev node.children);
201195 Format. fprintf ppf " @]"
202196
203197 let pp_header ppf =
204- let options = Domain.DLS. get options_dls in
205198 Format. fprintf ppf " %-25s " " " ;
206- if options.cputime then
199+ if ! options.cputime then
207200 Format. fprintf ppf " cputime" ;
208- if options.walltime then
201+ if ! options.walltime then
209202 Format. fprintf ppf " walltime" ;
210- if options.allocated then
203+ if ! options.allocated then
211204 Format. fprintf ppf " allocated" ;
212- if options.count then
205+ if ! options.count then
213206 Format. fprintf ppf " count" ;
214207 Format. fprintf ppf " @\n "
215208
0 commit comments