pub struct AsyncTracker { /* private fields */ }Expand description
Async memory tracker for task-aware memory tracking.
Implementations§
Source§impl AsyncTracker
impl AsyncTracker
pub fn new() -> Self
pub fn set_current_task(task_id: u64)
pub fn clear_current_task()
Sourcepub fn get_current_task() -> Option<u64>
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().
Sourcepub fn enter_task(task_id: u64) -> TaskGuard
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.
Sourcepub fn with_task<F, T>(task_id: u64, f: F) -> Twhere
F: FnOnce() -> T,
pub fn with_task<F, T>(task_id: u64, f: F) -> Twhere
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.
pub fn track_task_start( &self, task_id: u64, name: String, _thread_id: ThreadId, ) -> Result<(), AsyncError>
pub fn track_task_start_with_tokio( &self, task_id: u64, tokio_task_id: u64, name: String, _thread_id: ThreadId, ) -> Result<(), AsyncError>
Sourcepub fn track_task_end(&self, task_id: u64) -> Result<(), AsyncError>
pub fn track_task_end(&self, task_id: u64) -> Result<(), AsyncError>
Track a task end.
Sourcepub async fn track_in_tokio_task<F, T>(
&self,
name: String,
future: F,
) -> (u64, T)where
F: Future<Output = T>,
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 identificationfuture- 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).
Sourcepub fn detect_zombie_tasks(&self) -> Vec<u64>
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.
Sourcepub fn zombie_task_stats(&self) -> (usize, usize)
pub fn zombie_task_stats(&self) -> (usize, usize)
Get statistics about zombie tasks.
Optimized to acquire the lock only once.
pub fn track_allocation_auto( &self, ptr: usize, size: usize, var_name: Option<String>, type_name: Option<String>, )
Sourcepub fn track_allocation(&self, ptr: usize, size: usize, task_id: u64)
pub fn track_allocation(&self, ptr: usize, size: usize, task_id: u64)
Track an allocation associated with a task.
Sourcepub 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>,
)
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.
Sourcepub fn track_deallocation(&self, ptr: usize)
pub fn track_deallocation(&self, ptr: usize)
Track a deallocation associated with a task.
Sourcepub fn get_stats(&self) -> AsyncStats
pub fn get_stats(&self) -> AsyncStats
Get current statistics.
Sourcepub fn snapshot(&self) -> AsyncSnapshot
pub fn snapshot(&self) -> AsyncSnapshot
Take a snapshot of current state.
Sourcepub fn get_task_profile(&self, task_id: u64) -> Option<TaskMemoryProfile>
pub fn get_task_profile(&self, task_id: u64) -> Option<TaskMemoryProfile>
Get task memory profile
Sourcepub fn get_all_profiles(&self) -> Vec<TaskMemoryProfile>
pub fn get_all_profiles(&self) -> Vec<TaskMemoryProfile>
Get all task profiles
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Check if tracker is initialized
Sourcepub fn set_initialized(&self)
pub fn set_initialized(&self)
Mark tracker as initialized
Sourcepub fn analyze_task(
&self,
task_id: u64,
task_type: TaskType,
) -> Option<TaskReport>
pub fn analyze_task( &self, task_id: u64, task_type: TaskType, ) -> Option<TaskReport>
Generate task efficiency report
Sourcepub fn get_resource_rankings(&self) -> Vec<ResourceRanking>
pub fn get_resource_rankings(&self) -> Vec<ResourceRanking>
Get resource rankings for all tasks
Trait Implementations§
Source§impl Default for AsyncTracker
impl Default for AsyncTracker
Auto Trait Implementations§
impl Freeze for AsyncTracker
impl RefUnwindSafe for AsyncTracker
impl Send for AsyncTracker
impl Sync for AsyncTracker
impl Unpin for AsyncTracker
impl UnsafeUnpin for AsyncTracker
impl UnwindSafe for AsyncTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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