From 711a5c8d3dce020ed5d8980edf820347b6075d34 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Thu, 16 Nov 2023 22:50:01 -0700 Subject: [PATCH] Actually silence output of extra stats --- .../src/message_handler.rs | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/rust/libraries/acars_connection_manager/src/message_handler.rs b/rust/libraries/acars_connection_manager/src/message_handler.rs index ec50a7e9..06fb47ab 100644 --- a/rust/libraries/acars_connection_manager/src/message_handler.rs +++ b/rust/libraries/acars_connection_manager/src/message_handler.rs @@ -87,8 +87,12 @@ impl MessageHandlerConfig { let stats_total_messages_context: Arc> = Arc::clone(&total_messages_processed); let stats_total_messages_since_last_context: Arc> = Arc::clone(&total_messages_since_last); - let stats_frequency_context: Arc>> = - Arc::clone(&all_frequencies_logged); + let stats_frequency_context: Option(Arc>>) = if self.stats_verbose + { + Some(Arc::clone(&all_frequencies_logged)) + } else { + None + }; tokio::spawn(async move { print_stats( @@ -314,7 +318,7 @@ impl MessageHandlerConfig { pub async fn print_stats( total_all_time: Arc>, total_since_last: Arc>, - frequencies: Arc>>, + frequencies: Option(Arc>>), stats_every: u64, queue_type: &str, ) { @@ -331,15 +335,22 @@ pub async fn print_stats( // now print the frequencies, and show each as a percentage of the total_all_time - for freq in frequencies.lock().await.iter_mut() { - let percentage: f64 = (freq.count as f64 / total_all_time_locked as f64) * 100.0; - output.push_str( - format!( - "{} {}: {}/{} ({:.2}%)\n", - queue_type, freq.freq, freq.count, total_all_time_locked, percentage - ) - .as_str(), - ); + match frequencies { + None => {} + Some(frequencies) => { + // now print the frequencies, and show each as a percentage of the total_all_time + for freq in frequencies.lock().await.iter_mut() { + let percentage: f64 = + (freq.count as f64 / total_all_time_locked as f64) * 100.0; + output.push_str( + format!( + "{} {}: {}/{} ({:.2}%)\n", + queue_type, freq.freq, freq.count, total_all_time_locked, percentage + ) + .as_str(), + ); + } + } } println!("{}", output);