Skip to main content

EventTraceBuilder

Struct EventTraceBuilder 

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

Builder for configuring an ETW trace session.

Obtained from EventTrace::builder. Chain configuration methods, then call start to begin tracing and receive an EventTrace handle.

Implementations§

Source§

impl EventTraceBuilder

Source

pub fn system_provider(self, provider: SystemProvider) -> Self

Add a kernel event source to this trace session.

Can be called multiple times to monitor several sources at once. At least one provider must be added before calling start.

§Example
use windows_erg::etw::{EventTrace, SystemProvider};

let trace = EventTrace::builder("SecurityMonitor")
    .system_provider(SystemProvider::Process)
    .system_provider(SystemProvider::Registry)
    .start()?;
Source

pub fn user_provider(self, provider_guid: GUID) -> Self

Add a user-mode ETW provider by GUID.

This enables events from providers registered with EventRegister (for example application or service providers).

User-mode providers cannot be mixed with kernel SystemProviders in a single session.

Source

pub fn buffer_size(self, size_kb: u32) -> Self

Set buffer size in kilobytes (default: 64 KB).

Larger buffers reduce the chance of losing events at the cost of memory.

Source

pub fn min_buffers(self, count: u32) -> Self

Set the minimum number of event buffers pre-allocated by the OS (default: 2).

Source

pub fn max_buffers(self, count: u32) -> Self

Set the maximum number of event buffers the OS may allocate (default: 20).

Source

pub fn flush_interval(self, seconds: u32) -> Self

Set how often the OS flushes filled buffers, in seconds (default: 1).

Source

pub fn channel_capacity(self, capacity: usize) -> Self

Set the internal event channel capacity (default: 10 000).

Bounds memory usage during high-volume tracing. Events beyond this limit are dropped when the consumer falls behind.

Source

pub fn with_decoded_stream(self) -> Self

Emit only decoded events to avoid raw event allocation overhead.

Source

pub fn with_both_streams(self) -> Self

Emit both raw and decoded events.

Source

pub fn with_stack_traces(self) -> Self

Capture stack trace metadata for events when ETW provides it.

When enabled, raw TraceEvent values may include stack_trace parsed from event extended data items.

Source

pub fn with_thread_context(self) -> Self

Include thread context metadata in each event.

When enabled, raw TraceEvent values include thread_context metadata populated from the ETW event header (ProcessId and ThreadId).

Source

pub fn with_detailed_events(self) -> Self

Parse event payloads into named fields using the provider schema (planned feature).

When implemented, the raw data bytes in each TraceEvent will be pre-decoded into structured fields based on the provider’s event schema.

Source

pub fn with_cpu_samples(self) -> Self

Attach basic CPU sampling metadata to each raw event.

When enabled, raw TraceEvent values include cpu_sample with the logical processor number from ETW buffer context.

Source

pub fn with_process_filter<I, P>(self, pids: I) -> Self
where I: IntoIterator<Item = P>, P: Into<ProcessId>,

Restrict event collection to specific process IDs.

When non-empty, only events whose ProcessId matches one of pids are forwarded from the ETW callback to the output channels.

§Example
use windows_erg::etw::{EventTrace, SystemProvider};

let trace = EventTrace::builder("TargetedMonitor")
    .system_provider(SystemProvider::FileIo)
    .with_process_filter(vec![1234, 5678])
    .start()?;
Source

pub fn start(self) -> Result<EventTrace>

Start the trace session and return an EventTrace handle.

§Errors
ConditionError
Empty session nameEtwError::SessionStartFailed
Name longer than 1024 charsEtwError::SessionStartFailed
No providers specifiedEtwError::SessionStartFailed
Mixed kernel + user providersEtwError::SessionStartFailed
min_buffers > max_buffersEtwError::SessionStartFailed
NT Kernel Logger already runningSessionStartFailed with ERROR_ALREADY_EXISTS
Windows API failureEtwError::SessionStartFailed with OS error code

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.