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

Function parse_nettop_network_totals

packages/server/src/performance.rs:863–903  ·  view source on GitHub ↗
(output: &str)

Source from the content-addressed store, hash-verified

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());
865 let Some(header) = lines.next() else {
866 return (None, None);
867 };
868 let columns = split_nettop_csv_line(header);
869 let Some(received_index) = columns.iter().position(|column| column == "bytes_in") else {
870 return (None, None);
871 };
872 let Some(sent_index) = columns.iter().position(|column| column == "bytes_out") else {
873 return (None, None);
874 };
875
876 let mut received_total = 0_u64;
877 let mut sent_total = 0_u64;
878 let mut saw_received = false;
879 let mut saw_sent = false;
880
881 for line in lines {
882 let fields = split_nettop_csv_line(line);
883 if let Some(value) = fields
884 .get(received_index)
885 .and_then(|field| parse_nettop_byte_value(field))
886 {
887 received_total = received_total.saturating_add(value);
888 saw_received = true;
889 }
890 if let Some(value) = fields
891 .get(sent_index)
892 .and_then(|field| parse_nettop_byte_value(field))
893 {
894 sent_total = sent_total.saturating_add(value);
895 saw_sent = true;
896 }
897 }
898
899 (
900 saw_received.then_some(received_total),
901 saw_sent.then_some(sent_total),
902 )
903}
904
905fn split_nettop_csv_line(line: &str) -> Vec<String> {
906 line.split(',')

Callers 1

sample_network_totalsFunction · 0.85

Calls 4

split_nettop_csv_lineFunction · 0.85
parse_nettop_byte_valueFunction · 0.85
is_emptyMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected