pub struct CacheMetrics {
pub total_requests: u32,
pub requests_with_cache_hits: u32,
pub total_prompt_tokens: i64,
pub total_cache_read_tokens: i64,
pub total_cache_creation_tokens: i64,
pub cache_hit_ratio: f64,
pub cache_utilization_ratio: f64,
pub avg_cached_tokens_per_request: f64,
}Available on crate feature
runner only.Expand description
Metrics computed from session event history.
All ratio fields are percentages in the range [0.0, 100.0].
When there are no events with usage metadata, all fields are zero.
§Example
ⓘ
use adk_runner::CachePerformanceAnalyzer;
let events = session.events();
let metrics = CachePerformanceAnalyzer::analyze(&events);
println!("Cache hit ratio: {:.1}%", metrics.cache_hit_ratio);Fields§
§total_requests: u32Total requests with UsageMetadata.
requests_with_cache_hits: u32Requests where cache_read_input_token_count > 0.
total_prompt_tokens: i64Sum of all prompt_token_count values.
total_cache_read_tokens: i64Sum of all cache_read_input_token_count values.
total_cache_creation_tokens: i64Sum of all cache_creation_input_token_count values.
cache_hit_ratio: f64total_cache_read_tokens / total_prompt_tokens * 100.
cache_utilization_ratio: f64requests_with_cache_hits / total_requests * 100.
avg_cached_tokens_per_request: f64total_cache_read_tokens / total_requests.
Trait Implementations§
Source§impl Clone for CacheMetrics
impl Clone for CacheMetrics
Source§fn clone(&self) -> CacheMetrics
fn clone(&self) -> CacheMetrics
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CacheMetrics
impl Debug for CacheMetrics
Source§impl Default for CacheMetrics
impl Default for CacheMetrics
Source§fn default() -> CacheMetrics
fn default() -> CacheMetrics
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for CacheMetrics
impl<'de> Deserialize<'de> for CacheMetrics
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CacheMetrics, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CacheMetrics, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for CacheMetrics
impl Serialize for CacheMetrics
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for CacheMetrics
impl RefUnwindSafe for CacheMetrics
impl Send for CacheMetrics
impl Sync for CacheMetrics
impl Unpin for CacheMetrics
impl UnsafeUnpin for CacheMetrics
impl UnwindSafe for CacheMetrics
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestCreates a shared type from an unshared type.