ocaml-opentelemetry/eio/Eio_runtime_events/index.html
2026-04-06 19:57:49 +00:00

5 lines
17 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Eio_runtime_events (eio.Eio_runtime_events)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.1.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../index.html">Index</a> &#x00BB; <a href="../index.html">eio</a> &#x00BB; Eio_runtime_events</nav><header class="odoc-preamble"><h1>Module <code><span>Eio_runtime_events</span></code></h1><p>This library is used to write event traces using OCaml's runtime events infrastructure.</p></header><div class="odoc-tocs"><nav class="odoc-toc odoc-local-toc"><ul><li><a href="#writing-events">Writing events</a></li><li><a href="#consuming-events">Consuming events</a></li></ul></nav></div><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-id"><a href="#type-id" class="anchor"></a><code><span><span class="keyword">type</span> id</span><span> = int</span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-obj_ty"><a href="#type-obj_ty" class="anchor"></a><code><span><span class="keyword">type</span> obj_ty</span><span> = </span></code><ol><li id="type-obj_ty.Promise" class="def variant constructor anchored"><a href="#type-obj_ty.Promise" class="anchor"></a><code><span>| </span><span><span class="constructor">Promise</span></span></code></li><li id="type-obj_ty.Semaphore" class="def variant constructor anchored"><a href="#type-obj_ty.Semaphore" class="anchor"></a><code><span>| </span><span><span class="constructor">Semaphore</span></span></code></li><li id="type-obj_ty.Stream" class="def variant constructor anchored"><a href="#type-obj_ty.Stream" class="anchor"></a><code><span>| </span><span><span class="constructor">Stream</span></span></code></li><li id="type-obj_ty.Mutex" class="def variant constructor anchored"><a href="#type-obj_ty.Mutex" class="anchor"></a><code><span>| </span><span><span class="constructor">Mutex</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>Types of recorded objects.</p><span class="comment-delim">*)</span></div></li></ol></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-obj_ty_to_string"><a href="#val-obj_ty_to_string" class="anchor"></a><code><span><span class="keyword">val</span> obj_ty_to_string : <span><a href="#type-obj_ty">obj_ty</a> <span class="arrow">&#45;&gt;</span></span> string</span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-cc_ty"><a href="#type-cc_ty" class="anchor"></a><code><span><span class="keyword">type</span> cc_ty</span><span> = </span></code><ol><li id="type-cc_ty.Switch" class="def variant constructor anchored"><a href="#type-cc_ty.Switch" class="anchor"></a><code><span>| </span><span><span class="constructor">Switch</span></span></code></li><li id="type-cc_ty.Protect" class="def variant constructor anchored"><a href="#type-cc_ty.Protect" class="anchor"></a><code><span>| </span><span><span class="constructor">Protect</span></span></code></li><li id="type-cc_ty.Sub" class="def variant constructor anchored"><a href="#type-cc_ty.Sub" class="anchor"></a><code><span>| </span><span><span class="constructor">Sub</span></span></code></li><li id="type-cc_ty.Root" class="def variant constructor anchored"><a href="#type-cc_ty.Root" class="anchor"></a><code><span>| </span><span><span class="constructor">Root</span></span></code></li><li id="type-cc_ty.Any" class="def variant constructor anchored"><a href="#type-cc_ty.Any" class="anchor"></a><code><span>| </span><span><span class="constructor">Any</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>Types of cancellation contexts.</p><span class="comment-delim">*)</span></div></li></ol></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-cc_ty_to_string"><a href="#val-cc_ty_to_string" class="anchor"></a><code><span><span class="keyword">val</span> cc_ty_to_string : <span><a href="#type-cc_ty">cc_ty</a> <span class="arrow">&#45;&gt;</span></span> string</span></code></div></div><h3 id="writing-events"><a href="#writing-events" class="anchor"></a>Writing events</h3><div class="odoc-spec"><div class="spec value anchored" id="val-create_fiber"><a href="#val-create_fiber" class="anchor"></a><code><span><span class="keyword">val</span> create_fiber : <span><span>(<a href="#type-id">id</a> * <a href="#type-id">id</a>)</span> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-create_cc"><a href="#val-create_cc" class="anchor"></a><code><span><span class="keyword">val</span> create_cc : <span><span>(<a href="#type-id">id</a> * <a href="#type-cc_ty">cc_ty</a>)</span> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-create_obj"><a href="#val-create_obj" class="anchor"></a><code><span><span class="keyword">val</span> create_obj : <span><span>(<a href="#type-id">id</a> * <a href="#type-obj_ty">obj_ty</a>)</span> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-log"><a href="#val-log" class="anchor"></a><code><span><span class="keyword">val</span> log : <span>string <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-enter_span"><a href="#val-enter_span" class="anchor"></a><code><span><span class="keyword">val</span> enter_span : <span>string <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-exit_span"><a href="#val-exit_span" class="anchor"></a><code><span><span class="keyword">val</span> exit_span : <span>unit <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-name"><a href="#val-name" class="anchor"></a><code><span><span class="keyword">val</span> name : <span><span>(<a href="#type-id">id</a> * string)</span> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-suspend_fiber"><a href="#val-suspend_fiber" class="anchor"></a><code><span><span class="keyword">val</span> suspend_fiber : <span>string <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-exit_cc"><a href="#val-exit_cc" class="anchor"></a><code><span><span class="keyword">val</span> exit_cc : <span>unit <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-exit_fiber"><a href="#val-exit_fiber" class="anchor"></a><code><span><span class="keyword">val</span> exit_fiber : <span><a href="#type-id">id</a> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-error"><a href="#val-error" class="anchor"></a><code><span><span class="keyword">val</span> error : <span><span>(<a href="#type-id">id</a> * exn)</span> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fiber"><a href="#val-fiber" class="anchor"></a><code><span><span class="keyword">val</span> fiber : <span><a href="#type-id">id</a> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get"><a href="#val-get" class="anchor"></a><code><span><span class="keyword">val</span> get : <span><a href="#type-id">id</a> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_get"><a href="#val-try_get" class="anchor"></a><code><span><span class="keyword">val</span> try_get : <span><a href="#type-id">id</a> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-put"><a href="#val-put" class="anchor"></a><code><span><span class="keyword">val</span> put : <span><a href="#type-id">id</a> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-suspend_domain"><a href="#val-suspend_domain" class="anchor"></a><code><span><span class="keyword">val</span> suspend_domain : <span><a href="../../ocaml/Runtime_events/Type/index.html#type-span">Runtime_events.Type.span</a> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-domain_spawn"><a href="#val-domain_spawn" class="anchor"></a><code><span><span class="keyword">val</span> domain_spawn : <span><a href="#type-id">id</a> <a href="../../ocaml/Runtime_events/User/index.html#type-t">Runtime_events.User.t</a></span></span></code></div></div><h3 id="consuming-events"><a href="#consuming-events" class="anchor"></a>Consuming events</h3><div class="odoc-spec"><div class="spec type anchored" id="type-event"><a href="#type-event" class="anchor"></a><code><span><span class="keyword">type</span> event</span><span> = </span><span>[ </span></code><ol><li id="type-event.Create" class="def variant constructor anchored"><a href="#type-event.Create" class="anchor"></a><code><span>| </span><span>`Create <span class="keyword">of</span> <a href="#type-id">id</a> * <span>[ <span>`Fiber_in of <a href="#type-id">id</a></span> <span><span>| `Cc</span> of <a href="#type-cc_ty">cc_ty</a></span> <span><span>| `Obj</span> of <a href="#type-obj_ty">obj_ty</a></span> ]</span></span></code></li><li id="type-event.Fiber" class="def variant constructor anchored"><a href="#type-event.Fiber" class="anchor"></a><code><span>| </span><span>`Fiber <span class="keyword">of</span> <a href="#type-id">id</a></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The given fiber is now running.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Name" class="def variant constructor anchored"><a href="#type-event.Name" class="anchor"></a><code><span>| </span><span>`Name <span class="keyword">of</span> <a href="#type-id">id</a> * string</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>Names a promise, stream, etc.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Log" class="def variant constructor anchored"><a href="#type-event.Log" class="anchor"></a><code><span>| </span><span>`Log <span class="keyword">of</span> string</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The running fiber logs a message.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Enter_span" class="def variant constructor anchored"><a href="#type-event.Enter_span" class="anchor"></a><code><span>| </span><span>`Enter_span <span class="keyword">of</span> string</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The running fiber enters a traced section.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Exit_span" class="def variant constructor anchored"><a href="#type-event.Exit_span" class="anchor"></a><code><span>| </span><span>`Exit_span</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The running fiber leaves the current traced section.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Get" class="def variant constructor anchored"><a href="#type-event.Get" class="anchor"></a><code><span>| </span><span>`Get <span class="keyword">of</span> <a href="#type-id">id</a></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The running fiber gets a value from a promise, stream, acquires a lock, etc.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Try_get" class="def variant constructor anchored"><a href="#type-event.Try_get" class="anchor"></a><code><span>| </span><span>`Try_get <span class="keyword">of</span> <a href="#type-id">id</a></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The running fiber wants to get, but must wait.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Put" class="def variant constructor anchored"><a href="#type-event.Put" class="anchor"></a><code><span>| </span><span>`Put <span class="keyword">of</span> <a href="#type-id">id</a></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The running fiber resolves a promise, adds to a stream, releases a lock etc.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Error" class="def variant constructor anchored"><a href="#type-event.Error" class="anchor"></a><code><span>| </span><span>`Error <span class="keyword">of</span> <a href="#type-id">id</a> * string</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>A CC fails with the given error.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Exit_cc" class="def variant constructor anchored"><a href="#type-event.Exit_cc" class="anchor"></a><code><span>| </span><span>`Exit_cc</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The current CC ends.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Exit_fiber" class="def variant constructor anchored"><a href="#type-event.Exit_fiber" class="anchor"></a><code><span>| </span><span>`Exit_fiber <span class="keyword">of</span> <a href="#type-id">id</a></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The running fiber ends.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Suspend_domain" class="def variant constructor anchored"><a href="#type-event.Suspend_domain" class="anchor"></a><code><span>| </span><span>`Suspend_domain <span class="keyword">of</span> <a href="../../ocaml/Runtime_events/Type/index.html#type-span">Runtime_events.Type.span</a></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The domain asks the OS to wait for events.</p><span class="comment-delim">*)</span></div></li><li id="type-event.Suspend_fiber" class="def variant constructor anchored"><a href="#type-event.Suspend_fiber" class="anchor"></a><code><span>| </span><span>`Suspend_fiber <span class="keyword">of</span> string</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The running fiber is suspended (until resumed by <code>`Fiber</code>).</p><span class="comment-delim">*)</span></div></li><li id="type-event.Domain_spawn" class="def variant constructor anchored"><a href="#type-event.Domain_spawn" class="anchor"></a><code><span>| </span><span>`Domain_spawn <span class="keyword">of</span> <a href="#type-id">id</a></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The current domain was spawned by fiber <code>id</code>.</p><span class="comment-delim">*)</span></div></li></ol><code><span> ]</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-pp_event"><a href="#val-pp_event" class="anchor"></a><code><span><span class="keyword">val</span> pp_event : <span><a href="../../ocaml/Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-event">event</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>pp_event</code> formats an event as a human-readable string</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_callbacks"><a href="#val-add_callbacks" class="anchor"></a><code><span><span class="keyword">val</span> add_callbacks :
<span><span>(<span>int <span class="arrow">&#45;&gt;</span></span> <span><a href="../../ocaml/Runtime_events/Timestamp/index.html#type-t">Runtime_events.Timestamp.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-event">event</a> <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../../ocaml/Runtime_events/Callbacks/index.html#type-t">Runtime_events.Callbacks.t</a> <span class="arrow">&#45;&gt;</span></span>
<a href="../../ocaml/Runtime_events/Callbacks/index.html#type-t">Runtime_events.Callbacks.t</a></span></code></div><div class="spec-doc"><p><code>add_callbacks fn x</code> adds event handler <code>fn</code> to <code>x</code>.</p><p>When an Eio event is processed, it calls <code>fn ring_id ts event</code>.</p></div></div></div></body></html>