summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Axel 'fREW' Schmidt <frioux@gmail.com>2013-06-06 18:27:43 -0500
committerArthur Axel 'fREW' Schmidt <frioux@gmail.com>2013-06-06 18:27:43 -0500
commit3f90aea66675b0bc2224d16992390a6bb69accd4 (patch)
treea4761d49489ff543c54c33d1a1a51853bf9e9105
parentff53642a01ff891c00c9f4de8472f664353aa357 (diff)
downloadreply-3f90aea66675b0bc2224d16992390a6bb69accd4.tar.gz
reply-3f90aea66675b0bc2224d16992390a6bb69accd4.zip
add Timer plugin
-rw-r--r--Changes1
-rw-r--r--lib/Reply/Plugin/Timer.pm52
2 files changed, 53 insertions, 0 deletions
diff --git a/Changes b/Changes
index b037f86..22ffcd3 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
Revision history for Reply
{{$NEXT}}
+ - add Timer plugin (Arthur Axel fREW Schmidt)
0.05 2013-06-04
- avoid test failures from DataPrinter, since it's optional
diff --git a/lib/Reply/Plugin/Timer.pm b/lib/Reply/Plugin/Timer.pm
new file mode 100644
index 0000000..a3ec247
--- /dev/null
+++ b/lib/Reply/Plugin/Timer.pm
@@ -0,0 +1,52 @@
+package Reply::Plugin::Timer;
+use strict;
+use warnings;
+# ABSTRACT: time commands
+
+use base 'Reply::Plugin';
+
+use Time::HiRes qw(gettimeofday tv_interval);
+
+=head1 SYNOPSIS
+
+ ; .replyrc
+ [Timer]
+ mintime = 0.01
+
+=head1 DESCRIPTION
+
+This plugin prints timer info for results that take longer than C<mintime>.
+the default C<mintime> is C<< 0.01 >> seconds.
+
+=cut
+
+sub new {
+ my $class = shift;
+ my %opts = @_;
+
+ my $self = $class->SUPER::new(@_);
+ $self->{mintime} = $opts{mintime} || 0.01;
+
+ return $self;
+}
+
+
+sub execute {
+ my ($self, $next, @args) = @_;
+
+ my $t0 = [gettimeofday];
+ my $ret = $next->(@args);
+ my $elapsed = tv_interval($t0);
+
+ if ($elapsed > $self->{mintime}) {
+ if ($elapsed >= 1) {
+ printf "Execution Time: %0.3fs\n", $elapsed
+ } else {
+ printf "Execution Time: %dms\n", $elapsed * 1000
+ }
+ }
+
+ return $ret;
+}
+
+1;