@@ -221,35 +221,73 @@ Calling an operation that performs an effect (such as `yield`) can switch to a d
221221
222222## Tracing
223223
224- The library can write traces in CTF format, showing when threads (fibers) are created, when they run, and how they interact.
225- We can run the previous code with tracing enabled (writing to a new ` trace.ctf ` file) like this:
224+ When OCaml's tracing is turned on, Eio writes events about many actions,
225+ such as creating fibers or resolving promises.
226226
227- ``` ocaml
228- # let () =
229- Eio_unix.Trace.with_tracing "trace.ctf" @@ fun () ->
230- Eio_main.run main;;
231- +x = 1
232- +y = 1
233- +x = 2
234- +y = 2
235- +x = 3
236- +y = 3
227+ [ examples/trace] ( ./examples/trace/ ) shows how to consume the events manually:
228+
229+ <!-- $MDX skip -->
230+ ``` sh
231+ $ dune exec -- ./examples/trace/main.exe
232+ +tracer: starting
233+ 30926487700447:ring 0: create fiber 0
234+ 30926487702032:ring 0: running fiber 0
235+ 30926487705057:ring 0: create switch 1
236+ 30926487707264:ring 0: create fiber 2
237+ 30926487707512:ring 0: running fiber 2
238+ 30926487720213:ring 0: log " tracer: starting"
239+ +server: starting
240+ +client: connecting socket...
241+ +server: got connection from client
242+ +server: read " Hello" from socket
243+ 30926487769298:ring 0: running fiber 0
244+ 30926487769877:ring 0: create fiber 3
245+ 30926487770083:ring 0: running fiber 3
246+ 30926487771198:ring 0: create switch 4
247+ 30926487807888:ring 0: create switch 5
248+ 30926487808329:ring 0: create fiber 6
249+ 30926487808555:ring 0: running fiber 6
250+ 30926487812219:ring 0: log " server: starting"
251+ 30926487818883:ring 0: running fiber 3
252+ 30926487819091:ring 0: create fiber 7
253+ 30926487819155:ring 0: running fiber 7
254+ 30926487822428:ring 0: log " client: connecting socket..."
255+ 30926487901604:ring 0: running fiber 3
256+ 30926487904947:ring 0: running fiber 0
257+ 30926487907318:ring 0: running fiber 6
258+ 30926487917202:ring 0: log " server: got connection from client"
259+ 30926487929993:ring 0: running fiber 6
260+ 30926487941403:ring 0: running fiber 7
261+ 30926487948000:ring 0: running fiber 7
262+ 30926487971898:ring 0: resolve 7
263+ 30926487974810:ring 0: running fiber 6
264+ 30926487975215:ring 0: running fiber 6
265+ 30926487977869:ring 0: running fiber 6
266+ 30926487984514:ring 0: log " server: read \" Hello\" from socket"
267+ 30926487990785:ring 0: resolve 6
268+ 30926487991752:ring 0: running fiber 3
269+ 30926488022310:ring 0: resolve 3
270+ 30926497839725:ring 0: running fiber 2
271+ +tracer: stopping
237272```
238273
239- The trace can be viewed using [ mirage-trace-viewer] [ ] .
240- This should work even while the program is still running.
241- The file is a ring buffer, so when it gets full, old events will start to be overwritten with new ones.
274+ Note that the output from ` traceln ` appears in the trace as well as on the console.
275+
276+ There are various third-party tools that can consume this data
277+ (but may currently require patches to support the new system):
278+
279+ - [ Meio] [ ] (Monitoring for Eio) provides an interactive console-based UI for exploring running fibers.
280+ - [ Olly] [ ] can save Perfetto traces and report statistics.
281+ - [ mirage-trace-viewer] [ ] renders the trace visually.
282+
283+ For example, this is how mirage-trace-viewer renders the counting example above:
242284
243285<p align =' center ' >
244286 <img src =" ./doc/trace.svg " />
245287</p >
246288
247289This shows the two counting threads as two horizonal lines.
248290The white regions indicate when each thread was running.
249- Note that the output from ` traceln ` appears in the trace as well as on the console.
250-
251- The [ Meio] [ ] (Monitoring for Eio) project provides an interactive console-based UI for exploring running fibers,
252- using the new runtime events support in OCaml 5.1.
253291
254292## Cancellation
255293
@@ -1849,3 +1887,4 @@ Some background about the effects system can be found in:
18491887[ Lambda Capabilities ] : https://roscidus.com/blog/blog/2023/04/26/lambda-capabilities/
18501888[ Eio.Process ] : https://ocaml-multicore.github.io/eio/eio/Eio/Process/index.html
18511889[ Dev meetings ] : https://docs.google.com/document/d/1ZBfbjAkvEkv9ldumpZV5VXrEc_HpPeYjHPW_TiwJe4Q
1890+ [ Olly ] : https://github.com/tarides/runtime_events_tools
0 commit comments