Author: timbo
Date: Wed Nov 21 04:29:07 2007
New Revision: 10287

Modified:
   dbi/trunk/Changes
   dbi/trunk/lib/DBI/Gofer/Execute.pm

Log:
Gofer: track_recent now also keeps track of N most recent errors.
Gofer: The connect method is now also counted in stats.


Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes   (original)
+++ dbi/trunk/Changes   Wed Nov 21 04:29:07 2007
@@ -48,6 +48,10 @@
   Improvements to t/80proxy.t test script.
   Improvements to t/85gofer.t test script thanks to Stig.
 
+  Gofer changes:
+    track_recent now also keeps track of N most recent errors.
+    The connect method is now also counted in stats.
+
 =head2 Changes in DBI 1.601 (svn rev 10103),  21st October 2007
 
   Fixed t/05thrclone.t to work with Test::More >= 0.71

Modified: dbi/trunk/lib/DBI/Gofer/Execute.pm
==============================================================================
--- dbi/trunk/lib/DBI/Gofer/Execute.pm  (original)
+++ dbi/trunk/lib/DBI/Gofer/Execute.pm  Wed Nov 21 04:29:07 2007
@@ -158,6 +158,7 @@
 
     my ($connect_method, $dsn, $username, $password, $attr) = @{ 
$request->dbh_connect_call };
     $connect_method ||= 'connect_cached';
+    $stats->{method_calls_dbh}->{$connect_method}++;
 
     # delete attributes we don't want to affect the server-side
     # (Could just do this on client-side and trust the client. DoS?)
@@ -641,17 +642,22 @@
         if length($frozen_request)  > ($stats->{frozen_request_max_bytes}||0);
     $stats->{frozen_response_max_bytes} = length($frozen_response)
         if length($frozen_response) > ($stats->{frozen_response_max_bytes}||0);
+
     my $recent;
     if (my $track_recent = $self->{track_recent}) {
-        my $recent_requests = $stats->{recent_requests} ||= [];
-        push @$recent_requests, $recent = {
+        $recent = {
             request  => $frozen_request,
             response => $frozen_response,
             time_received => $time_received,
             duration => dbi_time()-$time_received,
-           ($meta) ? (meta => $meta) : (), # for any other info
+            ($meta) ? (meta => $meta) : (), # for any other info
         };
-        shift @$recent_requests if @$recent_requests > $track_recent;
+        my @queues =  ($stats->{recent_requests} ||= []);
+        push @queues, ($stats->{recent_errors}   ||= []) if $response->err;
+        for my $queue (@queues) {
+            push @$queue, $recent;
+            shift @$queue if @$queue > $track_recent;
+        }
     }
     return $recent;
 }

Reply via email to