pub struct CostTracker { /* private fields */ }Expand description
Per-model cost tracking and savings computation.
All operations are lock-free via atomics. Costs are stored as micro-dollars (1 USD = 1 000 000 micro-dollars) to avoid floating-point drift in long-running aggregations.
§Panics
This type and its methods never panic.
Implementations§
Source§impl CostTracker
impl CostTracker
Sourcepub fn new(local_cost_per_1k: f64, cloud_cost_per_1k: f64) -> Self
pub fn new(local_cost_per_1k: f64, cloud_cost_per_1k: f64) -> Self
Create a new cost tracker.
§Arguments
local_cost_per_1k— Cost per 1 000 tokens for the local model (USD).cloud_cost_per_1k— Cost per 1 000 tokens for the cloud model (USD).
§Returns
A new CostTracker with all counters at zero.
§Panics
This function never panics.
Sourcepub fn record_local(&self, tokens: u64)
pub fn record_local(&self, tokens: u64)
Sourcepub fn record_cloud(&self, tokens: u64)
pub fn record_cloud(&self, tokens: u64)
Sourcepub fn record_fallback(&self, tokens: u64)
pub fn record_fallback(&self, tokens: u64)
Sourcepub fn snapshot(&self) -> CostSnapshot
pub fn snapshot(&self) -> CostSnapshot
Return a snapshot of current cost metrics.
§Returns
A CostSnapshot with all current counters and computed costs.
§Panics
This function never panics.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for CostTracker
impl RefUnwindSafe for CostTracker
impl Send for CostTracker
impl Sync for CostTracker
impl Unpin for CostTracker
impl UnsafeUnpin for CostTracker
impl UnwindSafe for CostTracker
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§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::Request