Skip to main content

Recorder

Struct Recorder 

Source
pub struct Recorder<W: Write = BufWriter<File>> { /* private fields */ }
Expand description

Records stack samples for one or more Linux processes.

Call finish to drain perf rings, flush sorted events, and report write errors. Dropping a recorder only disables sampling on a best-effort basis; queued samples may be lost and flush errors cannot be reported from Drop.

Implementations§

Source§

impl Recorder

Source

pub fn attach<P: AsRef<Path>>( pid: Pid, output: P, attach_mode: AttachMode, options: RecorderOptions, ) -> Result<Self>

Attach to pid and start writing samples to output.

Use AttachMode::StopWhileAttaching for a process that is already running. Use AttachMode::OnExec with process::SuspendedLaunchedProcess when launching a new process.

§Errors

Returns an error when the options are invalid, perf cannot attach, the process cannot be inspected, or the spool file cannot be created.

Source

pub fn tail(&mut self) -> Result<Tail>

Flush the spool and create an incremental reader that shares exact module images still held by this recorder’s bounded image cache.

A recorder can create one live tail. Continue polling and flushing the recorder, then call crate::Tail::poll to consume newly visible batches. Build the symbolizer through crate::Tail::symbolizer and update it before resolving each batch.

§Errors

Returns an invalid-input error after a tail has already been created. Returns an I/O error when the spool cannot be flushed, cloned, or read.

Source§

impl<W: Write> Recorder<W>

Source

pub fn attach_with_writer( pid: Pid, output: W, attach_mode: AttachMode, options: RecorderOptions, ) -> Result<Self>

Attach to pid and write the spool to a caller-owned writer.

The writer is used through static dispatch. Passing &mut W lets the caller recover the completed bytes after Self::finish consumes the recorder.

§Errors

Returns an error when the options are invalid, perf cannot attach, the process cannot be inspected, or the writer rejects the spool header.

Source

pub fn poll(&mut self, timeout: Duration) -> Result<PollSummary>

Wait for data for at most timeout, then drain every ready event.

§Errors

Returns an error when polling perf, decoding events, unwinding a stack, or writing a spool record fails.

Source

pub fn attach_process( &mut self, pid: Pid, attach_mode: AttachMode, ) -> Result<AttachOutcome>

Add another process to this recording.

§Errors

Returns an error when perf cannot attach, process metadata cannot be read, or the spool cannot record the new mappings.

Source

pub fn refresh_threads(&mut self, pid: Pid) -> Result<RefreshOutcome>

Discover newly-created threads for pid when needed.

§Errors

Returns ErrorKind::InvalidInput when pid is not attached, or an I/O error when thread discovery fails.

Source

pub fn disable(&mut self) -> Result<()>

Disable sampling for all attached processes.

§Errors

Returns the first perf-event disable failure.

Source

pub fn enable(&mut self) -> Result<()>

Enable sampling for all attached processes.

§Errors

Returns the first perf-event enable or process-resume failure. When both fail, the enable failure remains primary and the resume failure is included as cleanup context.

Source

pub fn flush(&mut self) -> Result<()>

Drain all collected events, force loss bookkeeping and recovery, then flush the spool writer. Sampling and lifecycle discovery remain active.

When loss has made lifecycle state uncertain, this call can perform an expensive reconciliation pass over tracked processes and /proc, discover descendants, rebuild module state, and open missing perf events before it flushes the writer.

§Errors

Returns an event-processing or writer error.

Source

pub fn has_pending_events(&self) -> bool

Return whether userspace has queued events or Self::poll observed a readable perf buffer.

Source

pub fn summary(&self) -> RecordingSummary

Return a snapshot of the current counters.

Source

pub fn process_is_active(&mut self, pid: Pid) -> Result<bool>

Return whether pid is still believed to be alive.

§Errors

Returns an I/O error when process state cannot be checked.

Source

pub fn has_active_processes_except(&mut self, pid: Pid) -> Result<bool>

Return whether any active process other than pid remains.

§Errors

Returns an error when process state cannot be inspected. Inspection failures are never treated as an alive or dead result.

Source

pub fn active_process_count(&mut self) -> Result<usize>

Return the number of processes still believed to be alive.

§Errors

Returns an error when any tracked process cannot be inspected.

Source

pub fn finish(self) -> Result<RecordingSummary>

Flush the spool file and return the final counters.

§Errors

Returns the first disable, drain, or flush error. Later failures are retained as cleanup context, and flushing is attempted in every case.

Trait Implementations§

Source§

impl<W: Write> Debug for Recorder<W>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<W: Write> Drop for Recorder<W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<W = BufWriter<File>> !Freeze for Recorder<W>

§

impl<W = BufWriter<File>> !RefUnwindSafe for Recorder<W>

§

impl<W = BufWriter<File>> !Sync for Recorder<W>

§

impl<W = BufWriter<File>> !UnwindSafe for Recorder<W>

§

impl<W> Send for Recorder<W>
where PerfSpoolWriter<W>: Send,

§

impl<W> Unpin for Recorder<W>
where PerfSpoolWriter<W>: Unpin,

§

impl<W> UnsafeUnpin for Recorder<W>
where PerfSpoolWriter<W>: UnsafeUnpin,

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<T> ErasedDestructor for T
where T: 'static,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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, !>

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<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