Debian Codegraph @

src/collection/network/sysinfo.rs

raw symbols SCIP
1 //! Gets network data via sysinfo.
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#;
4
5 use sysinforust-analyzer cargo sysinfo 0.39.6 crate/::Networksrust-analyzer cargo sysinfo 0.39.6 common/network/Networks#;
6
7 use superrust-analyzer cargo bottom 0.14.9 collection/network/::NetworkHarvestrust-analyzer cargo bottom 0.14.9 collection/network/NetworkHarvest#;
8 use craterust-analyzer cargo bottom 0.14.9 crate/::apprust-analyzer cargo bottom 0.14.9 app/::filterrust-analyzer cargo bottom 0.14.9 app/filter/::Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#;
9
10 // TODO: Eventually make it so that this thing also takes individual usage into
11 // account, so we can show per-interface!
12 pub fn get_network_datarust-analyzer cargo bottom 0.14.9 collection/network/sysinfo/get_network_data().(
13 networks: &Networksrust-analyzer cargo sysinfo 0.39.6 common/network/Networks#, prev_net_access_time: Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#, prev_net_rx: &mut u64,
14 prev_net_tx: &mut u64, prev_net_rx_packets: &mut u64, prev_net_tx_packets: &mut u64,
15 curr_time: Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#, filter: &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#>,
16 ) -> NetworkHarvestrust-analyzer cargo bottom 0.14.9 collection/network/NetworkHarvest# {
17 let mut total_rx: u64 = 0;
18 let mut total_tx: u64 = 0;
19 let mut total_rx_packets: u64 = 0;
20 let mut total_tx_packets: u64 = 0;
21
22 for (name, network) in networks {
23 let to_keep = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(filter) = filter {
24 filter.should_keeprust-analyzer cargo bottom 0.14.9 app/filter/impl#[Filter]should_keep().(name)
25 } else {
26 true
27 };
28
29 if to_keep {
30 total_rx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().network.total_receivedrust-analyzer cargo sysinfo 0.39.6 common/network/impl#[NetworkData]total_received().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().8;
31 total_tx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().network.total_transmittedrust-analyzer cargo sysinfo 0.39.6 common/network/impl#[NetworkData]total_transmitted().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().8;
32 total_rx_packets rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().network.total_packets_receivedrust-analyzer cargo sysinfo 0.39.6 common/network/impl#[NetworkData]total_packets_received().();
33 total_tx_packets rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().network.total_packets_transmittedrust-analyzer cargo sysinfo 0.39.6 common/network/impl#[NetworkData]total_packets_transmitted().();
34 }
35 }
36
37 let elapsed_time = curr_time.duration_sincerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]duration_since().(prev_net_access_time).as_secs_f64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_secs_f64().();
38
39 let (rx, tx, rx_packets, tx_packets) = if elapsed_time rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().0.0 {
40 (0, 0, 0, 0)
41 } else {
42 (
43 ((total_rx.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_net_rx)) as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().elapsed_time) as u64,
44 ((total_tx.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_net_tx)) as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().elapsed_time) as u64,
45 ((total_rx_packets.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_net_rx_packets)) as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().elapsed_time) as u64,
46 ((total_tx_packets.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_net_tx_packets)) as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().elapsed_time) as u64,
47 )
48 };
49
50 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_net_rx = total_rx;
51 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_net_tx = total_tx;
52 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_net_rx_packets = total_rx_packets;
53 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_net_tx_packets = total_tx_packets;
54 NetworkHarvestrust-analyzer cargo bottom 0.14.9 collection/network/NetworkHarvest# {
55 rxrust-analyzer cargo bottom 0.14.9 collection/network/NetworkHarvest#rx.,
56 txrust-analyzer cargo bottom 0.14.9 collection/network/NetworkHarvest#tx.,
57 total_rxrust-analyzer cargo bottom 0.14.9 collection/network/NetworkHarvest#total_rx.,
58 total_txrust-analyzer cargo bottom 0.14.9 collection/network/NetworkHarvest#total_tx.,
59 rx_packetsrust-analyzer cargo bottom 0.14.9 collection/network/NetworkHarvest#rx_packets.,
60 tx_packetsrust-analyzer cargo bottom 0.14.9 collection/network/NetworkHarvest#tx_packets.,
61 total_rx_packetsrust-analyzer cargo bottom 0.14.9 collection/network/NetworkHarvest#total_rx_packets.,
62 total_tx_packetsrust-analyzer cargo bottom 0.14.9 collection/network/NetworkHarvest#total_tx_packets.,
63 }
64 }