pub struct RequestStreamMetrics { /* private fields */ }Expand description
Per-request streaming metrics collector.
Call record_first_token on the
first generated token, record_token
for each subsequent token, and
finish when generation is complete.
Implementations§
Source§impl RequestStreamMetrics
impl RequestStreamMetrics
Sourcepub fn new_with_prompt_tokens(prompt_tokens: usize) -> Self
pub fn new_with_prompt_tokens(prompt_tokens: usize) -> Self
Create a new metrics collector that records the prompt token count.
Sourcepub fn record_first_token(&mut self)
pub fn record_first_token(&mut self)
Record the arrival of the first generated token.
Calling this multiple times is safe — only the first call is recorded.
Sourcepub fn record_token(&mut self)
pub fn record_token(&mut self)
Record the arrival of a subsequent generated token (not the first).
If record_first_token has not been called
yet, this call is treated as the first token.
Sourcepub fn finish(&mut self)
pub fn finish(&mut self)
Mark the end of the generation pass.
This records a final timestamp used for end-to-end latency. It is safe to call even before any tokens have been recorded.
Sourcepub fn ttft(&self) -> Option<Duration>
pub fn ttft(&self) -> Option<Duration>
Time to first token (TTFT).
Returns None if record_first_token has
not been called.
Sourcepub fn median_tbt(&self) -> Option<Duration>
pub fn median_tbt(&self) -> Option<Duration>
Median inter-token latency.
Returns None when fewer than two tokens have been recorded (i.e. there
are no TBT samples).
Sourcepub fn p99_tbt(&self) -> Option<Duration>
pub fn p99_tbt(&self) -> Option<Duration>
P99 inter-token latency.
Returns None when there are no TBT samples.
Sourcepub fn mean_tbt(&self) -> Option<Duration>
pub fn mean_tbt(&self) -> Option<Duration>
Mean (arithmetic average) inter-token latency.
Returns None when there are no TBT samples.
Sourcepub fn tokens_per_second(&self) -> Option<f64>
pub fn tokens_per_second(&self) -> Option<f64>
Generation throughput in tokens per second.
Computed over the decode window (from first token to last token) so that TTFT does not distort the throughput figure.
Returns None if the decode window cannot be determined.
Sourcepub fn e2e_latency(&self) -> Option<Duration>
pub fn e2e_latency(&self) -> Option<Duration>
End-to-end request latency (from request start to generation finish).
Returns None if finish has not been called.
Sourcepub fn completion_tokens(&self) -> usize
pub fn completion_tokens(&self) -> usize
Total number of completion tokens generated so far.
Sourcepub fn snapshot(&self) -> StreamMetricsSnapshot
pub fn snapshot(&self) -> StreamMetricsSnapshot
Take a point-in-time snapshot of the current metrics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RequestStreamMetrics
impl RefUnwindSafe for RequestStreamMetrics
impl Send for RequestStreamMetrics
impl Sync for RequestStreamMetrics
impl Unpin for RequestStreamMetrics
impl UnsafeUnpin for RequestStreamMetrics
impl UnwindSafe for RequestStreamMetrics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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