pub struct Tracker { /* private fields */ }Expand description
SQLite-backed tracker for recording and displaying token savings metrics.
Thread-safe via an internal Mutex<Connection>, satisfying the Sync
requirement of ServerHandler.
§Examples
let tracker = Tracker::new("~/.local/share/mcp-rtk/metrics.db").unwrap();
tracker.track("list_merge_requests", "{...raw...}", "{...filtered...}", "gitlab").unwrap();
tracker.print_stats().unwrap();Implementations§
Source§impl Tracker
impl Tracker
Sourcepub fn new(db_path: &str) -> Result<Self>
pub fn new(db_path: &str) -> Result<Self>
Open or create the tracking database at the given path.
Supports ~/ expansion. Creates parent directories if needed.
§Errors
Returns an error if the database directory cannot be created or the SQLite connection fails to open.
Sourcepub fn track(
&self,
tool_name: &str,
raw_output: &str,
filtered_output: &str,
preset: &str,
) -> Result<()>
pub fn track( &self, tool_name: &str, raw_output: &str, filtered_output: &str, preset: &str, ) -> Result<()>
Record a single tool call’s raw and filtered output sizes.
Token count is estimated as bytes / 4.
§Errors
Returns an error if the database lock is poisoned or the insert fails.
Sourcepub fn print_stats(&self) -> Result<()>
pub fn print_stats(&self) -> Result<()>
Print a colorful summary of all-time token savings to stdout.
Includes an efficiency meter bar and a per-tool breakdown table with impact bars.
§Errors
Returns an error if the database lock is poisoned or query fails.
Sourcepub fn print_history(&self) -> Result<()>
pub fn print_history(&self) -> Result<()>
Print the last 50 tool calls with timestamps and savings percentages.
§Errors
Returns an error if the database lock is poisoned or query fails.
Sourcepub fn stats_as_json(&self) -> Result<Value>
pub fn stats_as_json(&self) -> Result<Value>
Return all tracking stats as a serde_json::Value for programmatic use.
§Errors
Returns an error if the database lock is poisoned or query fails.
Sourcepub fn export_json(&self) -> Result<()>
pub fn export_json(&self) -> Result<()>
Export all tracking stats as pretty-printed JSON to stdout.
§Errors
Returns an error if the database lock is poisoned or query fails.
Sourcepub fn tracked_presets(&self) -> Result<HashSet<String>>
pub fn tracked_presets(&self) -> Result<HashSet<String>>
Return the set of preset names that have tracking data.
Used by discover to detect which servers are already proxied.