1 package MojoFacets::Plugin::NYTProf;
10 $app->plugins->add_hook(
11 before_dispatch => sub {
13 return unless $ENV{PROFILE};
14 my $id = Time::HiRes::gettimeofday();
15 $c->stash('nytprof.id' => $id);
16 my $path = "/tmp/nytprof.$id";
17 DB::enable_profile($path);
22 $app->plugins->add_hook(
23 after_dispatch => sub {
25 my $p = $ENV{PROFILE} || return;
26 DB::disable_profile();
27 return unless my $id = $c->stash('nytprof.id');
28 my $duration = Time::HiRes::gettimeofday() - $id;
29 if ( $duration > $p ) {
30 my $path = "/tmp/nytprof.$id";
31 my $new = "/tmp/MojoFacets.profile-$id-$duration";
33 warn "profile $new $duration ", -s $new, " bytes\n";
35 warn "profile $path $duration < $p unlink\n";