blib/lib/DBI/Shell/Timing.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 94.3% 50 / 53 CC 7 SCAR 12.4
CC
7
Cov
100%
do_timing
6.0
do_go
2.0
BEGIN
1.0
CRAP 3.5
« blib/lib/DBI/Shell/FindSqlFile.pm ↑ Summary blib/lib/DBI/Format/CSV.pm »
1 #
2 # Package meta, adds meta database commands to dbish
3 #
4 package DBI::Shell::Timing;
5  
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Benchmark qw(timeit timestr);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub init {
11 4 ▶ my ($self, $sh, @arg) = @_;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
12  
13  
14 4 $sh->install_options(
15 [
16 [ 'timing_style' => qq{auto} ],
17 [ 'timing_timing' => 1 ], # Set the default to on
18 [ 'timing_format' => '5.2f' ],
19 [ 'timing_prefix' => 'Elapsed: ' ],
20 ]);
21 4 my $com_ref = $sh->{commands};
22 $com_ref->{timing} = {
23 4 hint =>
24 "timing: on/off (1/0) display execute time upon completion of command",
25 };
26
27 4 return $self;
28 }
29  
30 sub do_timing {
31 19 ▶ my $self = shift;
Subroutine do_timing: called CC=6 SCAR=17.9
Pod undocumented
32 19 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 11 19
33 8 my $t = shift;
34 # $self->log( qq{timing called with $t} );
35 8 ▶ $t = 0 if ($t =~ m/off|stop|end/i);
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /off|stop|end/i 4 4 8
36 8 ▶ $t = 1 if ($t =~ m/on|start|begin/i);
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /on|start|begin/i 4 4 8
37 8 ▶ $self->{timing_timing} = ($t?1:0);
Branch: 1 branch
BranchTrueFalseTotal
$t ? : 4 4 8
38 }
39 19 ▶ $self->print_buffer(qq{timing: } . ($self->{timing_timing}? 'on': 'off'));
Branch: 1 branch
BranchTrueFalseTotal
$self->{'timing_timing'} ? : 10 9 19
40 19 return $self->{timing_timing};
41 }
42  
43  
44 #
45 # Subclass the do_go command to include the timing options. I'm not
46 # sure which is better, to subclass this command or completely
47 # override it.
48 #
49 sub do_go {
50 40 ▶ my $self = shift;
Subroutine do_go: called CC=2 SCAR=6.9
Pod undocumented
51 40 ▶ my $rv = timeit( 1, sub { $self->DBI::Shell::Base::do_go( @_ ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
52 40 ▶ if ($self->{timing_timing}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"timing_timing"}) 39 1 40
53 my $str = $self->{timing_prefix} .
54 39 timestr( $rv, $self->{timing_style}, $self->{timing_format} );
55 39 $self->log( $str );
56 }
57 40 return;
58 }
59  
60 4 my $_unimp = qq{timing: not implemented yet};
61  
62 4 1;
« blib/lib/DBI/Shell/FindSqlFile.pm ↑ Summary blib/lib/DBI/Format/CSV.pm »