From: Darold Gilles Date: Sat, 27 Apr 2013 09:18:35 +0000 (+0200) Subject: Add samples queries to Most frequent waiting queries report. X-Git-Tag: v3.3~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=702552e9d1e798e7cfd8045711541230145a4d05;p=pgbadger Add samples queries to Most frequent waiting queries report. --- diff --git a/pgbadger b/pgbadger index abe6add..1ec4be2 100755 --- a/pgbadger +++ b/pgbadger @@ -1863,6 +1863,61 @@ Report not supported by text format } } + # Show lock wait detailed informations + if (!$disable_lock && scalar keys %lock_info > 0) { + + my @top_locked_queries; + foreach my $h (keys %normalyzed_info) { + if (exists($normalyzed_info{$h}{locks})) { + push (@top_locked_queries, [$h, $normalyzed_info{$h}{locks}{count}, $normalyzed_info{$h}{locks}{wait}, + $normalyzed_info{$h}{locks}{minwait}, $normalyzed_info{$h}{locks}{maxwait}]); + } + } + + # Most frequent waiting queries (N) + @top_locked_queries = sort {$b->[2] <=> $a->[2]} @top_locked_queries; + print $fh "\n- Most frequent waiting queries (N) -----------------------------------------\n\n"; + print $fh "Rank Count Total wait time (s) Min/Max/Avg duration (s) Query\n"; + for (my $i = 0 ; $i <= $#top_locked_queries ; $i++) { + last if ($i > $end_top); + print $fh ($i + 1), ") ", $top_locked_queries[$i]->[1], " - ", &convert_time($top_locked_queries[$i]->[2]), + " - ", &convert_time($top_locked_queries[$i]->[3]), "/", &convert_time($top_locked_queries[$i]->[4]), "/", + &convert_time(($top_locked_queries[$i]->[4] / $top_locked_queries[$i]->[1])), + " - ", $top_locked_queries[$i]->[0], "\n"; + print $fh "--\n"; + my $k = $top_locked_queries[$i]->[0]; + my $j = 1; + foreach my $d (sort {$b <=> $a} keys %{$normalyzed_info{$k}{samples}}) { + my $db = " - database: $normalyzed_info{$k}{samples}{$d}{db}" if ($normalyzed_info{$k}{samples}{$d}{db}); + $db .= ", user: $normalyzed_info{$k}{samples}{$d}{user}" if ($normalyzed_info{$k}{samples}{$d}{user}); + $db .= ", remote: $normalyzed_info{$k}{samples}{$d}{remote}" if ($normalyzed_info{$k}{samples}{$d}{remote}); + $db .= ", app: $normalyzed_info{$k}{samples}{$d}{app}" if ($normalyzed_info{$k}{samples}{$d}{app}); + $db =~ s/^, / - /; + print $fh "\t- Example $j: ", &convert_time($d), "$db - ", $normalyzed_info{$k}{samples}{$d}{query}, "\n"; + $j++; + } + } + print $fh "\n"; + @top_locked_queries = (); + + # Queries that waited the most + @top_locked_info = sort {$b->[1] <=> $a->[1]} @top_locked_info; + print $fh "\n- Queries that waited the mosts ---------------------------------------------\n\n"; + print $fh "Rank Wait time (s) Query\n"; + for (my $i = 0 ; $i <= $#top_locked_info ; $i++) { + my $ttl = $top_locked_info[$i]->[1] || ''; + my $db = " - database: $top_locked_info[$i]->[3]" if ($top_locked_info[$i]->[3]); + $db .= ", user: $top_locked_info[$i]->[4]" if ($top_locked_info[$i]->[4]); + $db .= ", remote: $top_locked_info[$i]->[5]" if ($top_locked_info[$i]->[5]); + $db .= ", app: $top_locked_info[$i]->[6]" if ($top_locked_info[$i]->[6]); + $db =~ s/^, / - /; + print $fh ($i + 1), ") ", &convert_time($top_locked_info[$i]->[0]), + " $ttl$db - ", $top_locked_info[$i]->[2], "\n"; + print $fh "--\n"; + } + print $fh "\n"; + } + # Show top information if (!$disable_query && ($#top_slowest >= 0)) { print $fh "\n- Slowest queries ------------------------------------------------------\n\n"; @@ -3752,6 +3807,7 @@ sub dump_as_html Query }; + my $idx = 1; for (my $i = 0 ; $i <= $#top_locked_queries ; $i++) { last if ($i > $end_top); my $col = $i % 2; @@ -3760,7 +3816,28 @@ sub dump_as_html "", &convert_time($top_locked_queries[$i]->[3]), "/", &convert_time($top_locked_queries[$i]->[4]), "/", &convert_time(($top_locked_queries[$i]->[4] / $top_locked_queries[$i]->[1])), "
", - &highlight_code($top_locked_queries[$i]->[0]), "
\n"; + &highlight_code($top_locked_queries[$i]->[0]), "\n"; + my $k = $top_locked_queries[$i]->[0]; + if ($normalyzed_info{$k}{count} > 1) { + print $fh +"
"; + my $j = 0; + foreach my $d (sort {$b <=> $a} keys %{$normalyzed_info{$k}{samples}}) { + my $colb = $j % 2; + my $db = " - database: $normalyzed_info{$k}{samples}{$d}{db}" if ($normalyzed_info{$k}{samples}{$d}{db}); + $db .= ", user: $normalyzed_info{$k}{samples}{$d}{user}" if ($normalyzed_info{$k}{samples}{$d}{user}); + $db .= ", remote: $normalyzed_info{$k}{samples}{$d}{remote}" if ($normalyzed_info{$k}{samples}{$d}{remote}); + $db .= ", app: $normalyzed_info{$k}{samples}{$d}{app}" if ($normalyzed_info{$k}{samples}{$d}{app}); + $db =~ s/^, / - /; + print $fh +"
", + &convert_time($d), " | ", &highlight_code($normalyzed_info{$k}{samples}{$d}{query}), "
"; + $j++; + } + print $fh "
"; + } + print $fh "\n"; + $idx++; } print $fh "\n"; @top_locked_queries = ();