| 166 | } |
| 167 | |
| 168 | pub fn record_client_stream_stats(&self, stats: ClientStreamStats) { |
| 169 | let mut snapshots = self |
| 170 | .client_stream_stats |
| 171 | .lock() |
| 172 | .unwrap_or_else(|poisoned| poisoned.into_inner()); |
| 173 | prune_stale_client_stream_stats(&mut snapshots); |
| 174 | |
| 175 | if let Some(existing) = snapshots.iter_mut().find(|existing| { |
| 176 | let (client_id, kind) = existing.key(); |
| 177 | let (next_client_id, next_kind) = stats.key(); |
| 178 | client_id == next_client_id && kind == next_kind |
| 179 | }) { |
| 180 | *existing = stats; |
| 181 | } else { |
| 182 | snapshots.push_back(stats); |
| 183 | } |
| 184 | |
| 185 | while snapshots.len() > CLIENT_STREAM_STATS_LIMIT { |
| 186 | snapshots.pop_front(); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | pub fn client_stream_stats_snapshot(&self) -> Vec<ClientStreamStats> { |
| 191 | let mut snapshots = self |