From ffc52e24295aa32fb40bd39871ef3378e93f591b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 26 Jun 2010 23:38:38 +0200 Subject: [PATCH] use PROFILE to specify minimum duration This allows us to ignore short timed requests, and focus just on long running ones --- lib/MojoFacets/Plugin/NYTProf.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/MojoFacets/Plugin/NYTProf.pm b/lib/MojoFacets/Plugin/NYTProf.pm index 37a1bf2..7604a19 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,17 @@ 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"; + warn "profile $path $duration ", -s $path, " bytes\n"; + } else { + warn "profile $path $duration < $p unlink\n"; + unlink $path; + } } ); } -- 2.20.1