こんにちは!ぽろきぃだy!
2008年ボジョレー解禁日のパフォーマンス改善にて、使用しましたソースコードを公開しようかと思うよ!下の画像のことだね!
![](https://image02.seesaawiki.jp/p/y/polocky/c2079b82fc21cf5c.png)
公開といっても、数分で書けるような簡単なものなんだけど、Template-Toolkit内の速度を見ることに限定すればそれなりに使えるポロリ!
2008年ボジョレー解禁日のパフォーマンス改善にて、使用しましたソースコードを公開しようかと思うよ!下の画像のことだね!
![](https://image02.seesaawiki.jp/p/y/polocky/c2079b82fc21cf5c.png)
公開といっても、数分で書けるような簡単なものなんだけど、Template-Toolkit内の速度を見ることに限定すればそれなりに使えるポロリ!
package Template::Plugin::Debug::Watch; use warnings; use strict; use base qw/Template::Plugin/; use Time::HiRes qw(gettimeofday tv_interval ); # Help me, help you. sub new { my $class = shift; my $context = shift; #TODO: do not use hardcoding. my $self = bless { data => [] , t => [gettimeofday] , alert => 0.02 , summary_sec => 0.1 }, $class; my $sec = tv_interval( $self->{t} ); push @{$self->{data}} , { label => 'BEGIN' , sec => sprintf("%f",$sec) , color => 'green' , summary_sec => $sec , color => 'green' , summary_color => 'green' }; return $self; } sub check { my $self = shift; my $label = shift; my $summary_sec = tv_interval( $self->{t} ); my $sec = sprintf("%f",$summary_sec - $self->{data}[-1]{summary_sec}); my $color = $sec > $self->{alert} ? 'red' : 'green'; my $summary_color = $summary_sec > $self->{summary_sec} ? 'red' : 'green'; push @{$self->{data}} , { label => $label , sec => $sec , color => $color , summary_sec => $summary_sec , color => $color , summary_color => $summary_color }; return ''; } sub debug_screen { my $self = shift; $self->check('END'); my $html = qq|<div id="template-plugin-debug-watch" class="debug-watch-box" style="padding:10px;position: absolute; top: 1px; right: 1px;background-color : #000 ; color : #fff ;z-index:1000"><table border="1" style="border-color:red">\n|; $html .=qq|<tr><th colspan="3" style="padding:3px;text-align:center"><span style="color:green">Debug::Watch</th></tr>|; $html .=qq|<tr><th style="padding:3px">label</th><th style="padding:3px">sec</th><th style="padding:3px">total sec</th></tr>|; for my $item ( @{$self->{data}} ) { $html .= qq|<tr><td style="padding:3px;">$item->{label}</td><td style="padding:3px;"><span style="color:$item->{color};">$item->{sec}</span> sec</td><td style="padding:3px;"><span style="color:$item->{summary_color};">$item->{summary_sec}</span> sec</td></tr>\n|; } $html .= qq|</table></div>\n|; return $html; } 1; =head1 NAME Template::Plugin::Debug::Watch - Watch Out! =head1 SYNOPSYS [% USE watcher = Debug::Watch %] <!-- do somwthig A--> [% watcher.check('A') %] <!-- do somwthig B--> [% watcher.check('B') %] <!-- do left oever --> [% watcher.debug_screen %] =head1 Author polocky =cut
タグ
コメントをかく