gossamer/performance_observer
Asynchronously receive performance entries as the runtime records
them. Subscribe to many kinds at once via observe, or
to a single kind with buffer replay via
observe_buffered. The handler receives a
Batch of new entries plus the
PerformanceObserver itself for
in-handler disconnect /
take_records calls.
Types
The entries delivered to a handler on a single observer invocation, plus the count of entries the runtime dropped from its global buffer before this observer started observing.
pub type Batch {
Batch(
entries: List(performance_entry.PerformanceEntry),
dropped: Int,
)
}
Constructors
-
Batch( entries: List(performance_entry.PerformanceEntry), dropped: Int, )Arguments
- entries
-
The entries delivered to the handler on this invocation.
- dropped
-
The count of entries the runtime dropped from its global buffer due to overflow. Reported only on the first invocation of an
observe_bufferedobserver; always zero on other observers and on subsequent invocations.
A subscription that delivers performance entries to a handler.
See PerformanceObserver on MDN.
pub type PerformanceObserver
Values
pub fn disconnect(observer: PerformanceObserver) -> Nil
Stops the observer from receiving further entries. Any pending
entries are discarded — call take_records first
to drain them.
pub fn observe(
entry_kinds: List(performance_entry.Kind),
handler: fn(Batch, PerformanceObserver) -> a,
) -> PerformanceObserver
Subscribes to performance entries of the given kinds. The handler
receives a Batch of new entries plus the
PerformanceObserver so it can call
disconnect or take_records
from inside (e.g., auto-disconnect after the first batch).
Equivalent to constructing a JavaScript PerformanceObserver and
calling observer.observe({ entryTypes: [...] }).
Kind support differs across runtimes — see
supported_entry_types.
pub fn observe_buffered(
entry_kind: performance_entry.Kind,
handler: fn(Batch, PerformanceObserver) -> a,
) -> PerformanceObserver
Subscribes to a single entry kind and replays any entries the
runtime has already buffered for that kind. Useful when the
observer attaches after some entries were recorded. The handler
also receives the PerformanceObserver.
Equivalent to constructing a JavaScript PerformanceObserver and
calling observer.observe({ type: ..., buffered: true }).
pub fn supported_entry_types() -> List(performance_entry.Kind)
Returns the entry kinds this runtime’s PerformanceObserver
accepts. Every runtime accepts
MarkKind and
MeasureKind; Node accepts a
larger set including resource-loading and several runtime-
internal kinds (DNS, GC, etc.) that arrive wrapped as
OtherKind(name).
pub fn take_records(
observer: PerformanceObserver,
) -> List(performance_entry.PerformanceEntry)
Returns and clears any entries that have been recorded but not yet delivered to the handler.