pub struct TokenStats {
pub read_fires: AtomicUsize,
pub read_saved_tokens: AtomicU64,
pub edit_fires: AtomicUsize,
pub edit_saved_tokens: AtomicU64,
pub write_fires: AtomicUsize,
pub grep_fires: AtomicUsize,
pub grep_saved_tokens: AtomicU64,
pub tool_calls: Mutex<HashMap<String, usize>>,
pub tool_token_details: Mutex<HashMap<String, (u64, u64)>>,
pub total_tokens_served: AtomicU64,
pub total_tokens_naive: AtomicU64,
}Expand description
In-memory atomic counters tracking hook fires and estimated token savings per hook type.
All counters start at zero; incremented by handlers on each successful response.
Token savings are estimated as (file_bytes - output_bytes) / 4 (bytes-per-token heuristic).
Fields§
§read_fires: AtomicUsize§read_saved_tokens: AtomicU64§edit_fires: AtomicUsize§edit_saved_tokens: AtomicU64§write_fires: AtomicUsizeWrite fires track new-file indexing; no savings because it’s additive context.
grep_fires: AtomicUsize§grep_saved_tokens: AtomicU64§tool_calls: Mutex<HashMap<String, usize>>Per-tool invocation counts since daemon start.
tool_token_details: Mutex<HashMap<String, (u64, u64)>>Per-tool token tracking: tool_name -> (tokens_served, tokens_saved).
total_tokens_served: AtomicU64Total tokens served across all tool calls this session.
total_tokens_naive: AtomicU64Total estimated naive-equivalent tokens (what raw file reads would cost).
Implementations§
Source§impl TokenStats
impl TokenStats
Sourcepub fn record_read(&self, file_bytes: u64, output_bytes: u64)
pub fn record_read(&self, file_bytes: u64, output_bytes: u64)
Record a Read hook fire. Savings vs competent-manual windowed-read baseline.
Sourcepub fn record_edit(&self, file_bytes: u64, output_bytes: u64)
pub fn record_edit(&self, file_bytes: u64, output_bytes: u64)
Record an Edit hook fire. Savings vs competent-manual windowed-read baseline.
Sourcepub fn record_write(&self)
pub fn record_write(&self)
Record a Write hook fire (new-file indexing). No savings — additive context.
Sourcepub fn record_grep(&self, _file_bytes: u64, output_bytes: u64)
pub fn record_grep(&self, _file_bytes: u64, output_bytes: u64)
Record a Grep hook fire. Savings vs competent-manual grep+window baseline.
Sourcepub fn record_tool_call(&self, name: &str)
pub fn record_tool_call(&self, name: &str)
Record a single MCP tool invocation by name.
Sourcepub fn record_tool_tokens(
&self,
tool_name: &str,
tokens_served: u64,
tokens_saved: u64,
)
pub fn record_tool_tokens( &self, tool_name: &str, tokens_served: u64, tokens_saved: u64, )
Record per-tool token details: tokens served and tokens saved.
Sourcepub fn tool_token_details(&self) -> Vec<(String, u64, u64)>
pub fn tool_token_details(&self) -> Vec<(String, u64, u64)>
Return per-tool token details sorted by tokens saved descending.
Sourcepub fn tool_call_counts(&self) -> Vec<(String, usize)>
pub fn tool_call_counts(&self) -> Vec<(String, usize)>
Return per-tool invocation counts sorted by count descending, then name ascending.
Sourcepub fn summary(&self) -> StatsSnapshot
pub fn summary(&self) -> StatsSnapshot
Read all counter values atomically (Relaxed ordering — display only).
Auto Trait Implementations§
impl !Freeze for TokenStats
impl !RefUnwindSafe for TokenStats
impl Send for TokenStats
impl Sync for TokenStats
impl Unpin for TokenStats
impl UnsafeUnpin for TokenStats
impl UnwindSafe for TokenStats
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<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