diff --git a/perf/src/client.rs b/perf/src/client.rs index aebf722e0..ff25d7d1f 100644 --- a/perf/src/client.rs +++ b/perf/src/client.rs @@ -2,6 +2,7 @@ use std::path::PathBuf; use std::{ net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, + path::Path, sync::Arc, time::{Duration, Instant}, }; @@ -166,15 +167,22 @@ pub async fn run(opt: Opt) -> Result<()> { let stats_fut = async { let interval_duration = Duration::from_secs(opt.interval); + #[cfg(feature = "json-output")] + let allow_table_output = opt.json.clone().is_none_or(|path| path != Path::new("-")); + #[cfg(not(feature = "json-output"))] + let allow_table_output = true; + loop { let start = Instant::now(); tokio::time::sleep(interval_duration).await; { stats.on_interval(start, &stream_stats); - stats.print(); - if opt.common.conn_stats { - println!("{:?}\n", connection.stats()); + if allow_table_output { + stats.print(); + if opt.common.conn_stats { + println!("{:?}\n", connection.stats()); + } } } } diff --git a/perf/src/stats.rs b/perf/src/stats.rs index e042cbfb1..ba10a0ba0 100644 --- a/perf/src/stats.rs +++ b/perf/src/stats.rs @@ -120,12 +120,11 @@ impl Stats { #[cfg(feature = "json-output")] pub fn print_json(&self, path: &Path) -> io::Result<()> { - match path { - path if path == Path::new("-") => json::print(self, std::io::stdout()), - _ => { - let file = File::create(path)?; - json::print(self, file) - } + if path == Path::new("-") { + json::print(self, std::io::stdout()); + } else { + let file = File::create(path)?; + json::print(self, file) } Ok(()) }