From: Darold Date: Sun, 24 Jun 2012 11:46:32 +0000 (+0200) Subject: Add --disable-query command line option to remove queries statistics from the output X-Git-Tag: v3.2~219 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=60685f2f1c0cebf27463a6351a86ac7f468262be;p=pgbadger Add --disable-query command line option to remove queries statistics from the output --- diff --git a/README b/README index ed60f5d..d5ae253 100644 --- a/README +++ b/README @@ -46,6 +46,7 @@ SYNOPSIS you can use this option multiple time. --disable-error : do not generate error report. --disable-hourly : do not generate hourly reports. + --disable-query : do not generate queries reports (slowest, most frequent, ...). Examples: diff --git a/doc/pgBadger.pod b/doc/pgBadger.pod index 9460a78..d554b05 100644 --- a/doc/pgBadger.pod +++ b/doc/pgBadger.pod @@ -48,6 +48,7 @@ Options: you can use this option multiple time. --disable-error : do not generate error report. --disable-hourly : do not generate hourly reports. + --disable-query : do not generate queries reports (slowest, most frequent, ...). Examples: diff --git a/pgbadger b/pgbadger index bc5d70b..00f5e1a 100755 --- a/pgbadger +++ b/pgbadger @@ -67,6 +67,8 @@ my $error_only = 0; my @exclude_query = (); my $disable_error = 0; my $disable_hourly = 0; +my $disable_type = 0; +my $disable_query = 0; my $NUMPROGRESS = 10000; my @DIMENSIONS = (800,300); @@ -113,6 +115,8 @@ my $result = GetOptions ( "exclude-query=s" => \@exclude_query, "disable-error!"=> \$disable_error, "disable-hourly!"=> \$disable_hourly, + "disable-type!"=> \$disable_type, + "disable-query!"=> \$disable_query, ); if ($ver) { @@ -525,6 +529,8 @@ Options: you can use this option multiple time. --disable-error : do not generate error report. --disable-hourly : do not generate hourly reports. + --disable-type : do not generate query type report. + --disable-query : do not generate queries reports (slowest, most frequent, ...). Examples: @@ -739,17 +745,19 @@ Report not supported by text format }; } - # INSERT/DELETE/UPDATE/SELECT repartition - my $totala = $overall_stat{'SELECT'} + $overall_stat{'INSERT'} + $overall_stat{'UPDATE'} + $overall_stat{'DELETE'}; - my $total = $overall_stat{'queries_number'}; - print $fh "\n- Queries by type ------------------------------------------------------\n\n"; - print $fh "Type Count Percentage\n"; - print $fh "SELECT: ", &comma_numbers($overall_stat{'SELECT'}) || 0, " ", sprintf("%0.2f", ($overall_stat{'SELECT'}*100)/$total), "%\n"; - print $fh "INSERT: ", &comma_numbers($overall_stat{'INSERT'}) || 0, " ", sprintf("%0.2f", ($overall_stat{'INSERT'}*100)/$total), "%\n"; - print $fh "UPDATE: ", &comma_numbers($overall_stat{'UPDATE'}) || 0, " ", sprintf("%0.2f", ($overall_stat{'UPDATE'}*100)/$total), "%\n"; - print $fh "DELETE: ", &comma_numbers($overall_stat{'DELETE'}) || 0, " ", sprintf("%0.2f", ($overall_stat{'DELETE'}*100)/$total), "%\n"; - print $fh "OTHERS: ", &comma_numbers($total - $totala) || 0, " ", sprintf("%0.2f", (($total - $totala)*100)/$total), "%\n" if (($total - $totala) > 0); - print $fh "\n"; + if (!$disable_type) { + # INSERT/DELETE/UPDATE/SELECT repartition + my $totala = $overall_stat{'SELECT'} + $overall_stat{'INSERT'} + $overall_stat{'UPDATE'} + $overall_stat{'DELETE'}; + my $total = $overall_stat{'queries_number'}; + print $fh "\n- Queries by type ------------------------------------------------------\n\n"; + print $fh "Type Count Percentage\n"; + print $fh "SELECT: ", &comma_numbers($overall_stat{'SELECT'}) || 0, " ", sprintf("%0.2f", ($overall_stat{'SELECT'}*100)/$total), "%\n"; + print $fh "INSERT: ", &comma_numbers($overall_stat{'INSERT'}) || 0, " ", sprintf("%0.2f", ($overall_stat{'INSERT'}*100)/$total), "%\n"; + print $fh "UPDATE: ", &comma_numbers($overall_stat{'UPDATE'}) || 0, " ", sprintf("%0.2f", ($overall_stat{'UPDATE'}*100)/$total), "%\n"; + print $fh "DELETE: ", &comma_numbers($overall_stat{'DELETE'}) || 0, " ", sprintf("%0.2f", ($overall_stat{'DELETE'}*100)/$total), "%\n"; + print $fh "OTHERS: ", &comma_numbers($total - $totala) || 0, " ", sprintf("%0.2f", (($total - $totala)*100)/$total), "%\n" if (($total - $totala) > 0); + print $fh "\n"; + } if (scalar keys %lock_info > 0) { print $fh "\n- Locks by type ------------------------------------------------------\n\n"; @@ -827,88 +835,90 @@ Report not supported by text format } # Show top informations - print $fh "\n- Slowest queries ------------------------------------------------------\n\n"; - print $fh "Rank Duration (s) Query\n"; - for (my $i = 0; $i <= $#top_slowest; $i++) { - print $fh $i+1, ") " . &convert_time($top_slowest[$i]->[0]) . " - $top_slowest[$i]->[2]\n"; - print $fh "--\n"; - } - @top_slowest = (); + if (!$disable_query) { + print $fh "\n- Slowest queries ------------------------------------------------------\n\n"; + print $fh "Rank Duration (s) Query\n"; + for (my $i = 0; $i <= $#top_slowest; $i++) { + print $fh $i+1, ") " . &convert_time($top_slowest[$i]->[0]) . " - $top_slowest[$i]->[2]\n"; + print $fh "--\n"; + } + @top_slowest = (); - print $fh "\n- Queries that took up the most time (N) -------------------------------\n\n"; - print $fh "Rank Total duration Times executed Av. duration (s) Query\n"; - my $idx = 1; - foreach my $k (sort {$normalyzed_info{$b}{duration} <=> $normalyzed_info{$a}{duration}} keys %normalyzed_info) { - next if (!$normalyzed_info{$k}{count}); - last if ($idx > $top); - my $q = $k; - if ($normalyzed_info{$k}{count} == 1) { - foreach (keys %{$normalyzed_info{$k}{samples}}) { - $q = $normalyzed_info{$k}{samples}{$_}{query}; - last; + print $fh "\n- Queries that took up the most time (N) -------------------------------\n\n"; + print $fh "Rank Total duration Times executed Av. duration (s) Query\n"; + my $idx = 1; + foreach my $k (sort {$normalyzed_info{$b}{duration} <=> $normalyzed_info{$a}{duration}} keys %normalyzed_info) { + next if (!$normalyzed_info{$k}{count}); + last if ($idx > $top); + my $q = $k; + if ($normalyzed_info{$k}{count} == 1) { + foreach (keys %{$normalyzed_info{$k}{samples}}) { + $q = $normalyzed_info{$k}{samples}{$_}{query}; + last; + } } + $normalyzed_info{$k}{average} = $normalyzed_info{$k}{duration}/$normalyzed_info{$k}{count}; + print $fh "$idx) " . &convert_time($normalyzed_info{$k}{duration}) . " - " . &comma_numbers($normalyzed_info{$k}{count}) . " - " . &convert_time($normalyzed_info{$k}{average}) . " - $q\n"; + print $fh "--\n"; + my $i = 1; + foreach my $d (sort {$b <=> $a} keys %{$normalyzed_info{$k}{samples}}) { + print $fh "\t- Example $i: ", &convert_time($d), " - ", $normalyzed_info{$k}{samples}{$d}{query}, "\n"; + $i++; + } + $idx++; } - $normalyzed_info{$k}{average} = $normalyzed_info{$k}{duration}/$normalyzed_info{$k}{count}; - print $fh "$idx) " . &convert_time($normalyzed_info{$k}{duration}) . " - " . &comma_numbers($normalyzed_info{$k}{count}) . " - " . &convert_time($normalyzed_info{$k}{average}) . " - $q\n"; - print $fh "--\n"; - my $i = 1; - foreach my $d (sort {$b <=> $a} keys %{$normalyzed_info{$k}{samples}}) { - print $fh "\t- Example $i: ", &convert_time($d), " - ", $normalyzed_info{$k}{samples}{$d}{query}, "\n"; - $i++; - } - $idx++; - } - print $fh "\n- Most frequent queries (N) --------------------------------------------\n\n"; - print $fh "Rank Times executed Total duration Av. duration (s) Query\n"; - $idx = 1; - foreach my $k (sort {$normalyzed_info{$b}{count} <=> $normalyzed_info{$a}{count}} keys %normalyzed_info) { - next if (!$normalyzed_info{$k}{count}); - last if ($idx > $top); - my $q = $k; - if ($normalyzed_info{$k}{count} == 1) { - foreach (keys %{$normalyzed_info{$k}{samples}}) { - $q = $normalyzed_info{$k}{samples}{$_}{query}; - last; + print $fh "\n- Most frequent queries (N) --------------------------------------------\n\n"; + print $fh "Rank Times executed Total duration Av. duration (s) Query\n"; + $idx = 1; + foreach my $k (sort {$normalyzed_info{$b}{count} <=> $normalyzed_info{$a}{count}} keys %normalyzed_info) { + next if (!$normalyzed_info{$k}{count}); + last if ($idx > $top); + my $q = $k; + if ($normalyzed_info{$k}{count} == 1) { + foreach (keys %{$normalyzed_info{$k}{samples}}) { + $q = $normalyzed_info{$k}{samples}{$_}{query}; + last; + } } + print $fh "$idx) " . &comma_numbers($normalyzed_info{$k}{count}) . " - " . &convert_time($normalyzed_info{$k}{duration}) . " - " . &convert_time($normalyzed_info{$k}{duration}/$normalyzed_info{$k}{count}) . " - $q\n"; + print $fh "--\n"; + my $i = 1; + foreach my $d (sort {$b <=> $a} keys %{$normalyzed_info{$k}{samples}}) { + print $fh "\tExample $i: ", &convert_time($d), " - ", $normalyzed_info{$k}{samples}{$d}{query}, "\n"; + $i++; + } + $idx++; } - print $fh "$idx) " . &comma_numbers($normalyzed_info{$k}{count}) . " - " . &convert_time($normalyzed_info{$k}{duration}) . " - " . &convert_time($normalyzed_info{$k}{duration}/$normalyzed_info{$k}{count}) . " - $q\n"; - print $fh "--\n"; - my $i = 1; - foreach my $d (sort {$b <=> $a} keys %{$normalyzed_info{$k}{samples}}) { - print $fh "\tExample $i: ", &convert_time($d), " - ", $normalyzed_info{$k}{samples}{$d}{query}, "\n"; - $i++; - } - $idx++; - } - print $fh "\n- Slowest queries (N) --------------------------------------------------\n\n"; - print $fh "Rank Av. duration (s) Times executed Total duration Query\n"; - $idx = 1; - foreach my $k (sort {$normalyzed_info{$b}{average} <=> $normalyzed_info{$a}{average}} keys %normalyzed_info) { - next if (!$normalyzed_info{$k}{count}); - last if ($idx > $top); - my $q = $k; - if ($normalyzed_info{$k}{count} == 1) { - foreach (keys %{$normalyzed_info{$k}{samples}}) { - $q = $normalyzed_info{$k}{samples}{$_}{query}; - last; + print $fh "\n- Slowest queries (N) --------------------------------------------------\n\n"; + print $fh "Rank Av. duration (s) Times executed Total duration Query\n"; + $idx = 1; + foreach my $k (sort {$normalyzed_info{$b}{average} <=> $normalyzed_info{$a}{average}} keys %normalyzed_info) { + next if (!$normalyzed_info{$k}{count}); + last if ($idx > $top); + my $q = $k; + if ($normalyzed_info{$k}{count} == 1) { + foreach (keys %{$normalyzed_info{$k}{samples}}) { + $q = $normalyzed_info{$k}{samples}{$_}{query}; + last; + } } + print $fh "$idx) " . &convert_time($normalyzed_info{$k}{average}) . " - " . &comma_numbers($normalyzed_info{$k}{count}) . " - " . &convert_time($normalyzed_info{$k}{duration}) . " - $q\n"; + print $fh "--\n"; + my $i = 1; + foreach my $d (sort {$b <=> $a} keys %{$normalyzed_info{$k}{samples}}) { + print $fh "\tExample $i: ", &convert_time($d), " - ", $normalyzed_info{$k}{samples}{$d}{query}, "\n"; + $i++; + } + $idx++; } - print $fh "$idx) " . &convert_time($normalyzed_info{$k}{average}) . " - " . &comma_numbers($normalyzed_info{$k}{count}) . " - " . &convert_time($normalyzed_info{$k}{duration}) . " - $q\n"; - print $fh "--\n"; - my $i = 1; - foreach my $d (sort {$b <=> $a} keys %{$normalyzed_info{$k}{samples}}) { - print $fh "\tExample $i: ", &convert_time($d), " - ", $normalyzed_info{$k}{samples}{$d}{query}, "\n"; - $i++; - } - $idx++; } if (!$disable_error) { print $fh "\n- Most frequent errors (N) ---------------------------------------------\n\n"; print $fh "Rank Times reported Error\n"; - $idx = 1; + my $idx = 1; foreach my $k (sort {$error_info{$b}{count} <=> $error_info{$a}{count}} keys %error_info) { next if (!$error_info{$k}{count}); last if ($idx > $top); @@ -1217,26 +1227,24 @@ EOF if (!$error_only) { print $fh qq{