Archive Ensembl HomeArchive Ensembl Home
EprofStack.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003   Copyright (c) 1999-2012 The European Bioinformatics Institute and
00004   Genome Research Limited.  All rights reserved.
00005 
00006   This software is distributed under a modified Apache license.
00007   For license details, please see
00008 
00009     http://www.ensembl.org/info/about/code_licence.html
00010 
00011 =head1 CONTACT
00012 
00013   Please email comments or questions to the public Ensembl
00014   developers list at <dev@ensembl.org>.
00015 
00016   Questions may also be sent to the Ensembl help desk at
00017   <helpdesk@ensembl.org>.
00018 
00019 =cut
00020 
00021 =head1 NAME
00022 
00023 Bio::EnsEMBL::Util::EprofStack - DESCRIPTION of Object
00024 
00025 =head1 SYNOPSIS
00026 
00027 =head1 DESCRIPTION
00028 
00029 =head1 METHODS
00030 
00031 =cut
00032 
00033 package Bio::EnsEMBL::Utils::EprofStack;
00034 
00035 use strict;
00036 use warnings;
00037 
00038 use POSIX;
00039 
00040 use Bio::EnsEMBL::Utils::Exception ('warning');
00041 
00042 BEGIN {
00043   eval {
00044     require Time::HiRes;
00045     Time::HiRes->import('time');
00046   };
00047 }
00048 
00049 sub new {
00050   my ( $proto, $name ) = @_;
00051 
00052   my $class = ref($proto) || $proto;
00053 
00054   my $self = bless( { 'is_active'       => 0,
00055                       'total_time'      => 0,
00056                       'total_time_time' => 0,
00057                       'max_time'        => 0,
00058                       'min_time'        => 999999999,
00059                       'number'          => 0,
00060                       'tag'             => $name
00061                     },
00062                     $class );
00063 
00064   return $self;
00065 }
00066 
00067 =head2 push_stack
00068 
00069  Title   : push_stack
00070  Usage   :
00071  Function:
00072  Example :
00073  Returns : 
00074  Args    :
00075 
00076 
00077 =cut
00078 
00079 sub push_stack {
00080   my ( $self, @args ) = @_;
00081 
00082   if ( $self->{'is_active'} == 1 ) {
00083     warning(
00084              sprintf(     "Attempting to push stack on tag '%s' "
00085                         . "when active. Discarding previous push."
00086                         . $self->tag() ) );
00087   }
00088 
00089   # my ( $user, $sys ) = times();
00090   # $self->{'current_start'} = (POSIX::times)[0];
00091 
00092   $self->{'current_start'} = time();
00093   $self->{'is_active'}     = 1;
00094 }
00095 
00096 =head2 pop_stack
00097 
00098  Title   : pop_stack
00099  Usage   :
00100  Function:
00101  Example :
00102  Returns : 
00103  Args    :
00104 
00105 
00106 =cut
00107 
00108 sub pop_stack {
00109   my ( $self, @args ) = @_;
00110 
00111   if ( $self->{'is_active'} == 0 ) {
00112     warning(
00113              sprintf( "Attempting to pop stack on tag '%s' "
00114                         . "when not active. Ignoring.",
00115                       $self->tag() ) );
00116   }
00117 
00118   # my ( $user, $sys ) = times();
00119   # my $clocktime =
00120   #   ( (POSIX::times)[0] - $self->{'current_start'} )/
00121   #   POSIX::sysconf(&POSIX::_SC_CLK_TCK);
00122 
00123   my $clocktime = time() - $self->{'current_start'};
00124 
00125   if ( $self->{'max_time'} < $clocktime ) {
00126     $self->{'max_time'} = $clocktime;
00127   }
00128   if ( $self->{'min_time'} > $clocktime ) {
00129     $self->{'min_time'} = $clocktime;
00130   }
00131 
00132   $self->{'total_time'}      += $clocktime;
00133   $self->{'total_time_time'} += $clocktime*$clocktime;
00134   $self->{'number'}++;
00135   $self->{'is_active'} = 0;
00136 } ## end sub pop_stack
00137 
00138 =head2 total_time_time
00139 
00140  Title   : total_time_time
00141  Usage   : $obj->total_time_time($newval)
00142  Function: 
00143  Returns : value of total_time_time
00144  Args    : newvalue (optional)
00145 
00146 
00147 =cut
00148 
00149 sub total_time_time {
00150   my ( $self, $value ) = @_;
00151 
00152   if ( defined($value) ) { $self->{'total_time_time'} = $value }
00153 
00154   return $self->{'total_time_time'};
00155 }
00156 
00157 =head2 max_time
00158 
00159  Title   : max_time
00160  Usage   : $obj->max_time($newval)
00161  Function: 
00162  Returns : value of max_time
00163  Args    : newvalue (optional)
00164 
00165 
00166 =cut
00167 
00168 sub max_time {
00169   my ( $self, $value ) = @_;
00170 
00171   if ( defined($value) ) { $self->{'max_time'} = $value }
00172 
00173   return $self->{'max_time'};
00174 }
00175 
00176 =head2 min_time
00177 
00178  Title   : min_time
00179  Usage   : $obj->min_time($newval)
00180  Function: 
00181  Returns : value of min_time
00182  Args    : newvalue (optional)
00183 
00184 
00185 =cut
00186 
00187 sub min_time {
00188   my ( $self, $value ) = @_;
00189 
00190   if ( defined($value) ) { $self->{'min_time'} = $value }
00191 
00192   return $self->{'min_time'};
00193 }
00194 
00195 =head2 total_time
00196 
00197  Title   : total_time
00198  Usage   : $obj->total_time($newval)
00199  Function: 
00200  Returns : value of total_time
00201  Args    : newvalue (optional)
00202 
00203 
00204 =cut
00205 
00206 sub total_time {
00207   my ( $self, $value ) = @_;
00208 
00209   if ( defined($value) ) { $self->{'total_time'} = $value }
00210 
00211   return $self->{'total_time'};
00212 }
00213 
00214 =head2 number
00215 
00216  Title   : number
00217  Usage   : $obj->number($newval)
00218  Function: 
00219  Returns : value of number
00220  Args    : newvalue (optional)
00221 
00222 
00223 =cut
00224 
00225 sub number {
00226   my ( $self, $value ) = @_;
00227 
00228   if ( defined($value) ) { $self->{'number'} = $value }
00229 
00230   return $self->{'number'};
00231 }
00232 
00233 =head2 is_active
00234 
00235  Title   : is_active
00236  Usage   : $obj->is_active($newval)
00237  Function: 
00238  Returns : value of is_active
00239  Args    : newvalue (optional)
00240 
00241 
00242 =cut
00243 
00244 sub is_active {
00245   my ( $self, $value ) = @_;
00246 
00247   if ( defined($value) ) { $self->{'is_active'} = $value }
00248 
00249   return $self->{'is_active'};
00250 }
00251 
00252 =head2 current_start
00253 
00254  Title   : current_start
00255  Usage   : $obj->current_start($newval)
00256  Function: 
00257  Returns : value of current_start
00258  Args    : newvalue (optional)
00259 
00260 
00261 =cut
00262 
00263 sub current_start {
00264   my ( $self, $value ) = @_;
00265 
00266   if ( defined($value) ) { $self->{'current_start'} = $value }
00267 
00268   return $self->{'current_start'};
00269 }
00270 
00271 =head2 tag
00272 
00273  Title   : tag
00274  Usage   : $obj->tag($newval)
00275  Function: 
00276  Returns : value of tag
00277  Args    : newvalue (optional)
00278 
00279 
00280 =cut
00281 
00282 sub tag {
00283   my ( $self, $value ) = @_;
00284 
00285   if ( defined($value) ) { $self->{'tag'} = $value }
00286 
00287   return $self->{'tag'};
00288 }
00289 
00290 1;