ThreadMetrics

Struct ThreadMetrics 

Source
pub struct ThreadMetrics {
Show 17 fields pub thread_id: ThreadId, pub cpu_time_ns: u64, pub context_switches: u64, pub voluntary_yields: u64, pub involuntary_preemptions: u64, pub peak_stack_usage: usize, pub current_stack_usage: usize, pub page_faults: u64, pub user_time_ns: u64, pub kernel_time_ns: u64, pub created_at: Instant, pub last_active: Instant, pub priority_changes: u32, pub memory_allocations: u64, pub memory_deallocations: u64, pub total_memory_allocated: u64, pub current_memory_usage: u64,
}
Expand description

Per-thread metrics tracking.

Fields§

§thread_id: ThreadId

Thread ID

§cpu_time_ns: u64

Total CPU time consumed (nanoseconds)

§context_switches: u64

Number of context switches

§voluntary_yields: u64

Number of voluntary yields

§involuntary_preemptions: u64

Number of involuntary preemptions

§peak_stack_usage: usize

Peak stack usage (bytes)

§current_stack_usage: usize

Current stack usage (bytes)

§page_faults: u64

Number of page faults

§user_time_ns: u64

Time spent in user mode (nanoseconds)

§kernel_time_ns: u64

Time spent in kernel mode (nanoseconds)

§created_at: Instant

Thread creation time

§last_active: Instant

Last active time

§priority_changes: u32

Priority changes

§memory_allocations: u64

Memory allocations

§memory_deallocations: u64

Memory deallocations

§total_memory_allocated: u64

Total memory allocated (bytes)

§current_memory_usage: u64

Current memory usage (bytes)

Implementations§

Source§

impl ThreadMetrics

Source

pub fn new(thread_id: ThreadId) -> Self

Create new thread metrics.

Source

pub fn add_cpu_time(&mut self, duration: Duration, is_user_mode: bool)

Update CPU time metrics.

Source

pub fn record_context_switch(&mut self, voluntary: bool)

Record a context switch.

Source

pub fn update_stack_usage(&mut self, current_usage: usize)

Update stack usage metrics.

Source

pub fn record_allocation(&mut self, size: u64)

Record memory allocation.

Source

pub fn record_deallocation(&mut self, size: u64)

Record memory deallocation.

Source

pub fn cpu_utilization(&self) -> f64

Calculate CPU utilization percentage.

Source

pub fn preemption_rate(&self) -> f64

Calculate preemption rate.

Trait Implementations§

Source§

impl Clone for ThreadMetrics

Source§

fn clone(&self) -> ThreadMetrics

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ThreadMetrics

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<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, 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> 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 = 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.