]> granicus.if.org Git - pgbadger/commitdiff
Fix missing Avg values in CSV report. Thanks to Yosuke Tomita for the report.
authorDarold Gilles <gilles@darold.net>
Fri, 14 Oct 2016 13:51:25 +0000 (15:51 +0200)
committerDarold Gilles <gilles@darold.net>
Fri, 14 Oct 2016 13:51:25 +0000 (15:51 +0200)
tools/pgbadger_tools

index 9a41f2ca6b0ad5f7deb1e7d67e1f861319d653c5..6bc69aa30949028db2a15d2050107b7dc7e56c43 100755 (executable)
@@ -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,