Skip to content

Commit 4a91a67

Browse files
committed
Update tracing section of README
1 parent d9a7e20 commit 4a91a67

File tree

8 files changed

+402
-283
lines changed

8 files changed

+402
-283
lines changed

README.md

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -220,70 +220,30 @@ Calling an operation that performs an effect (such as `yield`) can switch to a d
220220
When OCaml's tracing is turned on, Eio writes events about many actions,
221221
such as creating fibers or resolving promises.
222222

223-
[examples/trace](./examples/trace/) shows how to consume the events manually:
223+
You can use [eio-trace][] to capture a trace and display it in a window.
224+
For example, this is a trace of the counting example above:
224225

225-
<!-- $MDX skip -->
226-
```sh
227-
$ dune exec -- ./examples/trace/main.exe
228-
+tracer: starting
229-
30926487700447:ring 0: create fiber 0
230-
30926487702032:ring 0: running fiber 0
231-
30926487705057:ring 0: create switch 1
232-
30926487707264:ring 0: create fiber 2
233-
30926487707512:ring 0: running fiber 2
234-
30926487720213:ring 0: log "tracer: starting"
235-
+server: starting
236-
+client: connecting socket...
237-
+server: got connection from client
238-
+server: read "Hello" from socket
239-
30926487769298:ring 0: running fiber 0
240-
30926487769877:ring 0: create fiber 3
241-
30926487770083:ring 0: running fiber 3
242-
30926487771198:ring 0: create switch 4
243-
30926487807888:ring 0: create switch 5
244-
30926487808329:ring 0: create fiber 6
245-
30926487808555:ring 0: running fiber 6
246-
30926487812219:ring 0: log "server: starting"
247-
30926487818883:ring 0: running fiber 3
248-
30926487819091:ring 0: create fiber 7
249-
30926487819155:ring 0: running fiber 7
250-
30926487822428:ring 0: log "client: connecting socket..."
251-
30926487901604:ring 0: running fiber 3
252-
30926487904947:ring 0: running fiber 0
253-
30926487907318:ring 0: running fiber 6
254-
30926487917202:ring 0: log "server: got connection from client"
255-
30926487929993:ring 0: running fiber 6
256-
30926487941403:ring 0: running fiber 7
257-
30926487948000:ring 0: running fiber 7
258-
30926487971898:ring 0: resolve 7
259-
30926487974810:ring 0: running fiber 6
260-
30926487975215:ring 0: running fiber 6
261-
30926487977869:ring 0: running fiber 6
262-
30926487984514:ring 0: log "server: read \"Hello\" from socket"
263-
30926487990785:ring 0: resolve 6
264-
30926487991752:ring 0: running fiber 3
265-
30926488022310:ring 0: resolve 3
266-
30926497839725:ring 0: running fiber 2
267-
+tracer: stopping
268226
```
227+
dune build ./examples
228+
eio-trace run -- ./_build/default/examples/both/main.exe
229+
```
230+
231+
<p align='center'>
232+
<img src="./doc/traces/both-posix.svg"/>
233+
</p>
269234

235+
The upper horizontal bar is the initial fiber, and the brackets show `Fiber.both` creating a second fiber.
236+
The green segments show when each fiber is running.
270237
Note that the output from `traceln` appears in the trace as well as on the console.
238+
In the eio-trace window, scrolling with the mouse or touchpad will zoom in or out of the diagram.
271239

272-
There are various third-party tools that can consume this data
240+
There are various third-party tools that can also consume this data
273241
(but may currently require patches to support the new system):
274242

275243
- [Meio][] (Monitoring for Eio) provides an interactive console-based UI for exploring running fibers.
276244
- [Olly][] can save Perfetto traces and report statistics.
277-
- [mirage-trace-viewer][] renders traces visually.
278-
279-
For example, this is how mirage-trace-viewer renders the counting example above:
280-
281-
<p align='center'>
282-
<img src="./doc/trace.svg"/>
283-
</p>
284245

285-
This shows the two counting threads as two horizonal lines.
286-
The white regions indicate when each thread was running.
246+
[examples/trace](./examples/trace/) shows how to consume the events manually.
287247

288248
## Cancellation
289249

@@ -1893,3 +1853,4 @@ Some background about the effects system can be found in:
18931853
[Eio.Process]: https://ocaml-multicore.github.io/eio/eio/Eio/Process/index.html
18941854
[Dev meetings]: https://docs.google.com/document/d/1ZBfbjAkvEkv9ldumpZV5VXrEc_HpPeYjHPW_TiwJe4Q
18951855
[Olly]: https://github.com/tarides/runtime_events_tools
1856+
[eio-trace]: https://github.com/ocaml-multicore/eio-trace

doc/trace.svg

Lines changed: 0 additions & 223 deletions
This file was deleted.

doc/traces/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
all:
2+
eio-trace render -f both-posix.fxt both-posix.svg

doc/traces/both-posix.fxt

1.77 KB
Binary file not shown.

doc/traces/both-posix.svg

Lines changed: 372 additions & 0 deletions
Loading

examples/both/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(executable
2+
(name main)
3+
(libraries eio_main))

examples/both/main.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
open Eio.Std
2+
3+
let () =
4+
Eio_main.run @@ fun _env ->
5+
Fiber.both
6+
(fun () -> for x = 1 to 3 do traceln "x = %d" x; Fiber.yield () done)
7+
(fun () -> for y = 1 to 3 do traceln "y = %d" y; Fiber.yield () done)

lib_eio/unix/private.ml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ module Rcfd = Rcfd
1818
module Fork_action = Fork_action
1919

2020
let run_in_systhread ?(label="systhread") fn =
21-
Eio.Private.Suspend.enter label @@ fun fiber enqueue ->
22-
match Eio.Private.Fiber_context.get_error fiber with
23-
| Some err -> enqueue (Error err)
24-
| None ->
25-
let _t : Thread.t = Thread.create (fun () -> enqueue (try Ok (fn ()) with exn -> Error exn)) () in
26-
()
21+
Eio.Private.Suspend.enter label @@ fun _ctx enqueue ->
22+
let _t : Thread.t = Thread.create (fun () -> enqueue (try Ok (fn ()) with exn -> Error exn)) () in
23+
()

0 commit comments

Comments
 (0)