mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-16 16:25:08 +00:00
fix(perf): suppress table output in JSON mode
Suppress table output meant to provide human-friendly visualization when using the `--json` CLI option and its argument is `-`, that is, when the JSON output targets stdout. Fixes #2544.
This commit is contained in:
committed by
Benjamin Saunders
parent
459c347149
commit
f853e5e082
+11
-3
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-6
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user