Skip to main content

AsyncTracker

Struct AsyncTracker 

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

Async memory tracker for task-aware memory tracking.

Implementations§

Source§

impl AsyncTracker

Source

pub fn new() -> Self

Source

pub fn set_current_task(task_id: u64)

Source

pub fn clear_current_task()

Source

pub fn get_current_task() -> Option<u64>

Get the current task ID from the thread-local storage.

Note: This only returns the manually set task ID. For automatic tokio task detection, use track_in_tokio_task().

Source

pub fn enter_task(task_id: u64) -> TaskGuard

Enter a task context with automatic cleanup. Returns a TaskGuard that will clear the task ID when dropped.

Source

pub fn with_task<F, T>(task_id: u64, f: F) -> T
where F: FnOnce() -> T,

Execute a closure within a task context with automatic cleanup. The task ID is automatically cleared after the closure completes, even if the closure panics.

Source

pub fn track_task_start( &self, task_id: u64, name: String, _thread_id: ThreadId, ) -> Result<(), AsyncError>

Source

pub fn track_task_start_with_tokio( &self, task_id: u64, tokio_task_id: u64, name: String, _thread_id: ThreadId, ) -> Result<(), AsyncError>

Source

pub fn track_task_end(&self, task_id: u64) -> Result<(), AsyncError>

Track a task end.

Source

pub async fn track_in_tokio_task<F, T>( &self, name: String, future: F, ) -> (u64, T)
where F: Future<Output = T>,

Execute an async block within a tokio task context.

This method automatically detects the tokio task ID and sets up tracking. When the future completes, the task is automatically marked as ended.

§Arguments
  • name - Task name for identification
  • future - The async block to execute
§Returns

A tuple of (unique_task_id, output). The unique_task_id is our internal ID (not the tokio task ID).

Source

pub fn detect_zombie_tasks(&self) -> Vec<u64>

Detect zombie tasks.

A zombie task is a task that was started but never completed. These tasks may indicate memory leaks or improper task cleanup.

§Returns

A vector of task IDs for zombie tasks.

Source

pub fn zombie_task_stats(&self) -> (usize, usize)

Get statistics about zombie tasks.

Optimized to acquire the lock only once.

Source

pub fn track_allocation_auto( &self, ptr: usize, size: usize, var_name: Option<String>, type_name: Option<String>, )

Source

pub fn track_allocation(&self, ptr: usize, size: usize, task_id: u64)

Track an allocation associated with a task.

Source

pub fn track_allocation_with_location( &self, ptr: usize, size: usize, task_id: u64, var_name: Option<String>, type_name: Option<String>, source_location: Option<SourceLocation>, )

Track an allocation with source location.

Source

pub fn track_deallocation(&self, ptr: usize)

Track a deallocation associated with a task.

Source

pub fn get_stats(&self) -> AsyncStats

Get current statistics.

Source

pub fn snapshot(&self) -> AsyncSnapshot

Take a snapshot of current state.

Source

pub fn get_task_profile(&self, task_id: u64) -> Option<TaskMemoryProfile>

Get task memory profile

Source

pub fn get_all_profiles(&self) -> Vec<TaskMemoryProfile>

Get all task profiles

Source

pub fn is_initialized(&self) -> bool

Check if tracker is initialized

Source

pub fn set_initialized(&self)

Mark tracker as initialized

Source

pub fn analyze_task( &self, task_id: u64, task_type: TaskType, ) -> Option<TaskReport>

Generate task efficiency report

Source

pub fn get_resource_rankings(&self) -> Vec<ResourceRanking>

Get resource rankings for all tasks

Trait Implementations§

Source§

impl Default for AsyncTracker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for AsyncTracker

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
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