summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcyqsimon <28627918+cyqsimon@users.noreply.github.com>2023-10-12 19:03:52 +0800
committercyqsimon <28627918+cyqsimon@users.noreply.github.com>2023-10-12 19:03:52 +0800
commitea3e0d675f976cc776e3cb331b9d721f34858477 (patch)
treed0696909334d5d8ca88e53973b9a23bf31388d63
parentb1726fc1cc33445bd5787d2a1c6a8143d85a8859 (diff)
Reduce logging noise by omitting known orphan connections
-rw-r--r--src/display/ui.rs7
-rw-r--r--src/display/ui_state.rs9
2 files changed, 11 insertions, 5 deletions
diff --git a/src/display/ui.rs b/src/display/ui.rs
index 4c13da6..3241b0b 100644
--- a/src/display/ui.rs
+++ b/src/display/ui.rs
@@ -30,9 +30,10 @@ where
let mut terminal = Terminal::new(terminal_backend).unwrap();
terminal.clear().unwrap();
terminal.hide_cursor().unwrap();
- let state = UIState {
- cumulative_mode: opts.total_utilization,
- ..Default::default()
+ let state = {
+ let mut state = UIState::default();
+ state.cumulative_mode = opts.total_utilization;
+ state
};
Ui {
terminal,
diff --git a/src/display/ui_state.rs b/src/display/ui_state.rs
index 36f679a..54ffbd1 100644
--- a/src/display/ui_state.rs
+++ b/src/display/ui_state.rs
@@ -1,4 +1,5 @@
use std::{
+ cell::RefCell,
cmp,
collections::{HashMap, HashSet, VecDeque},
hash::Hash,
@@ -87,10 +88,13 @@ pub struct UIState {
pub processes_map: HashMap<String, NetworkData>,
pub remote_addresses_map: HashMap<IpAddr, NetworkData>,
pub connections_map: HashMap<Connection, ConnectionData>,
+ /// Used for reducing logging noise.
+ known_orphan_sockets: RefCell<HashSet<LocalSocket>>,
}
impl UIState {
fn get_proc_name<'a>(
+ &self,
connections_to_procs: &'a HashMap<LocalSocket, String>,
local_socket: &LocalSocket,
) -> Option<&'a String> {
@@ -113,7 +117,8 @@ impl UIState {
})
});
- if name.is_none() {
+ // only log each orphan connection once
+ if name.is_none() && self.known_orphan_sockets.borrow_mut().insert(*local_socket) {
match connections_to_procs
.iter()
.find(|(socket, _)| socket.port == port && socket.protocol == protocol)
@@ -173,7 +178,7 @@ impl UIState {
total_bytes_uploaded += connection_info.total_bytes_uploaded;
let data_for_process = if let Some(process_name) =
- UIState::get_proc_name(connections_to_procs, &connection.local_socket)
+ self.get_proc_name(connections_to_procs, &connection.local_socket)
{
connection_data.process_name = process_name.clone();
processes