| 770 | } |
| 771 | |
| 772 | fn prune_history(history: &mut VecDeque<PerformanceSample>, now_ms: u64) { |
| 773 | let retention_start = now_ms.saturating_sub(HISTORY_RETENTION_MS); |
| 774 | while history |
| 775 | .front() |
| 776 | .is_some_and(|sample| sample.timestamp_ms < retention_start) |
| 777 | { |
| 778 | history.pop_front(); |
| 779 | } |
| 780 | while history.len() > HISTORY_MAX_SAMPLES { |
| 781 | history.pop_front(); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | async fn sample_network(pid: i32) -> Result<NetworkSnapshot, AppError> { |
| 786 | let (received_bytes, sent_bytes) = sample_network_totals(pid).await.unwrap_or((None, None)); |