pub struct Timer { /* private fields */ }Expand description
One named measurement region.
A host timer brackets arbitrary host code. A device timer must be
initialized against an engine, then one
Engine::checkpoint_with_timer records the device timestamps around the
submitted batch. The device path is single-flight: a timer cannot tag a
new submission while its previous one is still pending.
Implementations§
Source§impl Timer
impl Timer
Sourcepub fn new(domain: TimerDomain, name: impl Into<String>) -> Self
pub fn new(domain: TimerDomain, name: impl Into<String>) -> Self
Create a timer in domain named name.
Sourcepub fn init(&mut self, engine: &Engine, name: impl Into<String>) -> Result<()>
pub fn init(&mut self, engine: &Engine, name: impl Into<String>) -> Result<()>
Resolve Auto to Device and acquire this engine’s device timestamp
backend. A host timer needs no engine and initialization is a no-op.
§Errors
Returns an error when the domain is Device and the engine’s compute
queue cannot provide timestamps.
Sourcepub fn begin(&mut self) -> Result<()>
pub fn begin(&mut self) -> Result<()>
Begin a host-side region. Auto resolves to Host here.
§Errors
Returns an error when the timer resolves to Device — device regions are
recorded by Engine::checkpoint_with_timer — or when a previous host
region is still running.
Sourcepub fn commit(&mut self, units: f64) -> Result<f64>
pub fn commit(&mut self, units: f64) -> Result<f64>
Commit the measured region in milliseconds and remember units for
Timer::throughput. Never waits: a device timer requires its tagged
submission to be complete.
§Errors
FailedPrecondition: no completed region exists (host timer without a finishedbegin/end, device timer without a tagged submission).NotReady: the device submission is still pending.- Vulkan timestamp readback failures.
Sourcepub const fn elapsed_milliseconds(&self) -> f64
pub const fn elapsed_milliseconds(&self) -> f64
Return the last committed region duration in milliseconds.
Sourcepub const fn throughput(&self) -> f64
pub const fn throughput(&self) -> f64
Return committed units per second, or 0.0 before a nonzero commit.
Sourcepub const fn domain(&self) -> TimerDomain
pub const fn domain(&self) -> TimerDomain
Return the resolved or configured domain.
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Return whether this timer can measure in its current domain. A host
timer is always initialized; a device timer requires Timer::init.
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Return whether a measurement region is in flight: a running host region, or a device submission that has not completed.