pub struct ResourceAccountant { /* private fields */ }Expand description
Low-overhead single-owner framework resource ownership accountant.
Implementations§
Source§impl ResourceAccountant
Single-owner registration, fence-deferred release, owner destruction, and leak attribution for ResourceAccountant.
impl ResourceAccountant
Single-owner registration, fence-deferred release, owner destruction, and leak attribution for ResourceAccountant.
Sourcepub fn register_resource(
&mut self,
owner: ResourceOwnerId,
kind: TrackedResourceKind,
handle_id: u64,
byte_size: usize,
retention: ResourceRetentionClass,
)
pub fn register_resource( &mut self, owner: ResourceOwnerId, kind: TrackedResourceKind, handle_id: u64, byte_size: usize, retention: ResourceRetentionClass, )
Registers or updates a tracked resource under a single authoritative owner, deduplicating by (kind, handle_id).
§Arguments
&Self- Mutable resource accountant.ResourceOwnerId- Single authoritative resource owner.TrackedResourceKind- Resource category.u64- Unique resource handle identifier withinkind.usize- Estimated byte footprint.ResourceRetentionClass- Initial retention classification.
Sourcepub fn update_retention(
&mut self,
kind: TrackedResourceKind,
handle_id: u64,
retention: ResourceRetentionClass,
retire_fence_id: u64,
) -> bool
pub fn update_retention( &mut self, kind: TrackedResourceKind, handle_id: u64, retention: ResourceRetentionClass, retire_fence_id: u64, ) -> bool
Updates the retention classification and optional GPU retirement fence of an already-tracked resource.
§Arguments
&Self- Mutable resource accountant.TrackedResourceKind- Resource category.u64- Resource handle identifier.ResourceRetentionClass- Replacement retention class.u64- GPU fence required before release (0when immediate).
§Returns
bool-trueif the resource was found and updated.
Sourcepub fn release_resource(
&mut self,
kind: TrackedResourceKind,
handle_id: u64,
) -> bool
pub fn release_resource( &mut self, kind: TrackedResourceKind, handle_id: u64, ) -> bool
Sourcepub fn mark_owner_destroyed(
&mut self,
owner: ResourceOwnerId,
now_ms: u64,
retire_fence_id: u64,
) -> usize
pub fn mark_owner_destroyed( &mut self, owner: ResourceOwnerId, now_ms: u64, retire_fence_id: u64, ) -> usize
Releases all non-GPU resources belonging to owner and transitions GPU resources awaiting retire_fence_id to PendingFenceRelease.
§Arguments
&Self- Mutable resource accountant.ResourceOwnerId- Destroyed owner identifier.u64- Monotonic destruction timestamp in milliseconds.u64- GPU retirement fence identifier (0if no GPU work references this owner).
§Returns
usize- Number of resources still remaining live underownerafter marking destruction.
Sourcepub fn complete_gpu_fence(&mut self, fence_id: u64) -> usize
pub fn complete_gpu_fence(&mut self, fence_id: u64) -> usize
Sourcepub fn set_page_counts(
&mut self,
active: usize,
frozen: usize,
evicted: usize,
destroyed: u64,
)
pub fn set_page_counts( &mut self, active: usize, frozen: usize, evicted: usize, destroyed: u64, )
Updates the high-level page lifecycle phase counters reported in snapshots.
§Arguments
&Self- Mutable resource accountant.usize- Active page count.usize- Frozen page count.usize- Evicted cold page snapshot count.u64- Cumulative destroyed page count.
Sourcepub fn snapshot(
&self,
now_ms: u64,
grace_period_ms: u64,
) -> ResourceAccountingSnapshot
pub fn snapshot( &self, now_ms: u64, grace_period_ms: u64, ) -> ResourceAccountingSnapshot
Captures a structured ResourceAccountingSnapshot cleanly separating expected_retained from destroyed_owner.live_objects.
§Arguments
&Self- Resource accountant reference.u64- Current monotonic timestamp in milliseconds.u64- Grace period in milliseconds after owner destruction before classifying remaining live objects as leaks.
§Returns
ResourceAccountingSnapshot- Complete ownership and leak-attribution telemetry snapshot.
Sourcepub fn allocate_handle_id(&mut self) -> u64
pub fn allocate_handle_id(&mut self) -> u64
Allocates the next non-zero monotonic resource handle identifier for runtime subsystems.
§Returns
u64- Unique non-zero resource handle identifier.
Sourcepub fn register_auto_handle(
&mut self,
owner: ResourceOwnerId,
kind: TrackedResourceKind,
byte_size: usize,
retention: ResourceRetentionClass,
) -> u64
pub fn register_auto_handle( &mut self, owner: ResourceOwnerId, kind: TrackedResourceKind, byte_size: usize, retention: ResourceRetentionClass, ) -> u64
Allocates a unique handle and registers a tracked resource under owner in one call.
§Arguments
ResourceOwnerId- Authoritative resource owner.TrackedResourceKind- Resource category.usize- Estimated memory or VRAM byte footprint.ResourceRetentionClass- Initial retention classification.
§Returns
u64- Allocated unique resource handle identifier.
Sourcepub fn release_owner_resources(
&mut self,
owner: ResourceOwnerId,
kind_filter: Option<TrackedResourceKind>,
) -> usize
pub fn release_owner_resources( &mut self, owner: ResourceOwnerId, kind_filter: Option<TrackedResourceKind>, ) -> usize
Releases all live resources attributed to owner, optionally restricted to a single resource kind.
§Arguments
ResourceOwnerId- Owner whose resources should be released.Option<TrackedResourceKind>- Optional category filter (Nonereleases every category).
§Returns
usize- Number of resources removed from the live registry.
Sourcepub fn live_count_for_owner(&self, owner: ResourceOwnerId) -> usize
pub fn live_count_for_owner(&self, owner: ResourceOwnerId) -> usize
Sourcepub fn live_bytes_for_owner(&self, owner: ResourceOwnerId) -> usize
pub fn live_bytes_for_owner(&self, owner: ResourceOwnerId) -> usize
Sourcepub fn prune_clean_destroyed_owners(&mut self) -> usize
pub fn prune_clean_destroyed_owners(&mut self) -> usize
Removes destroyed owner records that have zero remaining live resources to prevent unbounded growth.
§Returns
usize- Number of retired destroyed-owner entries pruned.