(pid: i32)
| 832 | } |
| 833 | |
| 834 | async fn sample_network_totals(pid: i32) -> Result<(Option<u64>, Option<u64>), AppError> { |
| 835 | let output = timeout( |
| 836 | NETWORK_TOTALS_TIMEOUT, |
| 837 | Command::new("nettop") |
| 838 | .args([ |
| 839 | "-P", |
| 840 | "-L", |
| 841 | "1", |
| 842 | "-x", |
| 843 | "-J", |
| 844 | "bytes_in,bytes_out", |
| 845 | "-p", |
| 846 | &pid.to_string(), |
| 847 | ]) |
| 848 | .output(), |
| 849 | ) |
| 850 | .await |
| 851 | .map_err(|_| AppError::native("Timed out reading process network totals."))? |
| 852 | .map_err(|error| AppError::native(format!("Unable to read process network totals: {error}")))?; |
| 853 | |
| 854 | if !output.status.success() { |
| 855 | return Ok((None, None)); |
| 856 | } |
| 857 | |
| 858 | Ok(parse_nettop_network_totals(&String::from_utf8_lossy( |
| 859 | &output.stdout, |
| 860 | ))) |
| 861 | } |
| 862 | |
| 863 | fn parse_nettop_network_totals(output: &str) -> (Option<u64>, Option<u64>) { |
| 864 | let mut lines = output.lines().filter(|line| !line.trim().is_empty()); |
no test coverage detected