pub struct ActivitySession { /* private fields */ }Expand description
A host-side model of CUPTI’s asynchronous Activity buffer protocol.
The real flow is: the tool registers a requested callback (CUPTI calls it
to obtain an empty buffer) and a completed callback (CUPTI calls it to
hand back a full buffer for draining), enables one or more
CuptiActivityKinds, runs GPU work (which fills buffers), then calls
cuptiActivityFlushAll to force any partial buffer to be completed.
This struct reproduces that ownership dance deterministically: record
fills the pending buffer, flush (and a full buffer) moves records into the
completed queue which ActivitySession::drain empties — modelling the
completed-buffer callback delivering records to the tool.
Implementations§
Source§impl ActivitySession
impl ActivitySession
Sourcepub const DEFAULT_BUFFER_CAPACITY: usize = 256
pub const DEFAULT_BUFFER_CAPACITY: usize = 256
Default per-buffer record capacity, echoing CUPTI’s habit of using a few-MB buffer that holds many fixed-size records.
Sourcepub fn with_buffer_capacity(buffer_capacity: usize) -> Self
pub fn with_buffer_capacity(buffer_capacity: usize) -> Self
Create a session with an explicit per-buffer record capacity.
Sourcepub fn register_callbacks(&mut self)
pub fn register_callbacks(&mut self)
Model cuptiActivityRegisterCallbacks: install the buffer request /
complete hooks. Idempotent.
Sourcepub fn callbacks_registered(&self) -> bool
pub fn callbacks_registered(&self) -> bool
Whether buffer callbacks have been registered.
Sourcepub fn enable(
&mut self,
kind: CuptiActivityKind,
) -> Result<(), CuptiActivityError>
pub fn enable( &mut self, kind: CuptiActivityKind, ) -> Result<(), CuptiActivityError>
Model cuptiActivityEnable(kind): turn a record kind on.
§Errors
CuptiActivityError::CallbacksNotRegistered — CUPTI rejects enabling
activity before buffer callbacks exist (there would be nowhere to put
the records).
Sourcepub fn disable(&mut self, kind: CuptiActivityKind)
pub fn disable(&mut self, kind: CuptiActivityKind)
Model cuptiActivityDisable(kind): turn a record kind off.
Sourcepub fn is_enabled(&self, kind: CuptiActivityKind) -> bool
pub fn is_enabled(&self, kind: CuptiActivityKind) -> bool
Whether the given kind is currently enabled.
Sourcepub fn enabled_kinds(&self) -> &[CuptiActivityKind]
pub fn enabled_kinds(&self) -> &[CuptiActivityKind]
The set of currently enabled kinds.
Sourcepub fn record(
&mut self,
record: ActivityRecord,
) -> Result<(), CuptiActivityError>
pub fn record( &mut self, record: ActivityRecord, ) -> Result<(), CuptiActivityError>
Emit one activity record into the pending buffer.
Models the GPU filling a buffer obtained from the requested callback.
If the record’s kind is not enabled it is silently dropped (CUPTI does
the same) and counted in ActivitySession::dropped_records.
§Errors
CuptiActivityError::CallbacksNotRegisteredif no callbacks exist.CuptiActivityError::BufferFullif the pending buffer is already at capacity — the caller mustActivitySession::flushfirst.
Sourcepub fn flush(&mut self) -> Result<usize, CuptiActivityError>
pub fn flush(&mut self) -> Result<usize, CuptiActivityError>
Model cuptiActivityFlushAll: move every pending record into the
completed queue, as CUPTI does when it hands a full / forced buffer to
the completed callback. Returns the number of records flushed.
§Errors
CuptiActivityError::CallbacksNotRegistered if no callbacks exist —
cuptiActivityFlushAll is meaningless without a completed callback to
deliver buffers to.
Sourcepub fn drain(&mut self) -> Vec<ActivityRecord>
pub fn drain(&mut self) -> Vec<ActivityRecord>
Drain the completed queue, returning all records delivered to the tool since the last drain. Models the tool consuming the completed buffer.
Sourcepub fn pending_len(&self) -> usize
pub fn pending_len(&self) -> usize
Number of records currently waiting in the (un-flushed) pending buffer.
Sourcepub fn completed_len(&self) -> usize
pub fn completed_len(&self) -> usize
Number of records flushed and waiting to be drained.
Sourcepub fn dropped_records(&self) -> u64
pub fn dropped_records(&self) -> u64
Count of records dropped because their kind was disabled.