[Jifty-commit] r4651 - in jifty/trunk: lib/Jifty/Plugin lib/Jifty/Plugin/SQLQueries

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Dec 7 22:55:17 EST 2007


Author: sartak
Date: Fri Dec  7 22:55:17 2007
New Revision: 4651

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Plugin/SQLQueries.pm
   jifty/trunk/lib/Jifty/Plugin/SQLQueries/View.pm

Log:
 r48788 at onn:  sartak | 2007-12-07 22:55:01 -0500
 SQLQueries: keep track of the ten slowest queries and display them. The query page could use a bit of visual design. :)


Modified: jifty/trunk/lib/Jifty/Plugin/SQLQueries.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/SQLQueries.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/SQLQueries.pm	Fri Dec  7 22:55:17 2007
@@ -5,6 +5,7 @@
 use warnings;
 
 our @requests;
+our @slow_queries;
 
 =head1 NAME
 
@@ -110,6 +111,13 @@
                             $statement,
                             join ', ', @$bindings);
         $total_time += $duration;
+
+        # keep track of the ten slowest queries so far
+        if ($duration > $slow_queries[0][3]) {
+            push @slow_queries, $_;
+            @slow_queries = sort { $a->[3] <=> $b->[3] } @slow_queries;
+            shift @slow_queries if @slow_queries > 9;
+        }
     }
 
     push @requests, {

Modified: jifty/trunk/lib/Jifty/Plugin/SQLQueries/View.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/SQLQueries/View.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/SQLQueries/View.pm	Fri Dec  7 22:55:17 2007
@@ -33,6 +33,26 @@
             }
             hr {}
 
+            h3 { "Slowest queries" };
+            table {
+                row {
+                    th { "Time taken" };
+                    th { "Query" };
+                };
+
+                for (reverse @Jifty::Plugin::SQLQueries::slow_queries)
+                {
+                    my ($time, $statement, $bindings, $duration, $misc) = @$_;
+                    row {
+                        cell { $duration };
+                        cell { $statement };
+                    };
+                }
+            };
+
+            hr {};
+
+            h3 { "All queries" };
             table {
                 row {
                     th { "ID" }
@@ -76,26 +96,32 @@
                     "Table of Contents" } };
 
             for ( @{ $query->{queries} } ) {
-                my ($time, $statement, $bindings, $duration, $misc) = @$_;
                 hr {};
-                h4 { pre { $statement } };
-                ul {
-                    li { "At: " . gmtime($time) };
-                    li { "Time taken: $duration" };
-                }
-                h5 { "Bindings:" }
-                ol {
-                    li { $_ } for @$bindings;
-                }
-                h5 { "Stack trace:" }
-                pre {
-                    $misc->{SQLQueryPlugin};
-                }
+                set query => $_;
+                show '/__jifty/admin/queries/query';
             }
         }
     }
 };
 
+template '/__jifty/admin/queries/query' => sub {
+    my ($time, $statement, $bindings, $duration, $misc) = @{ get 'query' };
+
+    h4 { pre { $statement } };
+    ul {
+        li { "At: " . gmtime($time) };
+        li { "Time taken: $duration" };
+    }
+    h5 { "Bindings:" }
+    ol {
+        li { $_ } for @$bindings;
+    }
+    h5 { "Stack trace:" }
+    pre {
+        $misc->{SQLQueryPlugin};
+    }
+};
+
 =head1 SEE ALSO
 
 L<Jifty::Plugin::SQLQueries>, L<Jifty::Plugin::SQLQueries::Dispatcher>


More information about the Jifty-commit mailing list