comparison variant_effect_predictor/Bio/EnsEMBL/Utils/Eprof.pm @ 0:1f6dce3d34e0

Uploaded
author mahtabm
date Thu, 11 Apr 2013 02:01:53 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1f6dce3d34e0
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::Utils::Eprof - Bespoke Ensembl profiler
24
25 =head1 SYNOPSIS
26
27 use Bio::EnsEMBL::Utils::Eprof( 'eprof_start', 'eprof_end',
28 'eprof_dump' );
29
30 &eprof_start('function-a');
31 # ... do something
32 &eprof_end('function-a');
33
34 &eprof_dump( \*STDERR );
35
36 # there is an object based set for above as well, for running
37 # multiple concurrent profilers
38
39 =head1 DESCRIPTION
40
41 This is an Ensembl profiler as we broke the Perl profilers.
42
43 =head1 METHODS
44
45 =cut
46
47 package Bio::EnsEMBL::Utils::Eprof;
48
49 use strict;
50 use warnings;
51
52 use Bio::EnsEMBL::Utils::Exception ('throw');
53 use Bio::EnsEMBL::Utils::EprofStack;
54
55 use base qw( Exporter );
56
57 our @EXPORT_OK =
58 ( 'eprof_start', 'eprof_end', 'eprof_dump', 'eprof_reset' );
59
60 my $global;
61
62 sub new {
63 my ($proto) = @_;
64
65 my $class = ref($proto) || $proto;
66 my $self = bless( { '_tags' => {} }, $class );
67
68 return $self;
69 }
70
71 =head2 eprof_start
72
73 Title : eprof_start
74 Usage :
75 Function:
76 Example :
77 Returns :
78 Args :
79
80
81 =cut
82
83 sub eprof_start {
84 my ($tag) = @_;
85
86 if ( !defined($global) ) {
87 $global = Bio::EnsEMBL::Utils::Eprof->new();
88 }
89
90 $global->start($tag);
91 }
92
93 =head2 eprof_end
94
95 Title : eprof_end
96 Usage :
97 Function:
98 Example :
99 Returns :
100 Args :
101
102
103 =cut
104
105 sub eprof_end {
106 my ($tag) = @_;
107
108 if ( !defined($global) ) {
109 $global = Bio::EnsEMBL::Utils::Eprof->new();
110 }
111
112 $global->end($tag);
113 }
114
115 sub eprof_dump {
116 my ($fh) = @_;
117
118 if ( !defined($global) ) { return }
119
120 $global->dump($fh);
121 }
122
123 =head2 eprof_reset
124
125 Title : eprof_reset
126 Usage :
127 Function:
128 Example :
129 Returns :
130 Args :
131
132
133 =cut
134
135 sub eprof_reset { undef($global) }
136
137 =head2 dump
138
139 Title : dump
140 Usage :
141 Function:
142 Example :
143 Returns :
144 Args :
145
146
147 =cut
148
149 sub dump {
150 my ( $self, $fh ) = @_;
151
152 my @tags = sort {
153 $self->_tags()->{$a}->total_time()
154 <=> $self->_tags()->{$b}->total_time()
155 } keys %{ $self->_tags() };
156
157 foreach my $tag (@tags) {
158 my $st = $self->_tags->{$tag};
159
160 if ( $st->number() == 0 ) { next }
161
162 my $STD = '---';
163
164 if ( $st->number() > 1 ) {
165 my $SS =
166 $st->total_time_time() -
167 $st->total_time()*$st->total_time()/$st->number();
168
169 if ( $SS > 0 ) {
170 $STD = sprintf( "%6f",
171 sqrt( $SS/$st->number()/( $st->number() - 1 ) )
172 );
173 }
174 }
175
176 print( $fh sprintf( "Eprof: %20s %6f %6f %d %s [%6f,%6f]\n",
177 $st->tag(), $st->total_time(),
178 $st->total_time()/$st->number(), $st->number(),
179 $STD, $st->min_time(),
180 $st->max_time() ) );
181 } ## end foreach my $tag (@tags)
182 } ## end sub dump
183
184 =head2 start
185
186 Title : start
187 Usage : $eprof->start('this_tag');
188 Function:
189 Example :
190 Returns :
191 Args :
192
193
194 =cut
195
196 sub start {
197 my ( $self, $tag ) = @_;
198
199 if ( !defined($tag) ) {
200 $self->throw("No tag, can't start.");
201 }
202
203 if ( !defined( $self->_tags()->{$tag} ) ) {
204 $self->_tags()->{$tag} = Bio::EnsEMBL::Utils::EprofStack->new($tag);
205 }
206
207 $self->_tags()->{$tag}->push_stack();
208 }
209
210 =head2 end
211
212 Title : end
213 Usage : $eprof->end('this_tag');
214 Function:
215 Example :
216 Returns :
217 Args :
218
219
220 =cut
221
222 sub end {
223 my ( $self, $tag ) = @_;
224
225 if ( !defined($tag) ) {
226 $self->throw("No tag, can't end.");
227 }
228
229 if ( !defined( $self->_tags()->{$tag} ) ) {
230 $self->throw(
231 sprintf( "Ending with a nonexistant tag '%s'", $tag ) );
232 }
233
234 $self->_tags->{$tag}->pop_stack();
235 }
236
237 =head2 _tags
238
239 Title : _tags
240 Usage : $obj->_tags($newval)
241 Function:
242 Returns : value of _tags
243 Args : newvalue (optional)
244
245
246 =cut
247
248 sub _tags {
249 my ($obj) = @_;
250 return $obj->{'_tags'};
251 }
252
253 1;
254