Skip to main content

EngineMetrics

Struct EngineMetrics 

Source
pub struct EngineMetrics {
    pub tokens_generated: AtomicU64,
    pub tokens_prefilled: AtomicU64,
    pub kv_cache_hits: AtomicU64,
    pub kv_cache_misses: AtomicU64,
    pub decode_nanos: AtomicU64,
    pub prefill_nanos: AtomicU64,
    pub requests_started: AtomicU64,
    pub requests_completed: AtomicU64,
}
Expand description

Thread-safe metrics counters for an inference engine.

Fields§

§tokens_generated: AtomicU64

Total tokens generated (decode phase).

§tokens_prefilled: AtomicU64

Total tokens processed in prefill.

§kv_cache_hits: AtomicU64

Total KV cache hits (prefix/page cache returns a cached slot).

§kv_cache_misses: AtomicU64

Total KV cache misses.

§decode_nanos: AtomicU64

Total decode time in nanoseconds.

§prefill_nanos: AtomicU64

Total prefill time in nanoseconds.

§requests_started: AtomicU64

Number of requests started.

§requests_completed: AtomicU64

Number of requests completed.

Implementations§

Source§

impl EngineMetrics

Source

pub fn new() -> Arc<Self>

Create an Arc-wrapped, zero-initialised metrics instance.

Source

pub fn record_decode_token(&self, elapsed: Duration)

Record a single decode token and the time taken to produce it.

Source

pub fn record_prefill(&self, n_tokens: u64, elapsed: Duration)

Record a prefill phase that processed n_tokens prompt tokens.

Source

pub fn record_kv_hit(&self)

Record a KV-cache hit (prefix or page reuse).

Source

pub fn record_kv_miss(&self)

Record a KV-cache miss (full prefill required).

Source

pub fn record_request_start(&self)

Record that a new inference request has started.

Source

pub fn record_request_complete(&self)

Record that an inference request has completed.

Source

pub fn throughput(&self) -> (f64, f64)

Returns (decode_tokens_per_sec, prefill_tokens_per_sec).

Both values are 0.0 if no time has been recorded for that phase.

Source

pub fn kv_cache_hit_rate(&self) -> f64

Returns KV cache hit rate in the range [0.0, 1.0].

Returns 0.0 when no lookups have been recorded.

Source

pub fn snapshot(&self) -> MetricsSnapshot

Returns a point-in-time snapshot of all counters.

Source

pub fn reset(&self)

Reset all counters to zero.

Trait Implementations§

Source§

impl Debug for EngineMetrics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EngineMetrics

Source§

fn default() -> EngineMetrics

Returns the “default value” for a type. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more