Skip to main content

Dial9Handle

Struct Dial9Handle 

Source
pub struct Dial9Handle { /* private fields */ }
Expand description

Cheap, cloneable handle for recording events and controlling telemetry.

A handle may be in one of two modes:

  • Enabled — backed by a live recorder; methods record events and control recording.
  • Disabled — an inert sentinel returned by Dial9Handle::disabled, and by Dial9Handle::current when neither the calling thread nor the process has a handle installed. All methods are no-ops.

Use is_enabled to distinguish the two modes.

Implementations§

Source§

impl Dial9Handle

Source

pub fn disabled() -> Self

Return an inert handle that is not connected to any recorder. All methods are no-ops.

Source

pub fn is_enabled(&self) -> bool

Whether recording through this handle currently does anything: the handle is connected to a live recorder AND recording is enabled (not paused via disable).

Returns false for handles obtained via Dial9Handle::disabled, for any handle Dial9Handle::current could not resolve, and while a connected recorder is paused.

Check this before doing per-event work that would be wasted while recording is off, such as work leading up to with_encoder. The check can race a concurrent enable/disable, which is benign since the event either lands or is skipped anyway.

To ask only whether the handle is connected at all, regardless of pause state, use is_connected.

Source

pub fn dump_trigger(&self) -> Option<DumpTrigger>

Available on crate feature pipeline only.

On-demand dump trigger for this runtime’s recorder.

Returns None on a disabled handle (see disabled) and when the runtime was built without a dump trigger (with_dump_trigger). The returned DumpTrigger is cheap to clone and every clone shares the configured debounce gate.

Source

pub fn current() -> Self

Return the Dial9Handle to record through, resolved in order:

  1. The handle installed on this thread with set_tl_handle, which runtime integrations do for the threads they own.
  2. The process-global handle, if Recorder::install_global_handle has been called.
  3. An inert disabled handle, where recording is a no-op.

Use is_enabled to branch on whether telemetry is live here.

Source

pub fn try_current_thread() -> Option<Self>

Return the Dial9Handle installed on this thread with set_tl_handle, or None if there is none.

Unlike current, never falls back to the process-global handle. To record an event, use current.

Source

pub fn enable(&self)

Enable telemetry recording. No-op on a disabled handle.

Source

pub fn disable(&self)

Disable telemetry recording. No-op on a disabled handle.

Source

pub fn track_current_thread(&self) -> Result<ThreadTrackingGuard>

Profile the calling thread.

Per-thread sources, such as the scheduler-event profiler, only sample threads that opt in. Tokio workers opt in on their own, call this from any other thread you want profiled. Profiling lasts until the returned guard drops.

Returns an error if a source could not start on this thread. No-op on a disabled handle.

use dial9_core::buffer::MemoryBuffer;
use dial9_core::recorder::recorder;

let rec = recorder(MemoryBuffer::new(1 << 20)?).build();
let handle = rec.handle().clone();

std::thread::spawn(move || -> std::io::Result<()> {
    let _tracking = handle.track_current_thread()?;
    // work here is sampled by the recorder's per-thread sources
    Ok(())
});
Source

pub fn is_connected(&self) -> bool

Whether this handle is wired to a recorder at all, regardless of whether recording is currently paused.

is_enabled answers the narrower question of whether a record right now would land.

Source

pub fn is_stopped(&self) -> bool

Whether the recorder behind this handle has shut down.

Terminal: a stopped recorder never records again. Returns false for a handle that is merely paused (see disable) and for a disabled handle, neither of which is stopped.

Source

pub fn with_source<T: Source, R>( &self, f: impl FnOnce(&mut T) -> R, ) -> Option<R>

Run f against this recorder’s source of type T.

None when the handle is disabled, no T is registered, or the source lock is poisoned.

Source

pub fn with_source_or_insert<T: Source, R>( &self, make: impl FnOnce() -> T, f: impl FnOnce(&mut T) -> R, ) -> Option<R>

Run f against this recorder’s source of type T, registering the one make builds if there is not one yet.

None when the handle is disabled, the recorder has shut down, or the source lock is poisoned.

Source

pub fn record_event(&self, event: impl Encodable)

Record a custom event into the trace.

Any type implementing dial9_trace_format::TraceEvent (typically via #[derive(TraceEvent)]) works directly. No-op on a disabled handle or when recording is paused.

Source

pub fn record_event_with<E: Encodable>(&self, make: impl FnOnce() -> E)

Record an event that is only built when recording is on.

Reach for this over record_event when building the event costs something you would rather not pay while recording is paused, such as a clock read or a lookup. make runs only if the event will be recorded.

Trait Implementations§

Source§

impl Clone for Dial9Handle

Source§

fn clone(&self) -> Dial9Handle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Dial9Handle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<V, F> ValueFormatter<&V> for F
where F: ValueFormatter<V> + ?Sized, V: ?Sized,

Source§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
Source§

fn format_value(writer: impl ValueWriter, value: &&V)

Write value to writer
Source§

impl<V, F> ValueFormatter<Arc<V>> for F
where F: ValueFormatter<V> + ?Sized, V: ?Sized,

Source§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
Source§

fn format_value(writer: impl ValueWriter, value: &Arc<V>)

Write value to writer
Source§

impl<V, F> ValueFormatter<Box<V>> for F
where F: ValueFormatter<V> + ?Sized, V: ?Sized,

Source§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
Source§

fn format_value(writer: impl ValueWriter, value: &Box<V>)

Write value to writer
Source§

impl<V, F> ValueFormatter<Cow<'_, V>> for F
where V: ToOwned + ?Sized, F: ValueFormatter<V> + ?Sized,

Source§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
Source§

fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)

Write value to writer
Source§

impl<V, F> ValueFormatter<Option<V>> for F
where F: ValueFormatter<V> + ?Sized,

Source§

const SHAPE: FieldShape<'static>

Available on non-metrique_require_explicit_impls only.
The shape of values produced by this formatter. Read more
Source§

fn format_value(writer: impl ValueWriter, value: &Option<V>)

Write value to writer
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more