[Jifty-commit] r6667 - in plugins/Jifty-Plugin-NYTProf: . doc lib lib/Jifty/Plugin t
Jifty commits
jifty-commit at lists.jifty.org
Wed Mar 18 16:26:08 EDT 2009
Author: alexmv
Date: Wed Mar 18 16:26:06 2009
New Revision: 6667
Added:
plugins/Jifty-Plugin-NYTProf/ (props changed)
plugins/Jifty-Plugin-NYTProf/Makefile.PL
plugins/Jifty-Plugin-NYTProf/doc/
plugins/Jifty-Plugin-NYTProf/lib/
plugins/Jifty-Plugin-NYTProf/lib/Jifty/
plugins/Jifty-Plugin-NYTProf/lib/Jifty/Plugin/
plugins/Jifty-Plugin-NYTProf/lib/Jifty/Plugin/NYTProf.pm
plugins/Jifty-Plugin-NYTProf/t/
Log:
NYTProf plugin
Added: plugins/Jifty-Plugin-NYTProf/Makefile.PL
==============================================================================
--- (empty file)
+++ plugins/Jifty-Plugin-NYTProf/Makefile.PL Wed Mar 18 16:26:06 2009
@@ -0,0 +1,8 @@
+use inc::Module::Install;
+name('Jifty-Plugin-NYTProf');
+version('0.01');
+requires('Jifty' => '0.90220');
+
+install_share;
+
+WriteAll;
Added: plugins/Jifty-Plugin-NYTProf/lib/Jifty/Plugin/NYTProf.pm
==============================================================================
--- (empty file)
+++ plugins/Jifty-Plugin-NYTProf/lib/Jifty/Plugin/NYTProf.pm Wed Mar 18 16:26:06 2009
@@ -0,0 +1,59 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::NYTProf;
+use base qw/Jifty::Plugin/;
+__PACKAGE__->mk_accessors(qw/first_request path/);
+
+sub init {
+ my $self = shift;
+
+ unless (%DB::sub) {
+ warn "Perl is not running in debug mode -- profiler disabled\n"
+ . "Run as `perl -d:NYTProf ./bin/jifty server` to profile startup\n"
+ . " or as `NYTPROF=start=no perl -d:NYTProf ./bin/jifty server` to profile runtime\n";
+ return;
+ }
+
+ my %args = (split /[:=]/, $ENV{NYTPROF} || '');
+ if ($args{start} and $args{start} eq "no") {
+ warn "Only profiling requests; unset NYTPROF environment variable to profile startup\n";
+ $self->path(Jifty::Util->absolute_path("var/profile"));
+ unless (-e $self->path or mkdir $self->path) {
+ warn "Can't create @{[$self->path]} for profiling: $!";
+ return;
+ }
+
+ $self->first_request(1);
+
+ Jifty::Handler->add_trigger(
+ before_request => sub { $self->before_request(@_) }
+ );
+
+ Jifty::Handler->add_trigger(
+ before_cleanup => sub { $self->before_cleanup }
+ );
+ } else {
+ warn "Only profiling startup time -- set NYTPROF=start=no to profile requests\n";
+ Jifty->add_trigger(
+ post_init => sub { DB::disable_profile() }
+ );
+ }
+}
+
+sub before_request {
+ my $self = shift;
+ return if $self->first_request;
+
+ DB::enable_profile($self->path . "/nytprof.$$.out")
+}
+
+sub before_cleanup {
+ my $self = shift;
+ DB::disable_profile()
+ unless $self->first_request;
+
+ $self->first_request(0);
+}
+
+1;
More information about the Jifty-commit
mailing list