Skip to content

Commit

Permalink
Actually silence output of extra stats
Browse files Browse the repository at this point in the history
  • Loading branch information
fredclausen committed Nov 17, 2023
1 parent 475075f commit 711a5c8
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions rust/libraries/acars_connection_manager/src/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ impl MessageHandlerConfig {
let stats_total_messages_context: Arc<Mutex<i32>> = Arc::clone(&total_messages_processed);
let stats_total_messages_since_last_context: Arc<Mutex<i32>> =
Arc::clone(&total_messages_since_last);
let stats_frequency_context: Arc<Mutex<Vec<FrequencyCount>>> =
Arc::clone(&all_frequencies_logged);
let stats_frequency_context: Option(Arc<Mutex<Vec<FrequencyCount>>>) = if self.stats_verbose
{
Some(Arc::clone(&all_frequencies_logged))
} else {
None
};

tokio::spawn(async move {
print_stats(
Expand Down Expand Up @@ -314,7 +318,7 @@ impl MessageHandlerConfig {
pub async fn print_stats(
total_all_time: Arc<Mutex<i32>>,
total_since_last: Arc<Mutex<i32>>,
frequencies: Arc<Mutex<Vec<FrequencyCount>>>,
frequencies: Option(Arc<Mutex<Vec<FrequencyCount>>>),
stats_every: u64,
queue_type: &str,
) {
Expand All @@ -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);
Expand Down

0 comments on commit 711a5c8

Please sign in to comment.