TracepointState

Struct TracepointState 

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

Low-level API: Represents a tracepoint registration.

Implementations§

Source§

impl TracepointState

Source

pub const fn new(initial_enable_status: u32) -> Self

Creates a new unregistered tracepoint.

initial_enable_status is normally 0, since an unregistered tracepoint will normally be considered disabled.

Source

pub fn enabled(&self) -> bool

Returns true if this tracepoint is enabled, i.e. enable_status != 0.

Source

pub fn unregister(&self) -> i32

Unregisters this tracepoint.

Returns 0 for success, error code (e.g. EBUSY, EALREADY) for error. Error code is usually ignored in retail code, but may be helpful during development to understand behavior or track down issues.

Source

pub unsafe fn register(self: Pin<&Self>, _name_args: &CStr) -> i32

Registers this tracepoint.

Requires: this TracepointState is not currently registered.

Returns 0 for success, error code (e.g. EACCES, ENOENT) for error. The error code is usually ignored in retail scenarios but may be helpful during development to understand behavior or track down issues.

_name_args is the tracepoint definition in the format Name[ FieldDef1[; FieldDef2...]]. For example:

  • MyTracepoint1
  • MyTracepoint2 u32 Field1
  • MyTracepoint3 u32 Field1; char Field2[20]
§Safety

The tracepoint must be unregistered before it is deallocated. TracepointState will unregister itself when dropped, so this is only an issue if the tracepoint is not dropped before it is deallocated. This might happen for a static variable in a shared library that gets unloaded.

Source

pub unsafe fn register_with_flags( self: Pin<&Self>, _name_args: &CStr, _flags: u16, ) -> i32

Advanced: Registers this tracepoint using the specified user_reg flags.

Requires: this TracepointState is not currently registered.

Returns 0 for success, error code (e.g. EACCES, ENOENT) for error. The error code is usually ignored in retail scenarios but may be helpful during development to understand behavior or track down issues.

_name_args is the tracepoint definition in the format Name[ FieldDef1[; FieldDef2...]]. For example:

  • MyTracepoint1
  • MyTracepoint2 u32 Field1
  • MyTracepoint3 u32 Field1; char Field2[20]

_flags is normally 0, but may also be set to a user_reg flag such as USER_EVENT_REG_PERSIST.

§Safety

The tracepoint must be unregistered before it is deallocated. TracepointState will unregister itself when dropped, so this is only an issue if the tracepoint is not dropped before it is deallocated. This might happen for a static variable in a shared library that gets unloaded.

Source

pub fn write(&self, data: &mut [EventDataDescriptor<'_>]) -> i32

Generates an event.

Requires: data[0].is_empty() since it will be used for the event headers.

Returns 0 for success, error code (e.g. EBADF) for error. The error code is usually ignored in retail scenarios but may be helpful during development to understand behavior or track down issues.

If disabled or unregistered, this method does nothing and returnes EBADF. Otherwise, sets data[0] = write_index then sends data[..] to the user_events_data file handle.

The event’s payload is the concatenation of the remaining data blocks, if any (i.e. data[1..]).

The payload’s layout should match the args specified in the call to register.

Source

pub fn write_with_headers( &self, data: &mut [EventDataDescriptor<'_>], headers: &mut [u8], ) -> i32

Generates an event with headers.

Requires: data[0].is_empty() since it will be used for the event headers; headers.len() >= 4 since it will be used for write_index.

Returns 0 for success, error code (e.g. EBADF) for error. The error code is usually ignored in retail scenarios but may be helpful during development to understand behavior or track down issues.

If disabled or unregistered, this method does nothing and returnes EBADF. Otherwise, sets data[0] = headers and headers[0..4] = write_index, then sends data[..] to the user_events_data file.

The event’s payload is the concatenation of the remaining data blocks, if any (i.e. data[1..]).

The payload’s layout should match the args specified in the call to register.

Trait Implementations§

Source§

impl Drop for TracepointState

Source§

fn drop(&mut self)

Executes the destructor for this type. 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<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.