Skip to content

Commit 1e76484

Browse files
authored
Merge pull request #21 from talex5/cancel
Show cancellations
2 parents 82a886b + c6ae0e1 commit 1e76484

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

lib/layout.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ end
4646

4747
type event =
4848
| Log of string
49+
| Error of string
4950
| Create_cc of string * item
5051
| Add_fiber of { parent : int; child : item }
5152
and item = {
@@ -87,6 +88,7 @@ let get t id = Ids.find_opt id t.items
8788

8889
let map_event f : Trace.event -> event = function
8990
| Log x -> Log x
91+
| Error x -> Error x
9092
| Create_cc (ty, x) -> Create_cc (ty, f x)
9193
| Add_fiber { parent; child } -> Add_fiber { parent; child = f child }
9294

@@ -112,7 +114,7 @@ let layout ~duration (ring : Ring.t) =
112114
let intervals = ref [] in
113115
i.events |> Array.iter (fun (ts, e) ->
114116
match e with
115-
| Log _ ->
117+
| Log _ | Error _ ->
116118
if i.end_cc_label = None then (
117119
i.end_cc_label <- Some ts;
118120
)
@@ -131,7 +133,7 @@ let layout ~duration (ring : Ring.t) =
131133
let start_fibers = List.length !intervals in
132134
i.events |> Array.iter (fun (ts, e) ->
133135
match e with
134-
| Log _ | Create_cc _ -> ()
136+
| Log _ | Error _ | Create_cc _ -> ()
135137
| Add_fiber { parent; child } ->
136138
if debug_layout then Fmt.epr "%d gets fiber %d, created by %d@." i.id child.id parent;
137139
let stop = Option.value child.end_time ~default:duration in
@@ -161,7 +163,7 @@ let layout ~duration (ring : Ring.t) =
161163
i.end_cc_label <- None;
162164
i.events |> Array.iter (fun (_ts, e) ->
163165
match e with
164-
| Log _ | Create_cc _ -> ()
166+
| Log _ | Error _ | Create_cc _ -> ()
165167
| Add_fiber { parent = _; child } ->
166168
visit ~y:(ring.y + i.height) child;
167169
i.height <- child.y - ring.y + child.height;

lib/render.ml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,26 @@ module Make (C : CANVAS) = struct
119119
let x = View.x_of_time v ts in
120120
link_fibers v cr ~x parent child
121121
| Create_cc (ty, cc) -> render_cc v cr ts cc ty
122-
| Log msg ->
122+
| Log msg | Error msg ->
123+
let is_error = match e with Error _ -> true | _ -> false in
123124
let x = View.x_of_time v ts in
124-
let y = y_of_row v item.y +. 10. in
125-
C.move_to cr ~x ~y:(y +. 3.);
126-
C.line_to cr ~x ~y:(y -. 3.);
127-
C.set_source_rgb cr ~r:0.0 ~g:0.0 ~b:0.0;
125+
let y = y_of_row v item.y in
126+
if is_error then (
127+
C.set_source_rgb cr ~r:0.8 ~g:0.0 ~b:0.0;
128+
C.move_to cr ~x ~y;
129+
C.line_to cr ~x ~y:(y +. float item.height *. View.pixels_per_row);
130+
) else (
131+
C.set_source_rgb cr ~r:0.0 ~g:0.0 ~b:0.0;
132+
C.move_to cr ~x ~y:(y +. 13.);
133+
C.line_to cr ~x ~y:(y +. 7.);
134+
);
128135
C.stroke cr;
129136
C.set_font_size cr Style.small_text;
130137
let clip_area = next |> Option.map (fun t2 ->
131138
let x2 = View.x_of_time v t2 in
132139
(x2 -. x -. 2.0, v.height)
133140
) in
134-
C.paint_text cr ~x:(x +. 2.) ~y:(y -. 2.) msg
141+
C.paint_text cr ~x:(x +. 2.) ~y:(y +. 8.) msg
135142
?clip_area
136143
done
137144

lib/trace.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type activation = [
1717

1818
type event =
1919
| Log of string
20+
| Error of string
2021
| Create_cc of string * item
2122
| Add_fiber of { parent : int; child : item }
2223
and item = {
@@ -185,6 +186,11 @@ let process_event t e =
185186
fiber_of_thread t thread |> Option.iter @@ fun fiber ->
186187
let item = get t (fiber.inner_cc) in
187188
item.events <- (timestamp, Log msg) :: item.events
189+
| "eio", "error", Instant ->
190+
let id = List.assoc_opt "id" args |> Option.get |> id_of_pointer in
191+
let msg = List.assoc_opt "message" args |> Option.get |> as_string in
192+
let item = get t id in
193+
item.events <- (timestamp, Error msg) :: item.events
188194
| "eio", "exit-fiber", Instant ->
189195
let id = List.assoc_opt "id" args |> Option.get |> id_of_pointer in
190196
let item = get t id in

src/record.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ let callbacks t =
148148
Write.instant_event t.fxt ~thread ~ts ~name:"domain-spawn" ~category:"eio" ~args:[
149149
"parent", `Pointer (Int64.of_int parent);
150150
];
151+
| `Error (id, err) ->
152+
Write.instant_event t.fxt ~thread ~ts ~name:"error" ~category:"eio" ~args:[
153+
"id", `Pointer (Int64.of_int id);
154+
"message", `String err;
155+
]
151156
| _ -> ()
152157
)
153158

0 commit comments

Comments
 (0)