X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FMojoFacets%2FPlugin%2FNYTProf.pm;h=4bc2f5a8079d575c4d2629d5e7d4b9b2fecbcfff;hb=4c26ead649e3118c016577279ed1fec491cca453;hp=37a1bf27111884a05e3cfcd7890f90f8e2c6f3dd;hpb=6e4ffa2f9e68200d60499d7b72f92d20d573c2b0;p=MojoFacets.git diff --git a/lib/MojoFacets/Plugin/NYTProf.pm b/lib/MojoFacets/Plugin/NYTProf.pm index 37a1bf2..4bc2f5a 100644 --- a/lib/MojoFacets/Plugin/NYTProf.pm +++ b/lib/MojoFacets/Plugin/NYTProf.pm @@ -10,11 +10,11 @@ sub register { $app->plugins->add_hook( before_dispatch => sub { my ($self, $c) = @_; + return unless $ENV{PROFILE}; my $id = Time::HiRes::gettimeofday(); $c->stash('nytprof.id' => $id); my $path = "/tmp/nytprof.$id"; DB::enable_profile($path); - warn "profile $path started\n"; } ); @@ -22,10 +22,19 @@ sub register { $app->plugins->add_hook( after_dispatch => sub { my ($self, $c) = @_; + my $p = $ENV{PROFILE} || return; DB::disable_profile(); return unless my $id = $c->stash('nytprof.id'); - my $path = "/tmp/nytprof.$id"; - warn "profile $path ", -s $profile, " bytes\n"; + my $duration = Time::HiRes::gettimeofday() - $id; + if ( $duration > $p ) { + my $path = "/tmp/nytprof.$id"; + my $new = "/tmp/MojoFacets.profile.$id-$duration"; + rename $path, $new; + warn "profile $new $duration ", -s $new, " bytes\n"; + } else { + warn "profile $path $duration < $p unlink\n"; + unlink $path; + } } ); }