From cc7806164b3a7e13c9e6706ed160e4c6c59df4bf Mon Sep 17 00:00:00 2001 From: My Arcana <47053826+myarcana@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:26:12 +0800 Subject: [PATCH 1/2] Make buffer size 0 show all ping history in the graph --- gping/src/main.rs | 9 ++++++--- gping/src/plot_data.rs | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/gping/src/main.rs b/gping/src/main.rs index 2a41af7ae..3d95ebf7d 100644 --- a/gping/src/main.rs +++ b/gping/src/main.rs @@ -73,8 +73,8 @@ struct Args { #[arg( short, long, - default_value = "30", - help = "Determines the number of seconds to display in the graph." + default_value = "0", + help = "Determines the number of seconds to display in the graph. Pass 0 for an indefinitely scaling buffer that displays the entire history." )] buffer: u64, /// Resolve ping targets to IPv4 address @@ -176,7 +176,10 @@ impl App { let now = Local::now(); let now_idx; let before_idx; - if (now - self.started) < self.display_interval { + if self.display_interval.is_zero() { + now_idx = now.timestamp_millis() as f64 / 1_000f64; + before_idx = self.started.timestamp_millis() as f64 / 1_000f64; + } else if (now - self.started) < self.display_interval { now_idx = (self.started + self.display_interval).timestamp_millis() as f64 / 1_000f64; before_idx = self.started.timestamp_millis() as f64 / 1_000f64; } else { diff --git a/gping/src/plot_data.rs b/gping/src/plot_data.rs index 6d0e43be4..0402f5803 100644 --- a/gping/src/plot_data.rs +++ b/gping/src/plot_data.rs @@ -33,16 +33,18 @@ impl PlotData { None => self.data.push((idx, f64::NAN)), } // Find the last index that we should remove. - let earliest_timestamp = (now - self.buffer).timestamp_millis() as f64 / 1_000f64; - let last_idx = self - .data - .iter() - .enumerate() - .filter(|(_, (timestamp, _))| *timestamp < earliest_timestamp) - .map(|(idx, _)| idx) - .last(); - if let Some(idx) = last_idx { - self.data.drain(0..idx).for_each(drop) + if !self.buffer.is_zero() { + let earliest_timestamp = (now - self.buffer).timestamp_millis() as f64 / 1_000f64; + let last_idx = self + .data + .iter() + .enumerate() + .filter(|(_, (timestamp, _))| *timestamp < earliest_timestamp) + .map(|(idx, _)| idx) + .last(); + if let Some(idx) = last_idx { + self.data.drain(0..idx).for_each(drop) + } } } From f9e9a6e97021ef4fa2191593779b15d9ab4f4f9a Mon Sep 17 00:00:00 2001 From: My Arcana <47053826+myarcana@users.noreply.github.com> Date: Wed, 14 Feb 2024 20:28:21 +0800 Subject: [PATCH 2/2] Add the buffer size 0 option to the man page --- gping.1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gping.1 b/gping.1 index 5f02998a3..b7b1ad341 100644 --- a/gping.1 +++ b/gping.1 @@ -52,8 +52,9 @@ Default for ping is 0.2, default for cmd is 0.5. .TP \f[B]-b\f[R], \f[B]--buffer\f[R] -Determines the number of seconds to display in the graph. -[default: 30] +Determines the number of seconds to display in the graph. Pass 0 for +an indefinitely scaling buffer that displays the entire history. +[default: 0] .TP \f[B]-4\f[R] Resolve ping targets to IPv4 address