Mercurial > repos > willmclaren > ensembl_vep
comparison variant_effect_predictor/Bio/EnsEMBL/Utils/EprofStack.pm @ 0:21066c0abaf5 draft
Uploaded
author | willmclaren |
---|---|
date | Fri, 03 Aug 2012 10:04:48 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:21066c0abaf5 |
---|---|
1 =head1 LICENSE | |
2 | |
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and | |
4 Genome Research Limited. All rights reserved. | |
5 | |
6 This software is distributed under a modified Apache license. | |
7 For license details, please see | |
8 | |
9 http://www.ensembl.org/info/about/code_licence.html | |
10 | |
11 =head1 CONTACT | |
12 | |
13 Please email comments or questions to the public Ensembl | |
14 developers list at <dev@ensembl.org>. | |
15 | |
16 Questions may also be sent to the Ensembl help desk at | |
17 <helpdesk@ensembl.org>. | |
18 | |
19 =cut | |
20 | |
21 =head1 NAME | |
22 | |
23 Bio::EnsEMBL::Util::EprofStack - DESCRIPTION of Object | |
24 | |
25 =head1 SYNOPSIS | |
26 | |
27 =head1 DESCRIPTION | |
28 | |
29 =head1 METHODS | |
30 | |
31 =cut | |
32 | |
33 package Bio::EnsEMBL::Utils::EprofStack; | |
34 | |
35 use strict; | |
36 use warnings; | |
37 | |
38 use POSIX; | |
39 | |
40 use Bio::EnsEMBL::Utils::Exception ('warning'); | |
41 | |
42 BEGIN { | |
43 eval { | |
44 require Time::HiRes; | |
45 Time::HiRes->import('time'); | |
46 }; | |
47 } | |
48 | |
49 sub new { | |
50 my ( $proto, $name ) = @_; | |
51 | |
52 my $class = ref($proto) || $proto; | |
53 | |
54 my $self = bless( { 'is_active' => 0, | |
55 'total_time' => 0, | |
56 'total_time_time' => 0, | |
57 'max_time' => 0, | |
58 'min_time' => 999999999, | |
59 'number' => 0, | |
60 'tag' => $name | |
61 }, | |
62 $class ); | |
63 | |
64 return $self; | |
65 } | |
66 | |
67 =head2 push_stack | |
68 | |
69 Title : push_stack | |
70 Usage : | |
71 Function: | |
72 Example : | |
73 Returns : | |
74 Args : | |
75 | |
76 | |
77 =cut | |
78 | |
79 sub push_stack { | |
80 my ( $self, @args ) = @_; | |
81 | |
82 if ( $self->{'is_active'} == 1 ) { | |
83 warning( | |
84 sprintf( "Attempting to push stack on tag '%s' " | |
85 . "when active. Discarding previous push." | |
86 . $self->tag() ) ); | |
87 } | |
88 | |
89 # my ( $user, $sys ) = times(); | |
90 # $self->{'current_start'} = (POSIX::times)[0]; | |
91 | |
92 $self->{'current_start'} = time(); | |
93 $self->{'is_active'} = 1; | |
94 } | |
95 | |
96 =head2 pop_stack | |
97 | |
98 Title : pop_stack | |
99 Usage : | |
100 Function: | |
101 Example : | |
102 Returns : | |
103 Args : | |
104 | |
105 | |
106 =cut | |
107 | |
108 sub pop_stack { | |
109 my ( $self, @args ) = @_; | |
110 | |
111 if ( $self->{'is_active'} == 0 ) { | |
112 warning( | |
113 sprintf( "Attempting to pop stack on tag '%s' " | |
114 . "when not active. Ignoring.", | |
115 $self->tag() ) ); | |
116 } | |
117 | |
118 # my ( $user, $sys ) = times(); | |
119 # my $clocktime = | |
120 # ( (POSIX::times)[0] - $self->{'current_start'} )/ | |
121 # POSIX::sysconf(&POSIX::_SC_CLK_TCK); | |
122 | |
123 my $clocktime = time() - $self->{'current_start'}; | |
124 | |
125 if ( $self->{'max_time'} < $clocktime ) { | |
126 $self->{'max_time'} = $clocktime; | |
127 } | |
128 if ( $self->{'min_time'} > $clocktime ) { | |
129 $self->{'min_time'} = $clocktime; | |
130 } | |
131 | |
132 $self->{'total_time'} += $clocktime; | |
133 $self->{'total_time_time'} += $clocktime*$clocktime; | |
134 $self->{'number'}++; | |
135 $self->{'is_active'} = 0; | |
136 } ## end sub pop_stack | |
137 | |
138 =head2 total_time_time | |
139 | |
140 Title : total_time_time | |
141 Usage : $obj->total_time_time($newval) | |
142 Function: | |
143 Returns : value of total_time_time | |
144 Args : newvalue (optional) | |
145 | |
146 | |
147 =cut | |
148 | |
149 sub total_time_time { | |
150 my ( $self, $value ) = @_; | |
151 | |
152 if ( defined($value) ) { $self->{'total_time_time'} = $value } | |
153 | |
154 return $self->{'total_time_time'}; | |
155 } | |
156 | |
157 =head2 max_time | |
158 | |
159 Title : max_time | |
160 Usage : $obj->max_time($newval) | |
161 Function: | |
162 Returns : value of max_time | |
163 Args : newvalue (optional) | |
164 | |
165 | |
166 =cut | |
167 | |
168 sub max_time { | |
169 my ( $self, $value ) = @_; | |
170 | |
171 if ( defined($value) ) { $self->{'max_time'} = $value } | |
172 | |
173 return $self->{'max_time'}; | |
174 } | |
175 | |
176 =head2 min_time | |
177 | |
178 Title : min_time | |
179 Usage : $obj->min_time($newval) | |
180 Function: | |
181 Returns : value of min_time | |
182 Args : newvalue (optional) | |
183 | |
184 | |
185 =cut | |
186 | |
187 sub min_time { | |
188 my ( $self, $value ) = @_; | |
189 | |
190 if ( defined($value) ) { $self->{'min_time'} = $value } | |
191 | |
192 return $self->{'min_time'}; | |
193 } | |
194 | |
195 =head2 total_time | |
196 | |
197 Title : total_time | |
198 Usage : $obj->total_time($newval) | |
199 Function: | |
200 Returns : value of total_time | |
201 Args : newvalue (optional) | |
202 | |
203 | |
204 =cut | |
205 | |
206 sub total_time { | |
207 my ( $self, $value ) = @_; | |
208 | |
209 if ( defined($value) ) { $self->{'total_time'} = $value } | |
210 | |
211 return $self->{'total_time'}; | |
212 } | |
213 | |
214 =head2 number | |
215 | |
216 Title : number | |
217 Usage : $obj->number($newval) | |
218 Function: | |
219 Returns : value of number | |
220 Args : newvalue (optional) | |
221 | |
222 | |
223 =cut | |
224 | |
225 sub number { | |
226 my ( $self, $value ) = @_; | |
227 | |
228 if ( defined($value) ) { $self->{'number'} = $value } | |
229 | |
230 return $self->{'number'}; | |
231 } | |
232 | |
233 =head2 is_active | |
234 | |
235 Title : is_active | |
236 Usage : $obj->is_active($newval) | |
237 Function: | |
238 Returns : value of is_active | |
239 Args : newvalue (optional) | |
240 | |
241 | |
242 =cut | |
243 | |
244 sub is_active { | |
245 my ( $self, $value ) = @_; | |
246 | |
247 if ( defined($value) ) { $self->{'is_active'} = $value } | |
248 | |
249 return $self->{'is_active'}; | |
250 } | |
251 | |
252 =head2 current_start | |
253 | |
254 Title : current_start | |
255 Usage : $obj->current_start($newval) | |
256 Function: | |
257 Returns : value of current_start | |
258 Args : newvalue (optional) | |
259 | |
260 | |
261 =cut | |
262 | |
263 sub current_start { | |
264 my ( $self, $value ) = @_; | |
265 | |
266 if ( defined($value) ) { $self->{'current_start'} = $value } | |
267 | |
268 return $self->{'current_start'}; | |
269 } | |
270 | |
271 =head2 tag | |
272 | |
273 Title : tag | |
274 Usage : $obj->tag($newval) | |
275 Function: | |
276 Returns : value of tag | |
277 Args : newvalue (optional) | |
278 | |
279 | |
280 =cut | |
281 | |
282 sub tag { | |
283 my ( $self, $value ) = @_; | |
284 | |
285 if ( defined($value) ) { $self->{'tag'} = $value } | |
286 | |
287 return $self->{'tag'}; | |
288 } | |
289 | |
290 1; |