| 1 | package DBIx::dbMan::Extension::BenchmarkStop; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base 'DBIx::dbMan::Extension'; | ||
| 5 | |||
| 6 | our $VERSION = '0.02'; | ||
| 7 | |||
| 8 | 1; | ||
| 9 | |||
| 10 | sub IDENTIFICATION { return "000001-000052-000002"; } | ||
| 11 | |||
| 12 | sub preference { return -40; } | ||
| 13 | |||
| 14 | sub init { | ||
| 15 | my $obj = shift; | ||
| 16 | |||
| 17 | $obj->{hires} = 0; | ||
| 18 | eval q{ | ||
| 19 | use Time::HiRes qw/gettimeofday tv_interval/; | ||
| 20 | }; | ||
| 21 | ++$obj->{hires} unless $@; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub handle_action { | ||
| 25 | my ($obj,%action) = @_; | ||
| 26 | |||
| 27 | if ($action{benchmark_starttime}) { | ||
| 28 | my $time; | ||
| 29 | if ($obj->{hires}) { | ||
| 30 | eval q{ | ||
| 31 | $time = tv_interval($action{benchmark_starttime},[ gettimeofday ]); | ||
| 32 | }; | ||
| 33 | } else { | ||
| 34 | $time = time-$action{benchmark_starttime}; | ||
| 35 | } | ||
| 36 | delete $action{benchmark_starttime}; | ||
| 37 | my $info = "Elapsed time: $time s\n"; | ||
| 38 | if ($action{action} eq 'OUTPUT') { | ||
| 39 | $action{output} .= $info; | ||
| 40 | } else { | ||
| 41 | $obj->{-interface}->print($info); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | $action{processed} = 1; | ||
| 46 | return %action; | ||
| 47 | } |