| 1 | =head1 LICENSE | ||
| 2 | |||
| 3 | See the NOTICE file distributed with this work for additional information | ||
| 4 | regarding copyright ownership. | ||
| 5 | |||
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 7 | you may not use this file except in compliance with the License. | ||
| 8 | You may obtain a copy of the License at | ||
| 9 | |||
| 10 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 11 | |||
| 12 | Unless required by applicable law or agreed to in writing, software | ||
| 13 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 15 | See the License for the specific language governing permissions and | ||
| 16 | limitations under the License. | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | |||
| 21 | =head1 CONTACT | ||
| 22 | |||
| 23 | Please email comments or questions to the public Ensembl | ||
| 24 | developers list at <http://lists.ensembl.org/mailman/listinfo/dev>. | ||
| 25 | |||
| 26 | Questions may also be sent to the Ensembl help desk at | ||
| 27 | <http://www.ensembl.org/Help/Contact>. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | Bio::EnsEMBL::Util::EprofStack - DESCRIPTION of Object | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | =head1 DESCRIPTION | ||
| 38 | |||
| 39 | =head1 METHODS | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | package Bio::EnsEMBL::Utils::EprofStack; | ||
| 44 | $Bio::EnsEMBL::Utils::EprofStack::VERSION = '114.0.0_50'; # TRIAL | ||
| 45 | $Bio::EnsEMBL::Utils::EprofStack::VERSION = '114.0.050'; | ||
| 46 | use strict; | ||
| 47 | use warnings; | ||
| 48 | |||
| 49 | use POSIX; | ||
| 50 | |||
| 51 | use Bio::EnsEMBL::Utils::Exception ('warning'); | ||
| 52 | |||
| 53 | BEGIN { | ||
| 54 | eval { | ||
| 55 | require Time::HiRes; | ||
| 56 | Time::HiRes->import('time'); | ||
| 57 | }; | ||
| 58 | } | ||
| 59 | |||
| 60 | sub new { | ||
| 61 | my ( $proto, $name ) = @_; | ||
| 62 | |||
| 63 | my $class = ref($proto) || $proto; | ||
| 64 | |||
| 65 | my $self = bless( { 'is_active' => 0, | ||
| 66 | 'total_time' => 0, | ||
| 67 | 'total_time_time' => 0, | ||
| 68 | 'max_time' => 0, | ||
| 69 | 'min_time' => 999999999, | ||
| 70 | 'number' => 0, | ||
| 71 | 'tag' => $name | ||
| 72 | }, | ||
| 73 | $class ); | ||
| 74 | |||
| 75 | return $self; | ||
| 76 | } | ||
| 77 | |||
| 78 | =head2 push_stack | ||
| 79 | |||
| 80 | Title : push_stack | ||
| 81 | Usage : | ||
| 82 | Function: | ||
| 83 | Example : | ||
| 84 | Returns : | ||
| 85 | Args : | ||
| 86 | |||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | sub push_stack { | ||
| 91 | my ( $self, @args ) = @_; | ||
| 92 | |||
| 93 | if ( $self->{'is_active'} == 1 ) { | ||
| 94 | warning( | ||
| 95 | sprintf( "Attempting to push stack on tag '%s' " | ||
| 96 | . "when active. Discarding previous push." | ||
| 97 | . $self->tag() ) ); | ||
| 98 | } | ||
| 99 | |||
| 100 | # my ( $user, $sys ) = times(); | ||
| 101 | # $self->{'current_start'} = (POSIX::times)[0]; | ||
| 102 | |||
| 103 | $self->{'current_start'} = time(); | ||
| 104 | $self->{'is_active'} = 1; | ||
| 105 | } | ||
| 106 | |||
| 107 | =head2 pop_stack | ||
| 108 | |||
| 109 | Title : pop_stack | ||
| 110 | Usage : | ||
| 111 | Function: | ||
| 112 | Example : | ||
| 113 | Returns : | ||
| 114 | Args : | ||
| 115 | |||
| 116 | |||
| 117 | =cut | ||
| 118 | |||
| 119 | sub pop_stack { | ||
| 120 | my ( $self, @args ) = @_; | ||
| 121 | |||
| 122 | if ( $self->{'is_active'} == 0 ) { | ||
| 123 | warning( | ||
| 124 | sprintf( "Attempting to pop stack on tag '%s' " | ||
| 125 | . "when not active. Ignoring.", | ||
| 126 | $self->tag() ) ); | ||
| 127 | } | ||
| 128 | |||
| 129 | # my ( $user, $sys ) = times(); | ||
| 130 | # my $clocktime = | ||
| 131 | # ( (POSIX::times)[0] - $self->{'current_start'} )/ | ||
| 132 | # POSIX::sysconf(&POSIX::_SC_CLK_TCK); | ||
| 133 | |||
| 134 | my $clocktime = time() - $self->{'current_start'}; | ||
| 135 | |||
| 136 | if ( $self->{'max_time'} < $clocktime ) { | ||
| 137 | $self->{'max_time'} = $clocktime; | ||
| 138 | } | ||
| 139 | if ( $self->{'min_time'} > $clocktime ) { | ||
| 140 | $self->{'min_time'} = $clocktime; | ||
| 141 | } | ||
| 142 | |||
| 143 | $self->{'total_time'} += $clocktime; | ||
| 144 | $self->{'total_time_time'} += $clocktime*$clocktime; | ||
| 145 | $self->{'number'}++; | ||
| 146 | $self->{'is_active'} = 0; | ||
| 147 | } ## end sub pop_stack | ||
| 148 | |||
| 149 | =head2 total_time_time | ||
| 150 | |||
| 151 | Title : total_time_time | ||
| 152 | Usage : $obj->total_time_time($newval) | ||
| 153 | Function: | ||
| 154 | Returns : value of total_time_time | ||
| 155 | Args : newvalue (optional) | ||
| 156 | |||
| 157 | |||
| 158 | =cut | ||
| 159 | |||
| 160 | sub total_time_time { | ||
| 161 | my ( $self, $value ) = @_; | ||
| 162 | |||
| 163 | if ( defined($value) ) { $self->{'total_time_time'} = $value } | ||
| 164 | |||
| 165 | return $self->{'total_time_time'}; | ||
| 166 | } | ||
| 167 | |||
| 168 | =head2 max_time | ||
| 169 | |||
| 170 | Title : max_time | ||
| 171 | Usage : $obj->max_time($newval) | ||
| 172 | Function: | ||
| 173 | Returns : value of max_time | ||
| 174 | Args : newvalue (optional) | ||
| 175 | |||
| 176 | |||
| 177 | =cut | ||
| 178 | |||
| 179 | sub max_time { | ||
| 180 | my ( $self, $value ) = @_; | ||
| 181 | |||
| 182 | if ( defined($value) ) { $self->{'max_time'} = $value } | ||
| 183 | |||
| 184 | return $self->{'max_time'}; | ||
| 185 | } | ||
| 186 | |||
| 187 | =head2 min_time | ||
| 188 | |||
| 189 | Title : min_time | ||
| 190 | Usage : $obj->min_time($newval) | ||
| 191 | Function: | ||
| 192 | Returns : value of min_time | ||
| 193 | Args : newvalue (optional) | ||
| 194 | |||
| 195 | |||
| 196 | =cut | ||
| 197 | |||
| 198 | sub min_time { | ||
| 199 | my ( $self, $value ) = @_; | ||
| 200 | |||
| 201 | if ( defined($value) ) { $self->{'min_time'} = $value } | ||
| 202 | |||
| 203 | return $self->{'min_time'}; | ||
| 204 | } | ||
| 205 | |||
| 206 | =head2 total_time | ||
| 207 | |||
| 208 | Title : total_time | ||
| 209 | Usage : $obj->total_time($newval) | ||
| 210 | Function: | ||
| 211 | Returns : value of total_time | ||
| 212 | Args : newvalue (optional) | ||
| 213 | |||
| 214 | |||
| 215 | =cut | ||
| 216 | |||
| 217 | sub total_time { | ||
| 218 | my ( $self, $value ) = @_; | ||
| 219 | |||
| 220 | if ( defined($value) ) { $self->{'total_time'} = $value } | ||
| 221 | |||
| 222 | return $self->{'total_time'}; | ||
| 223 | } | ||
| 224 | |||
| 225 | =head2 number | ||
| 226 | |||
| 227 | Title : number | ||
| 228 | Usage : $obj->number($newval) | ||
| 229 | Function: | ||
| 230 | Returns : value of number | ||
| 231 | Args : newvalue (optional) | ||
| 232 | |||
| 233 | |||
| 234 | =cut | ||
| 235 | |||
| 236 | sub number { | ||
| 237 | my ( $self, $value ) = @_; | ||
| 238 | |||
| 239 | if ( defined($value) ) { $self->{'number'} = $value } | ||
| 240 | |||
| 241 | return $self->{'number'}; | ||
| 242 | } | ||
| 243 | |||
| 244 | =head2 is_active | ||
| 245 | |||
| 246 | Title : is_active | ||
| 247 | Usage : $obj->is_active($newval) | ||
| 248 | Function: | ||
| 249 | Returns : value of is_active | ||
| 250 | Args : newvalue (optional) | ||
| 251 | |||
| 252 | |||
| 253 | =cut | ||
| 254 | |||
| 255 | sub is_active { | ||
| 256 | my ( $self, $value ) = @_; | ||
| 257 | |||
| 258 | if ( defined($value) ) { $self->{'is_active'} = $value } | ||
| 259 | |||
| 260 | return $self->{'is_active'}; | ||
| 261 | } | ||
| 262 | |||
| 263 | =head2 current_start | ||
| 264 | |||
| 265 | Title : current_start | ||
| 266 | Usage : $obj->current_start($newval) | ||
| 267 | Function: | ||
| 268 | Returns : value of current_start | ||
| 269 | Args : newvalue (optional) | ||
| 270 | |||
| 271 | |||
| 272 | =cut | ||
| 273 | |||
| 274 | sub current_start { | ||
| 275 | my ( $self, $value ) = @_; | ||
| 276 | |||
| 277 | if ( defined($value) ) { $self->{'current_start'} = $value } | ||
| 278 | |||
| 279 | return $self->{'current_start'}; | ||
| 280 | } | ||
| 281 | |||
| 282 | =head2 tag | ||
| 283 | |||
| 284 | Title : tag | ||
| 285 | Usage : $obj->tag($newval) | ||
| 286 | Function: | ||
| 287 | Returns : value of tag | ||
| 288 | Args : newvalue (optional) | ||
| 289 | |||
| 290 | |||
| 291 | =cut | ||
| 292 | |||
| 293 | sub tag { | ||
| 294 | my ( $self, $value ) = @_; | ||
| 295 | |||
| 296 | if ( defined($value) ) { $self->{'tag'} = $value } | ||
| 297 | |||
| 298 | return $self->{'tag'}; | ||
| 299 | } | ||
| 300 | |||
| 301 | 1; |