15 $fetching_stopwatch->continue();
16 $runnable->fetch_input();
17 $fetching_stopwatch->pause();
19 $running_stopwatch->continue();
21 $running_stopwatch->pause();
25 my $only_fetches = $fetching_stopwatch->get_elapsed; # probably stopped
26 my $total_time_elapsed = $total_stopwatch->get_elapsed; # running through
30 This is a standalone
object used to time various events in the Hive.
34 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
35 Copyright [2016-2024] EMBL-European Bioinformatics Institute
37 Licensed under the Apache License,
Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
38 You may obtain a copy of the License at
42 Unless required by applicable law or agreed to in writing, software distributed under the License
43 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44 See the License
for the specific language governing permissions and limitations under the License.
48 Please subscribe to the
Hive mailing list: http:
53 package Bio::EnsEMBL::Hive::Utils::Stopwatch;
57 use Time::HiRes qw(time);
59 my $default_unit = 1000; # milliseconds
64 my $self = bless {}, $class;
68 sub _unit { # only set it once
for each timer to avoid messing everything up
71 $self->{
'_unit'} = shift
if(@_);
72 return $self->{
'_unit'} || $default_unit;
78 $self->{
'_is_counting'} = shift
if(@_);
79 return $self->{
'_is_counting'} || 0;
85 $self->{
'_accumulated'} = shift
if(@_);
86 return $self->{
'_accumulated'} || 0;
89 sub
continue { # the opposite of pause()
92 unless($self->is_counting) { # ignore
if it was already running
93 $self->is_counting(1);
94 $self->{
'_start'} = time() * $self->_unit
103 $self->accumulated(0);
104 return $self->continue;
107 sub get_elapsed { # peek without stopping (in
case it was running)
110 return ($self->accumulated + $self->is_counting * (time() * $self->_unit - $self->{
'_start'}));
116 $self->accumulated( $self->get_elapsed );
117 $self->is_counting(0);