From 6e4ffa2f9e68200d60499d7b72f92d20d573c2b0 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 26 Jun 2010 23:15:53 +0200 Subject: [PATCH 1/1] profile using Devel::NYTProf --- lib/MojoFacets/Plugin/NYTProf.pm | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/MojoFacets/Plugin/NYTProf.pm diff --git a/lib/MojoFacets/Plugin/NYTProf.pm b/lib/MojoFacets/Plugin/NYTProf.pm new file mode 100644 index 0000000..37a1bf2 --- /dev/null +++ b/lib/MojoFacets/Plugin/NYTProf.pm @@ -0,0 +1,33 @@ +package MojoFacets::Plugin::NYTProf; + +use Devel::NYTProf; +use Time::HiRes (); + +sub register { + my ($self, $app) = @_; + + # Start timer + $app->plugins->add_hook( + before_dispatch => sub { + my ($self, $c) = @_; + my $id = Time::HiRes::gettimeofday(); + $c->stash('nytprof.id' => $id); + my $path = "/tmp/nytprof.$id"; + DB::enable_profile($path); + warn "profile $path started\n"; + } + ); + + # End timer + $app->plugins->add_hook( + after_dispatch => sub { + my ($self, $c) = @_; + DB::disable_profile(); + return unless my $id = $c->stash('nytprof.id'); + my $path = "/tmp/nytprof.$id"; + warn "profile $path ", -s $profile, " bytes\n"; + } + ); +} + +1; -- 2.20.1