@@ -104,57 +104,57 @@ let as_string = function
104104 | `String s -> s
105105 | _ -> failwith " Not a string"
106106
107- let layout ~duration (ring : Ring.t ) =
107+ let rec layout_item ~duration ~y (i : item ) =
108+ if debug_layout then Fmt. epr " %d is at %d@." i.id y;
109+ i.y < - y;
110+ i.height < - 1 ;
111+ i.end_cc_label < - None ;
112+ let intervals = ref [] in
113+ i.events |> Array. iter (fun (ts , e ) ->
114+ match e with
115+ | Log _ | Error _ ->
116+ if i.end_cc_label = None then (
117+ i.end_cc_label < - Some ts;
118+ )
119+ | Add_fiber _ -> ()
120+ | Create_cc (_ , child ) ->
121+ if debug_layout then Fmt. epr " %d creates cc %d (%a)@." i.id child.id Fmt. (option string ) child.name;
122+ if i.end_cc_label = None then (
123+ i.end_cc_label < - Some ts;
124+ );
125+ layout_item ~duration ~y child;
126+ i.height < - max i.height child.height;
127+ let stop = Option. value child.end_time ~default: duration in
128+ intervals := { Itv. value = child; start = ts; stop } :: ! intervals;
129+ );
130+ if i.end_cc_label = None then i.end_cc_label < - i.end_time;
131+ let start_fibers = List. length ! intervals in
132+ i.events |> Array. iter (fun (ts , e ) ->
133+ match e with
134+ | Log _ | Error _ | Create_cc _ -> ()
135+ | Add_fiber { parent; child } ->
136+ if debug_layout then Fmt. epr " %d gets fiber %d, created by %d@." i.id child.id parent;
137+ let stop = Option. value child.end_time ~default: duration in
138+ intervals := { Itv. value = child; start = ts; stop } :: ! intervals;
139+ );
140+ let intervals = List. rev ! intervals in
141+ let itv = Itv. create intervals in
142+ let height = ref i.height in
143+ intervals |> List. to_seq |> Seq. drop start_fibers |> Seq. iter (fun (interval : _ Itv.interval ) ->
144+ let y = ref (i.y + 1 ) in
145+ let adjust other =
146+ y := max ! y (other.y + other.height);
147+ in
148+ Itv. iter_overlaps adjust interval.start interval.stop itv;
149+ let f = interval.Itv. value in
150+ layout_item ~duration ~y: ! y f;
151+ height := max ! height (f.y - i.y + f.height);
152+ );
153+ i.height < - ! height;
154+ if debug_layout then Fmt. epr " %d is at %d+%d@." i.id y i.height
155+
156+ let layout_ring ~duration (ring : Ring.t ) =
108157 let max_y = ref 1 in
109- let rec visit ~y (i : item ) =
110- if debug_layout then Fmt. epr " %d is at %d@." i.id y;
111- i.y < - y;
112- i.height < - 1 ;
113- i.end_cc_label < - None ;
114- let intervals = ref [] in
115- i.events |> Array. iter (fun (ts , e ) ->
116- match e with
117- | Log _ | Error _ ->
118- if i.end_cc_label = None then (
119- i.end_cc_label < - Some ts;
120- )
121- | Add_fiber _ -> ()
122- | Create_cc (_ , child ) ->
123- if debug_layout then Fmt. epr " %d creates cc %d (%a)@." i.id child.id Fmt. (option string ) child.name;
124- if i.end_cc_label = None then (
125- i.end_cc_label < - Some ts;
126- );
127- visit ~y child;
128- i.height < - max i.height child.height;
129- let stop = Option. value child.end_time ~default: duration in
130- intervals := { Itv. value = child; start = ts; stop } :: ! intervals;
131- );
132- if i.end_cc_label = None then i.end_cc_label < - i.end_time;
133- let start_fibers = List. length ! intervals in
134- i.events |> Array. iter (fun (ts , e ) ->
135- match e with
136- | Log _ | Error _ | Create_cc _ -> ()
137- | Add_fiber { parent; child } ->
138- if debug_layout then Fmt. epr " %d gets fiber %d, created by %d@." i.id child.id parent;
139- let stop = Option. value child.end_time ~default: duration in
140- intervals := { Itv. value = child; start = ts; stop } :: ! intervals;
141- );
142- let intervals = List. rev ! intervals in
143- let itv = Itv. create intervals in
144- let height = ref i.height in
145- intervals |> List. to_seq |> Seq. drop start_fibers |> Seq. iter (fun (interval : _ Itv.interval ) ->
146- let y = ref (i.y + 1 ) in
147- let adjust other =
148- y := max ! y (other.y + other.height);
149- in
150- Itv. iter_overlaps adjust interval.start interval.stop itv;
151- let f = interval.Itv. value in
152- visit ~y: ! y f;
153- height := max ! height (f.y - i.y + f.height);
154- );
155- i.height < - ! height;
156- if debug_layout then Fmt. epr " %d is at %d+%d@." i.id y i.height;
157- in
158158 let visit_domain root =
159159 root.Ring. cc |> Option. iter @@ fun (_ts , (i : item )) ->
160160 i.y < - ring.y + 1 ;
@@ -164,7 +164,7 @@ let layout ~duration (ring : Ring.t) =
164164 match e with
165165 | Log _ | Error _ | Create_cc _ -> ()
166166 | Add_fiber { parent = _ ; child } ->
167- visit ~y: (ring.y + i.height) child;
167+ layout_item ~duration ~y: (ring.y + i.height) child;
168168 i.height < - child.y - ring.y + child.height;
169169 if i.end_cc_label = None then (
170170 i.end_cc_label < - child.end_cc_label;
@@ -233,7 +233,7 @@ let of_trace (trace : Trace.t) =
233233 let y = ref 0 in
234234 rings |> Trace.Rings. iter (fun _ (ring : Ring.t ) ->
235235 ring.y < - ! y;
236- layout ring ~duration ;
236+ layout_ring ring ~duration ;
237237 y := ! y + ring.height;
238238 );
239239 let height = ! y in
0 commit comments