MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / sample_network_totals

Function sample_network_totals

packages/server/src/performance.rs:834–861  ·  view source on GitHub ↗
(pid: i32)

Source from the content-addressed store, hash-verified

832}
833
834async 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
863fn parse_nettop_network_totals(output: &str) -> (Option<u64>, Option<u64>) {
864 let mut lines = output.lines().filter(|line| !line.trim().is_empty());

Callers 1

sample_networkFunction · 0.85

Calls 2

outputMethod · 0.65

Tested by

no test coverage detected