Discussion:
[Mason-devel] Timing component execution
Pedro Melo
2012-05-24 15:28:50 UTC
Permalink
Hi,

I'm trying to time each Mason2 component execution to track some
deviation on run times. I've tried adding a My::App::Mason::Component
and override 'main', but main is the final method, it only exists on
generated code.

My next option is to override Mason::Compilation::_output_method but
that means copying a lot of code.

Before I start down this road, any other suggestions?

Thanks,
--
Pedro Melo
@pedromelo
http://www.simplicidade.org/
http://about.me/melo
xmpp:***@simplicidade.org
mailto:***@simplicidade.org
Pedro Melo
2012-05-24 15:49:25 UTC
Permalink
Hi,

sorry to respond to my own question, I've solved it, and though it my
be handy to others.

I used this package:

package My::App::Mason::Compilation;
use Poet qw($conf $env);
use Poet::Moose;

extends 'Mason::Compilation';

override 'output_class_header' => sub {
return join("\n", super(), 'use Time::HiRes ();');
};

override '_output_method' => sub {
my ($self, $method) = @_;
local $method->{init} = 'my $___t0 = [Time::HiRes::gettimeofday];
'.$method->{init};
local $method->{body} = 'print STDERR "HIT ".$self->cmeta->{path}."
".Time::HiRes::tv_interval($___t0)."\n";'.$method->{body};

super();
};

1;

Feel free to adjust the print STDERR to whatever you need it to be.

Bye,
Post by Pedro Melo
Hi,
I'm trying to time each Mason2 component execution to track some
deviation on run times. I've tried adding a My::App::Mason::Component
and override 'main', but main is the final method, it only exists on
generated code.
My next option is to override Mason::Compilation::_output_method but
that means copying a lot of code.
Before I start down this road, any other suggestions?
--
Pedro Melo
@pedromelo
http://www.simplicidade.org/
http://about.me/melo
xmpp:***@simplicidade.org
mailto:***@simplicidade.org
Jonathan Swartz
2012-05-24 17:02:58 UTC
Permalink
Thanks Pedro. The fact that 'main' is difficult to override (because it's final) has come up as a problem before, so I'm thinking we need an intermediate method that can be more easily overriden. I'll take a look at this.

Incidentally, please use mason-users@ from now on - the list traffic is low enough as it is and there's certainly no reason to split it between two groups anymore (hasn't been for years). I'll shut down this list officially and transfer remaining users over when I get the chance.

Jon
Post by Pedro Melo
Hi,
sorry to respond to my own question, I've solved it, and though it my
be handy to others.
package My::App::Mason::Compilation;
use Poet qw($conf $env);
use Poet::Moose;
extends 'Mason::Compilation';
override 'output_class_header' => sub {
return join("\n", super(), 'use Time::HiRes ();');
};
override '_output_method' => sub {
local $method->{init} = 'my $___t0 = [Time::HiRes::gettimeofday];
'.$method->{init};
local $method->{body} = 'print STDERR "HIT ".$self->cmeta->{path}."
".Time::HiRes::tv_interval($___t0)."\n";'.$method->{body};
super();
};
1;
Feel free to adjust the print STDERR to whatever you need it to be.
Bye,
Post by Pedro Melo
Hi,
I'm trying to time each Mason2 component execution to track some
deviation on run times. I've tried adding a My::App::Mason::Component
and override 'main', but main is the final method, it only exists on
generated code.
My next option is to override Mason::Compilation::_output_method but
that means copying a lot of code.
Before I start down this road, any other suggestions?
--
Pedro Melo
@pedromelo
http://www.simplicidade.org/
http://about.me/melo
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mason-devel mailing list
https://lists.sourceforge.net/lists/listinfo/mason-devel
Loading...