<commit_before>
#
# BioPerl module for Bio::EnsEMBL::Util::EprofStack
#
# Cared for by <NAME> <<EMAIL>>
#
# Copyright <NAME>
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::EnsEMBL::Util::EprofStack - DESCRIPTION of Object

=head1 SYNOPSIS

Give standard usage here

=head1 DESCRIPTION

Describe the object here

=head1 CONTACT

Describe contact details here

=head1 APPENDIX

The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _

=cut


# Let the code begin...


package Bio::EnsEMBL::Utils::EprofStack;
use vars qw(@ISA);
use strict;

# Object preamble - inheriets from Bio::Root::Object

use Bio::Root::RootI;

@ISA = qw(Bio::Root::RootI);


sub new { 
    my ($class,$name) = @_;
    my $self = {};
    bless $self,$class;

    $self->is_active(0);
    $self->total_time(0);
    $self->number(0);
    $self->tag($name);

    return $self;
}

=head2 push_stack

 Title   : push_stack
 Usage   :
 Function:
 Example :
 Returns : 
 Args    :


=cut

sub push_stack{
   my ($self,@args) = @_;

   if( $self->is_active == 1 ) {
       $self->warn("Attempting to push stack on tag ",$self->tag," when active. Discarding previous push");
   }
   my($user,$sys) = times();
   $self->current_start($user);
   $self->is_active(1);
}

=head2 pop_stack

 Title   : pop_stack
 Usage   :
 Function:
 Example :
 Returns : 
 Args    :


=cut

sub pop_stack{
   my ($self,@args) = @_;

   if( $self->is_active == 0 ) {
       $self->warn("Attempting to push stack on tag ",$self->tag," when not active. Ignoring");
   }
   my($user,$sys) = times();
   $self->total_time( $self->total_time() + $user - $self->current_start);
   $self->number( $self->number() + 1 );
   $self->is_active(0);
}


=head2 total_time

 Title   : total_time
 Usage   : $obj->total_time($newval)
 Function: 
 Returns : value of total_time<commit_msg>POSIX timing instead of perl times()<commit_after>
#
# BioPerl module for Bio::EnsEMBL::Util::EprofStack
#
# Cared for by <NAME> <<EMAIL>>
#
# Copyright <NAME>
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::EnsEMBL::Util::EprofStack - DESCRIPTION of Object

=head1 SYNOPSIS

Give standard usage here

=head1 DESCRIPTION

Describe the object here

=head1 CONTACT

Describe contact details here

=head1 APPENDIX

The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _

=cut


# Let the code begin...


package Bio::EnsEMBL::Utils::EprofStack;
use vars qw(@ISA);
use POSIX;
use strict;

# Object preamble - inheriets from Bio::Root::Object

use Bio::Root::RootI;

@ISA = qw(Bio::Root::RootI);


sub new { 
    my ($class,$name) = @_;
    my $self = {};
    bless $self,$class;

    $self->is_active(0);
    $self->total_time(0);
    $self->number(0);
    $self->tag($name);

    return $self;
}

=head2 push_stack

 Title   : push_stack
 Usage   :
 Function:
 Example :
 Returns : 
 Args    :


=cut

sub push_stack{
   my ($self,@args) = @_;

   if( $self->is_active == 1 ) {
       $self->warn("Attempting to push stack on tag ",$self->tag," when active. Discarding previous push");
   }
   #my($user,$sys) = times();
   my $real = (POSIX::times)[0];
   $self->current_start($real);
   $self->is_active(1);
}

=head2 pop_stack

 Title   : pop_stack
 Usage   :
 Function:
 Example :
 Returns : 
 Args    :


=cut

sub pop_stack{
   my ($self,@args) = @_;

   if( $self->is_active == 0 ) {
       $self->warn("Attempting to push stack on tag ",$self->tag," when not active. Ignoring");
   }
   #my($user,$sys) = times();
   my $real = (POSIX::times)[0];
   my $clockticks =  $real - $self->current_start;
   my $clocktime = $clockticks / POSIX::sysconf(&POSIX::_SC_CLK_TCK);
   $self->total_time( $self->total_time() + $clocktime);
   $self->number( $self->number() + 1 );
   $self->is_active(0);
}


=head2 total_time

 Title   : total_time
 Usage   : $obj->total_time($newval)
 Function: 
 Returns : value of total_time
{'fraction_non_alphanumeric': 0.14790607601065117, 'fraction_numerical': 0.00823045267489712, 'mean_word_length': 3.530701754385965, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4655279', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1453, 'n_words': 403}