ResourceContext

Struct ResourceContext 

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

Thread-local resource context tracking active leases and operation counts.

Used by the #[grafos::instrument] proc macro to capture resource metadata on function entry/exit, and by grafos-std integration hooks to push/pop lease tracking automatically.

§Examples

use grafos_observe::context::{ResourceContext, LeaseInfo};
use grafos_observe::ResourceType;

ResourceContext::with_mut(|ctx| {
    ctx.push_lease(LeaseInfo {
        resource_type: ResourceType::Mem,
        lease_id: 1,
        node_addr: "10.10.0.11".into(),
        bytes_held: 4096,
    });
});

ResourceContext::with(|ctx| {
    assert_eq!(ctx.lease_count(), 1);
    assert_eq!(ctx.total_bytes_held(), 4096);
    assert_eq!(ctx.nodes_involved(), 1);
});

ResourceContext::with_mut(|ctx| {
    ctx.pop_lease(1);
});

ResourceContext::with(|ctx| {
    assert_eq!(ctx.lease_count(), 0);
});

Implementations§

Source§

impl ResourceContext

Source

pub fn with<F, R>(f: F) -> R
where F: FnOnce(&ResourceContext) -> R,

Access the current thread-local resource context immutably.

Source

pub fn with_mut<F, R>(f: F) -> R
where F: FnOnce(&mut ResourceContext) -> R,

Access the current thread-local resource context mutably.

Source

pub fn current_snapshot() -> ContextSnapshot

Take a snapshot of the current thread-local resource context.

Source§

impl ResourceContext

Source

pub fn push_lease(&mut self, info: LeaseInfo)

Push a new lease into the context (called on acquire).

Source

pub fn pop_lease(&mut self, lease_id: u64)

Remove a lease from the context by lease_id (called on drop/free).

Source

pub fn lease_count(&self) -> usize

Number of active leases in the current context.

Source

pub fn total_bytes_held(&self) -> u64

Total bytes held across all active leases.

Source

pub fn nodes_involved(&self) -> usize

Number of distinct nodes involved in active leases.

Source

pub fn active_leases(&self) -> &[LeaseInfo]

Read-only access to active leases.

Source

pub fn ops_mut(&mut self) -> &mut OpCounters

Mutable access to operation counters.

Source

pub fn ops(&self) -> &OpCounters

Read-only access to operation counters.

Source

pub fn snapshot(&self) -> ContextSnapshot

Take a snapshot of the current context state.

Source

pub fn record_fbmu_write(&mut self)

Record an FBMU write operation.

Source

pub fn record_fbmu_read(&mut self)

Record an FBMU read operation.

Source

pub fn record_fbbu_write(&mut self)

Record an FBBU write operation.

Source

pub fn record_fbbu_read(&mut self)

Record an FBBU read operation.

Source

pub fn record_gpu_submit(&mut self)

Record a GPU submit operation.

Source

pub fn record_tasklet_submit(&mut self)

Record a tasklet submit operation.

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.