[Jifty-commit] r4673 - in jifty/trunk: lib/Jifty/Plugin
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Dec 13 04:34:40 EST 2007
Author: sartak
Date: Thu Dec 13 04:34:39 2007
New Revision: 4673
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Plugin/Recorder.pm
Log:
r49017 at onn: sartak | 2007-12-13 04:34:16 -0500
Recorder: log how much memory we're using at each request if memory_usage is set.
Modified: jifty/trunk/lib/Jifty/Plugin/Recorder.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Recorder.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Recorder.pm Thu Dec 13 04:34:39 2007
@@ -2,7 +2,7 @@
use strict;
use warnings;
use base qw/Jifty::Plugin Class::Data::Inheritable/;
-__PACKAGE__->mk_accessors(qw/start path loghandle print_current_user/);
+__PACKAGE__->mk_accessors(qw/start path loghandle logged_request memory_usage/);
use Time::HiRes 'time';
use Jifty::Util;
@@ -21,12 +21,19 @@
my $self = shift;
my %args = (
path => 'log/requests',
+ memory_usage => 0,
@_,
);
return if $self->_pre_init;
$self->start(time);
+
+ $self->memory_usage($args{memory_usage});
+ if ($args{memory_usage}) {
+ require Proc::ProcessTable;
+ }
+
$self->path(Jifty::Util->absolute_path( $args{path} ));
Jifty::Util->make_path($self->path);
@@ -51,7 +58,7 @@
my $handler = shift;
my $cgi = shift;
- $self->print_current_user(0);
+ $self->logged_request(0);
eval {
my $delta = time - $self->start;
@@ -59,7 +66,7 @@
my $yaml = Jifty::YAML::Dump($request);
print { $self->get_loghandle } $yaml;
- $self->print_current_user(1);
+ $self->logged_request(1);
};
Jifty->log->error("Unable to append to request log: $@") if $@;
@@ -74,7 +81,7 @@
This, strictly speaking, isn't necessary. But we don't always want to lug the
sessions table around, so this gets us most of the way there.
-C<print_current_user> is checked to ensure that we don't append the current
+C<logged_request> is checked to ensure that we don't append the current
user if the current request couldn't be logged for whatever reason (perhaps
a serialization error?).
@@ -83,9 +90,23 @@
sub before_cleanup {
my $self = shift;
- if ($self->print_current_user) {
+ if ($self->logged_request) {
eval {
print { $self->get_loghandle } "current_user: " . (Jifty->web->current_user->id || 0) . "\n";
+
+ # get memory usage. yes, we really do need to go through these
+ # motions every request :(
+ if ($self->memory_usage) {
+ my $proc = Proc::ProcessTable->new;
+ for (@{ $proc->table }) {
+ next unless $_->pid == $$;
+
+ print { $self->get_loghandle } "memory: " . ($_->size||'?') . "\n";
+ return;
+ }
+
+ Jifty->log->error("Unable to find myself, pid $$, in Proc::ProcessTable.");
+ }
};
}
}
@@ -147,6 +168,11 @@
The path for creating request logs. Default: log/requests. This directory will
be created for you, if necessary.
+=item memory_usage
+
+Report how much memory (in bytes) Jifty is taking up. This uses
+L<Proc::ProcessTable>. Default is off.
+
=back
=head1 SEE ALSO
More information about the Jifty-commit
mailing list