[Jifty-commit] r6828 - in plugins/Jifty-Plugin-Gladiator/lib/Jifty/Plugin: .

Jifty commits jifty-commit at lists.jifty.org
Wed Apr 22 05:12:38 EDT 2009


Author: sartak
Date: Wed Apr 22 05:12:38 2009
New Revision: 6828

Removed:
   plugins/Jifty-Plugin-Gladiator/lib/Jifty/Plugin/Gladiator/Dispatcher.pm
   plugins/Jifty-Plugin-Gladiator/lib/Jifty/Plugin/Gladiator/View.pm
Modified:
   plugins/Jifty-Plugin-Gladiator/lib/Jifty/Plugin/Gladiator.pm

Log:
Reimplementation using RequestInspector

Modified: plugins/Jifty-Plugin-Gladiator/lib/Jifty/Plugin/Gladiator.pm
==============================================================================
--- plugins/Jifty-Plugin-Gladiator/lib/Jifty/Plugin/Gladiator.pm	(original)
+++ plugins/Jifty-Plugin-Gladiator/lib/Jifty/Plugin/Gladiator.pm	Wed Apr 22 05:12:38 2009
@@ -1,86 +1,40 @@
 package Jifty::Plugin::Gladiator;
 use strict;
 use warnings;
-use base qw/Jifty::Plugin Class::Data::Inheritable/;
-__PACKAGE__->mk_accessors(qw/prev_data/);
-
+use base 'Jifty::Plugin';
 use Devel::Gladiator;
-use List::Util 'reduce';
-
-our @requests;
+use Template::Declare::Tags;
 
 our $VERSION = 0.01;
 
-
-=head1 NAME
-
-Jifty::Plugin::Gladiator - Walk the areas, looking for leaked objects
-
-=head1 DESCRIPTION
-
-This plugin will attempt to output diffs between the current contents
-of memory after each request, in order to track leaks.
-
-=head1 USAGE
-
-Add the following to your site_config.yml
-
- framework:
-   Plugins:
-     - Gladiator: {}
-
-=head1 METHODS
-
-=head2 init
-
-init installs the trigger needed before each HTTP request. It also establishes
-the baseline for all times and creates the log path.
-
-=cut
-
-sub init {
-    my $self = shift;
-    my %args = (
-        @_,
-    );
-
-    return if $self->_pre_init;
-
-    Jifty::Handler->add_trigger(
-        after_request => sub { $self->after_request(@_) }
-    );
-}
-
-=head2 after_request
-
-=cut
-
-sub after_request {
-    my $self    = shift;
-    my $handler = shift;
-    my $cgi     = shift;
-
+sub count_types {
     # walk the arena, noting the type of each value
     my %types;
     for (@{ Devel::Gladiator::walk_arena() }) {
         ++$types{ ref $_ };
     }
 
-    # basic stats
-    my $all_values = reduce { $a + $b } values %types;
-    my $all_types  = keys %types;
+    return \%types;
+}
+
+sub inspect_before_request {
+    my $self = shift;
+    return $self->count_types;
+}
+
+sub inspect_after_request {
+    my $self = shift;
+    my $starting_arena = shift;
+    my $current_arena = $self->count_types;
+
     my $new_values = 0;
     my $new_types  = 0;
 
-    my %prev = %{ $self->prev_data || {} };
-
-    # copy so when we modify %types it doesn't affect prev_data
-    my %new_prev = %types;
-    $self->prev_data(\%new_prev);
+    my %types;
 
     # find the difference
-    for my $type (keys %types) {
-        my $diff = $types{$type} - ($prev{$type} || 0);
+    for my $type (keys %$current_arena) {
+        my $diff = $current_arena->{$type} - $starting_arena->{$type};
 
         if ($diff != 0) {
             $new_values += $diff;
@@ -88,36 +42,67 @@
         }
 
         $types{$type} = {
-            all => $types{$type},
+            all => $current_arena->{$type},
             new => $diff,
         }
     }
 
-    push @requests, {
-        id         => 1 + @requests,
-        url        => $cgi->url(-absolute=>1,-path_info=>1),
-        time       => scalar gmtime,
-
-        all_values => $all_values,
-        all_types  => $all_types,
+    return {
         new_values => $new_values,
         new_types  => $new_types,
-        diff       => \%types,
+        types      => \%types,
     };
 }
 
+sub inspect_render_summary {
+    my $self   = shift;
+    my $growth = shift;
+
+    return "$growth->{new_values} new values in $growth->{new_types} types";
+}
+
+sub inspect_render_analysis {
+    my $self   = shift;
+    my $growth = shift;
+    my $types  = $growth->{types};
+
+    ol {
+        for my $type (sort { $types->{$b} <=> $types->{$a} } keys %$types) {
+            li { "$type ($types->{$type})" }
+        }
+    }
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Jifty::Plugin::Gladiator - Walk the areas, looking for leaked objects
+
+=head1 DESCRIPTION
+
+This plugin will attempt to output diffs between the current contents
+of memory after each request, in order to track leaks.
+
+=head1 USAGE
+
+Add the following to your site_config.yml
+
+ framework:
+   Plugins:
+     - Gladiator: {}
+
 =head1 SEE ALSO
 
 L<Jifty::Plugin::LeakTracker>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2007 Best Practical Solutions
+Copyright 2007-2009 Best Practical Solutions
 
 This is free software and may be modified and distributed under the same terms as Perl itself.
 
 =cut
 
-1;
-
-


More information about the Jifty-commit mailing list