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