}
}
+use MojoFacets::Plugin::NYTProf;
# This method will run once at server start
sub startup {
save_tx( $self, $tx );
}
);
+
+ MojoFacets::Plugin::NYTProf->register( $self );
}
sub index {
my $self = shift;
- foreach my $name ( qw( MASTER MAX_FACETS ) ) {
- if ( my $val = $self->param($name) ) {
+ my @config = (qw(
+ MASTER
+ MAX_FACETS
+ PROFILE
+ ));
+
+ foreach my $name ( @config ) {
+ my $val = $self->param($name);
+ if ( defined $val ) {
$ENV{$name} = $val;
warn "$name = $val\n";
}
}
- $self->render;
+ $self->render(
+ config => \@config,
+ );
}
1;
--- /dev/null
+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) = @_;
+ return unless $ENV{PROFILE};
+ my $id = Time::HiRes::gettimeofday();
+ $c->stash('nytprof.id' => $id);
+ my $path = "/tmp/nytprof.$id";
+ DB::enable_profile($path);
+ }
+ );
+
+ # End timer
+ $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 $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;
+ }
+ }
+ );
+}
+
+1;
<ul>
-<h2>Replication</h2>
-<li>MASTER
-<input type=text name=MASTER value="<%= $ENV{MASTER} %>">
+% foreach my $name ( @$config ) {
-<h2>Facet display</h2>
-<li>MAX_FACETS
-<input type=text name=MAX_FACETS value="<%= $ENV{MAX_FACETS} %>">
+<li>
+<label>
+<%= $name %>
+<input type=text name=<%= $name %> value="<%= $ENV{$name} %>">
+</label>
+</li>
+
+% }
</ul>