File Coverage

blib/lib/Class/ReluctantORM/Monitor/Timer.pm
Criterion Covered Total %
statement 12 20 60.0
branch n/a
condition n/a
subroutine 4 9 44.4
pod 5 5 100.0
total 21 34 61.7


line stmt bran cond sub pod time code
1             package Class::ReluctantORM::Monitor::Timer;
2              
3             =head1 NAME
4              
5             Class::ReluctantORM::Monitor::Timer - Track running time of queries
6              
7             =head1 SYNOPSIS
8              
9             use aliased 'Class::ReluctantORM::Monitor::Timer';
10             my $mon = Timer->new(highwater_count => N, fatal_threshold => X);
11             Class::ReluctantORM->install_global_monitor($mon);
12             Pirate->install_class_monitor($mon);
13              
14             # Do a query....
15             Pirate->fetch(...);
16              
17             # Read from the monitor - decimal seconds
18             my $count = $mon->last_measured_value();
19              
20             =head1 DESCRIPTION
21              
22             A monitor that watches the amount of wall time used to execute a query.
23              
24             This is a Measuring Monitor.
25              
26             =cut
27              
28 1     1   6 use strict;
  1         1  
  1         31  
29 1     1   6 use warnings;
  1         2  
  1         25  
30 1     1   5 use base 'Class::ReluctantORM::Monitor::Measuring';
  1         2  
  1         84  
31              
32 1     1   1103 use Time::HiRes qw();
  1         2365  
  1         168  
33              
34 0     0 1   sub permitted_events { return qw(execute_finish); }
35 0     0 1   sub default_events { return qw(execute_finish); }
36 0     0 1   sub measurement_label { return 'Wall Time for query execute()'; }
37             sub take_measurement {
38 0     0 1   my ($mon, %event) = @_;
39 0           return Time::HiRes::time() - $mon->{_start};
40             }
41              
42             sub notify_execute_begin {
43 0     0 1   my $self = shift;
44 0           $self->reset();
45 0           $self->{_start} = Time::HiRes::time();
46             }
47              
48             1;