| 191 | } |
| 192 | |
| 193 | pub fn snapshot(&self) -> StatsSnapshot { |
| 194 | let map = match self.filtered_email_addresses.lock() { |
| 195 | Ok(guard) => guard.clone(), |
| 196 | Err(poisoned) => poisoned.into_inner().clone(), |
| 197 | }; |
| 198 | StatsSnapshot { |
| 199 | requests_total: self.requests_total.load(Ordering::Relaxed), |
| 200 | prompt_tokens_total: self.prompt_tokens_total.load(Ordering::Relaxed), |
| 201 | completion_tokens_total: self.completion_tokens_total.load(Ordering::Relaxed), |
| 202 | total_tokens_total: self.total_tokens_total.load(Ordering::Relaxed), |
| 203 | emails_filtered_total: self.emails_filtered_total.load(Ordering::Relaxed), |
| 204 | filtered_email_addresses: map, |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | /// Write the current snapshot to disk if configured and there are |
| 209 | /// unsaved changes. Atomic: write to a sibling temp file, then rename. |