From: Darold Gilles Date: Fri, 14 Oct 2016 13:51:25 +0000 (+0200) Subject: Fix missing Avg values in CSV report. Thanks to Yosuke Tomita for the report. X-Git-Tag: v9.1~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a11b8fdd4bbbacd111162d2844edc76d4d4cc37;p=pgbadger Fix missing Avg values in CSV report. Thanks to Yosuke Tomita for the report. --- diff --git a/tools/pgbadger_tools b/tools/pgbadger_tools index 9a41f2c..6bc69aa 100755 --- a/tools/pgbadger_tools +++ b/tools/pgbadger_tools @@ -786,6 +786,13 @@ sub load_stats foreach my $stmt (keys %_normalyzed_info) { + if (!$_normalyzed_info{$stmt}{count}) { + $normalyzed_info{$stmt}{average} = 0; + } else { + $normalyzed_info{$stmt}{average} = $_normalyzed_info{$stmt}{duration} / $_normalyzed_info{$stmt}{count}; + $normalyzed_info{$stmt}{average} =~ s/(\.\d{3}).*/$1/; + } + foreach my $dt (keys %{$_normalyzed_info{$stmt}{samples}} ) { foreach my $k (keys %{$_normalyzed_info{$stmt}{samples}{$dt}} ) { $normalyzed_info{$stmt}{samples}{$dt}{$k} = $_normalyzed_info{$stmt}{samples}{$dt}{$k}; @@ -1228,6 +1235,8 @@ sub csv_times_consuming_queries # Do not process request that are slower than $max_duration next if ( $max_duration && ( $d > $max_duration) ); + $normalyzed_info{$k}{average} = $normalyzed_info{$k}{duration} / $normalyzed_info{$k}{count}; + $csv->print ($fhcsv, [ $normalyzed_info{$k}{samples}{$d}{db}, $rank,