EnsEMBL/Utils/EprofStack.pm untested

filter: Statementstmt 0.0% 0 / 73 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 131 CC 13 SCAR 19.4
CC
13
Cov
0%
pop_stack
20.0
push_stack
6.0
total_time_time
6.0
CRAP 7.0
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';
45 use strict;
46 use warnings;
47  
48 use POSIX;
49  
50 use Bio::EnsEMBL::Utils::Exception ('warning');
51  
52 BEGIN {
53 eval {
54 require Time::HiRes;
55 Time::HiRes->import('time');
56 };
57 }
58  
59 sub new {
60 my ( $proto, $name ) = @_;
61  
62 my $class = ref($proto) || $proto;
63  
64 my $self = bless( { 'is_active' => 0,
65 'total_time' => 0,
66 'total_time_time' => 0,
67 'max_time' => 0,
68 'min_time' => 999999999,
69 'number' => 0,
70 'tag' => $name
71 },
72 $class );
73  
74 return $self;
75 }
76  
77 =head2 push_stack
78  
79 Title : push_stack
80 Usage :
81 Function:
82 Example :
83 Returns :
84 Args :
85  
86  
87 =cut
88  
89 sub push_stack {
90 my ( $self, @args ) = @_;
91  
92 if ( $self->{'is_active'} == 1 ) {
93 warning(
94 sprintf( "Attempting to push stack on tag '%s' "
95 . "when active. Discarding previous push."
96 . $self->tag() ) );
97 }
98  
99 # my ( $user, $sys ) = times();
100 # $self->{'current_start'} = (POSIX::times)[0];
101  
102 $self->{'current_start'} = time();
103 $self->{'is_active'} = 1;
104 }
105  
106 =head2 pop_stack
107  
108 Title : pop_stack
109 Usage :
110 Function:
111 Example :
112 Returns :
113 Args :
114  
115  
116 =cut
117  
118 sub pop_stack {
119 my ( $self, @args ) = @_;
120  
121 if ( $self->{'is_active'} == 0 ) {
122 warning(
123 sprintf( "Attempting to pop stack on tag '%s' "
124 . "when not active. Ignoring.",
125 $self->tag() ) );
126 }
127  
128 # my ( $user, $sys ) = times();
129 # my $clocktime =
130 # ( (POSIX::times)[0] - $self->{'current_start'} )/
131 # POSIX::sysconf(&POSIX::_SC_CLK_TCK);
132  
133 my $clocktime = time() - $self->{'current_start'};
134  
135 if ( $self->{'max_time'} < $clocktime ) {
136 $self->{'max_time'} = $clocktime;
137 }
138 if ( $self->{'min_time'} > $clocktime ) {
139 $self->{'min_time'} = $clocktime;
140 }
141  
142 $self->{'total_time'} += $clocktime;
143 $self->{'total_time_time'} += $clocktime*$clocktime;
144 $self->{'number'}++;
145 $self->{'is_active'} = 0;
146 } ## end sub pop_stack
147  
148 =head2 total_time_time
149  
150 Title : total_time_time
151 Usage : $obj->total_time_time($newval)
152 Function:
153 Returns : value of total_time_time
154 Args : newvalue (optional)
155  
156  
157 =cut
158  
159 sub total_time_time {
160 my ( $self, $value ) = @_;
161  
162 if ( defined($value) ) { $self->{'total_time_time'} = $value }
163  
164 return $self->{'total_time_time'};
165 }
166  
167 =head2 max_time
168  
169 Title : max_time
170 Usage : $obj->max_time($newval)
171 Function:
172 Returns : value of max_time
173 Args : newvalue (optional)
174  
175  
176 =cut
177  
178 sub max_time {
179 my ( $self, $value ) = @_;
180  
181 if ( defined($value) ) { $self->{'max_time'} = $value }
182  
183 return $self->{'max_time'};
184 }
185  
186 =head2 min_time
187  
188 Title : min_time
189 Usage : $obj->min_time($newval)
190 Function:
191 Returns : value of min_time
192 Args : newvalue (optional)
193  
194  
195 =cut
196  
197 sub min_time {
198 my ( $self, $value ) = @_;
199  
200 if ( defined($value) ) { $self->{'min_time'} = $value }
201  
202 return $self->{'min_time'};
203 }
204  
205 =head2 total_time
206  
207 Title : total_time
208 Usage : $obj->total_time($newval)
209 Function:
210 Returns : value of total_time
211 Args : newvalue (optional)
212  
213  
214 =cut
215  
216 sub total_time {
217 my ( $self, $value ) = @_;
218  
219 if ( defined($value) ) { $self->{'total_time'} = $value }
220  
221 return $self->{'total_time'};
222 }
223  
224 =head2 number
225  
226 Title : number
227 Usage : $obj->number($newval)
228 Function:
229 Returns : value of number
230 Args : newvalue (optional)
231  
232  
233 =cut
234  
235 sub number {
236 my ( $self, $value ) = @_;
237  
238 if ( defined($value) ) { $self->{'number'} = $value }
239  
240 return $self->{'number'};
241 }
242  
243 =head2 is_active
244  
245 Title : is_active
246 Usage : $obj->is_active($newval)
247 Function:
248 Returns : value of is_active
249 Args : newvalue (optional)
250  
251  
252 =cut
253  
254 sub is_active {
255 my ( $self, $value ) = @_;
256  
257 if ( defined($value) ) { $self->{'is_active'} = $value }
258  
259 return $self->{'is_active'};
260 }
261  
262 =head2 current_start
263  
264 Title : current_start
265 Usage : $obj->current_start($newval)
266 Function:
267 Returns : value of current_start
268 Args : newvalue (optional)
269  
270  
271 =cut
272  
273 sub current_start {
274 my ( $self, $value ) = @_;
275  
276 if ( defined($value) ) { $self->{'current_start'} = $value }
277  
278 return $self->{'current_start'};
279 }
280  
281 =head2 tag
282  
283 Title : tag
284 Usage : $obj->tag($newval)
285 Function:
286 Returns : value of tag
287 Args : newvalue (optional)
288  
289  
290 =cut
291  
292 sub tag {
293 my ( $self, $value ) = @_;
294  
295 if ( defined($value) ) { $self->{'tag'} = $value }
296  
297 return $self->{'tag'};
298 }
299  
300 1;