pub struct StreamStats {
pub tokens_generated: usize,
pub prefill_tokens: usize,
pub time_to_first_token_ms: u64,
pub total_time_ms: u64,
pub tokens_per_second: f32,
}Expand description
Per-request generation throughput statistics.
Fields§
§tokens_generated: usizeTotal tokens emitted in the completion.
prefill_tokens: usizeNumber of tokens in the prompt (prefill phase).
time_to_first_token_ms: u64Wall-clock milliseconds until the first token was emitted.
total_time_ms: u64Total wall-clock milliseconds for the entire generation.
tokens_per_second: f32Tokens-per-second throughput (cached result of StreamStats::throughput).
Implementations§
Source§impl StreamStats
impl StreamStats
Sourcepub fn finish(
&mut self,
tokens: usize,
prefill: usize,
ttft_ms: u64,
total_ms: u64,
)
pub fn finish( &mut self, tokens: usize, prefill: usize, ttft_ms: u64, total_ms: u64, )
Record the final statistics after generation completes.
Sourcepub fn throughput(&self) -> f32
pub fn throughput(&self) -> f32
Compute tokens-per-second from recorded statistics.
Returns 0.0 if total_time_ms is zero (avoids division by zero).
Sourcepub fn to_usage_chunk(&self, request_id: &str, model: &str) -> String
pub fn to_usage_chunk(&self, request_id: &str, model: &str) -> String
Serialize these statistics as an SSE usage chunk.
The payload follows the OpenAI convention of appending a final usage
chunk before [DONE]:
{"id":"...","object":"chat.completion.chunk","usage":{"prompt_tokens":…,…}}Trait Implementations§
Source§impl Debug for StreamStats
impl Debug for StreamStats
Source§impl Default for StreamStats
impl Default for StreamStats
Source§fn default() -> StreamStats
fn default() -> StreamStats
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for StreamStats
impl RefUnwindSafe for StreamStats
impl Send for StreamStats
impl Sync for StreamStats
impl Unpin for StreamStats
impl UnsafeUnpin for StreamStats
impl UnwindSafe for StreamStats
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
Mutably borrows from an owned value. Read more
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>
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 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>
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