Registers a hook on a pool handle. The hook is called as
fn(event, id) at each task lifecycle event that this process
observes:
Arguments
- pool
a pool handle from
mizu_pool()ormizu_pool_attach(); inside a task, the evaluating worker's own handle frommizu_current_pool().- fn
a
function(event, id), orNULLto remove a registered hook.
Details
"submit"when a task is committed.On worker handles:
"start"before the evaluation of a task, and"done"or"error"when its result is published."drop"when a claimed task is discarded (cancelled before or during execution, or its payload's shared region died with its submitter)."rehome"when a worker helping with the doorbell claims a map runner. The helper moves it onto its own deque, where idle peers can steal it, instead of executing it nested.
id identifies the task as "<submitter slot>:<counter>". This id is
stable across processes, so logs from both sides of a pool can be
correlated.
Registration is per-handle and per-process. A submitter that traces its
own handle sees only "submit". Execution events happen on the
workers. To trace a worker, install the hook from a task on the
worker's own handle:
mizu_submit(p, mizu_pool_trace(mizu_current_pool(), fn)). The
disabled hook costs one pointer check per event site, and the channel
functions have no event sites. An error raised by the hook propagates
as an internal failure at its site. On a worker, it takes the worker
down. This differs from a task's own error, which is published as the
error result of that task.
Examples
p <- mizu_pool()
mizu_pool_trace(p, function(event, id) cat(event, id, "\n"))
t <- mizu_submit(p, 1 + 1)
#> submit 0:1
mizu_collect(t)
#> [1] 2
mizu_pool_trace(p)
mizu_pool_stop(p)