Skip to content

Commit

Permalink
removed Mojolicious::Plugin::RequestTimer
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 7, 2013
1 parent b87ec42 commit de6955d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 98 deletions.
5 changes: 4 additions & 1 deletion Changes
Expand Up @@ -3,7 +3,8 @@
- Code name "Top Hat", this is a major release.
- Added is_empty method to Mojo::Transaction::HTTP.
- Added close_gracefully method to Mojo::IOLoop::Stream.
- Removed Mojolicious::Plugin::PoweredBy.
- Removed Mojolicious::Plugin::PoweredBy and
Mojolicious::Plugin::RequestTimer.
- Removed data attribute from Mojo::URL.
- Removed deprecated end method from Mojo::IOLoop::Delay.
- Removed deprecated build_form_tx, build_json_tx, post_form and post_json
Expand All @@ -19,6 +20,8 @@
from 0.5 to 1 second.
- Improved Mojo::DOM::HTML performance.
- Improved html_unescape performance in Mojo::Util.
- Improved Mojolicious::Plugin::EPLRenderer to cache templates more
efficiently.
- Improved documentation.
- Improved tests.
- Fixed Perl 5.17.11+ compatibility.
Expand Down
16 changes: 14 additions & 2 deletions lib/Mojolicious.pm
Expand Up @@ -14,6 +14,7 @@ use Mojolicious::Sessions;
use Mojolicious::Static;
use Mojolicious::Types;
use Scalar::Util qw(blessed weaken);
use Time::HiRes 'gettimeofday';

has commands => sub {
my $commands = Mojolicious::Commands->new(app => shift);
Expand Down Expand Up @@ -79,8 +80,8 @@ sub new {
$self->log->path($home->rel_file("log/$mode.log"))
if -w $home->rel_file('log');

$self->plugin($_) for qw(HeaderCondition DefaultHelpers TagHelpers);
$self->plugin($_) for qw(EPLRenderer EPRenderer RequestTimer);
$self->plugin($_)
for qw(HeaderCondition DefaultHelpers TagHelpers EPLRenderer EPRenderer);

# Exception handling should be first in chain
$self->hook(around_dispatch => \&_exception);
Expand Down Expand Up @@ -117,6 +118,17 @@ sub dispatch {
$self->static->dispatch($c) and $plugins->emit_hook(after_static => $c)
unless $tx->res->code;

# Start timer (ignore static files)
my $stash = $c->stash;
unless ($stash->{'mojo.static'} || $stash->{'mojo.started'}) {
my $req = $c->req;
my $method = $req->method;
my $path = $req->url->path->to_abs_string;
my $ua = $req->headers->user_agent || 'Anonymojo';
$self->log->debug("$method $path ($ua).");
$stash->{'mojo.started'} = [gettimeofday];
}

# Routes
$plugins->emit_hook(before_routes => $c);
my $res = $tx->res;
Expand Down
18 changes: 16 additions & 2 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -12,6 +12,7 @@ use Mojo::Util;
use Mojolicious;
use Mojolicious::Routes::Match;
use Scalar::Util ();
use Time::HiRes ();

has app => sub { Mojolicious->new };
has match => sub {
Expand Down Expand Up @@ -262,8 +263,21 @@ sub rendered {
$res->code($status || 200) if $status || !$res->code;

# Finish transaction
unless ($self->stash->{'mojo.finished'}++) {
my $app = $self->app;
my $stash = $self->stash;
unless ($stash->{'mojo.finished'}++) {

# Stop timer (ignore static files)
my $app = $self->app;
my $started = delete $stash->{'mojo.started'};
if (!$stash->{'mojo.static'} && $started) {
my $elapsed = sprintf '%f',
Time::HiRes::tv_interval($started, [Time::HiRes::gettimeofday()]);
my $rps = $elapsed == 0 ? '??' : sprintf '%.3f', 1 / $elapsed;
my $code = $res->code;
my $msg = $res->message || $res->default_message($code);
$app->log->debug("$code $msg (${elapsed}s, $rps/s).");
}

$app->plugins->emit_hook_reverse(after_dispatch => $self);
$app->sessions->store($self);
}
Expand Down
21 changes: 9 additions & 12 deletions lib/Mojolicious/Plugin/EPLRenderer.pm
Expand Up @@ -16,11 +16,13 @@ sub _epl {
return undef unless defined $path;

# Cached
my $cache = $renderer->cache;
my $key = delete $options->{cache} || $path;
my $mt = $cache->get($key) || Mojo::Template->new;
my $cache = $renderer->cache;
my $mt = $cache->get($key);
$mt ||= $cache->set($key => Mojo::Template->new)->get($key);
my $log = $c->app->log;
if ($mt->compiled) {
$c->app->log->debug("Rendering cached @{[$mt->name]}.");
$log->debug("Rendering cached @{[$mt->name]}.");
$$output = $mt->interpret($c);
}

Expand All @@ -29,7 +31,7 @@ sub _epl {

# Inline
if (defined $inline) {
$c->app->log->debug('Rendering inline template.');
$log->debug('Rendering inline template.');
$$output = $mt->name('inline template')->render($inline, $c);
}

Expand All @@ -40,24 +42,19 @@ sub _epl {

# Try template
if (-r $path) {
$c->app->log->debug(qq{Rendering template "$t".});
$log->debug(qq{Rendering template "$t".});
$$output = $mt->name("template $t")->render_file($path, $c);
}

# Try DATA section
elsif (my $d = $renderer->get_data_template($options)) {
$c->app->log->debug(qq{Rendering template "$t" from DATA section.});
$log->debug(qq{Rendering template "$t" from DATA section.});
$$output = $mt->name("template $t from DATA section")->render($d, $c);
}

# No template
else {
$c->app->log->debug(qq{Template "$t" not found.}) and return undef;
}
else { $log->debug(qq{Template "$t" not found.}) and return undef }
}

# Cache
$cache->set($key => $mt);
}

# Exception or success
Expand Down
81 changes: 0 additions & 81 deletions lib/Mojolicious/Plugin/RequestTimer.pm

This file was deleted.

0 comments on commit de6955d

Please sign in to comment.