Package suds :: Module metrics
[hide private]
[frames] | no frames]

Source Code for Module suds.metrics

 1  # This program is free software; you can redistribute it and/or modify 
 2  # it under the terms of the (LGPL) GNU Lesser General Public License as 
 3  # published by the Free Software Foundation; either version 3 of the  
 4  # License, or (at your option) any later version. 
 5  # 
 6  # This program is distributed in the hope that it will be useful, 
 7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 9  # GNU Library Lesser General Public License for more details at 
10  # ( http://www.gnu.org/licenses/lgpl.html ). 
11  # 
12  # You should have received a copy of the GNU Lesser General Public License 
13  # along with this program; if not, write to the Free Software 
14  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
15  # written by: Jeff Ortel ( jortel@redhat.com ) 
16   
17  """ 
18  The I{metrics} module defines classes and other resources 
19  designed for collecting and reporting performance metrics. 
20  """ 
21   
22  import time 
23  from logging import getLogger 
24  from suds import * 
25  from math import modf 
26   
27  log = getLogger(__name__) 
28   
29 -class Timer:
30
31 - def __init__(self):
32 self.started = 0 33 self.stopped = 0
34
35 - def start(self):
36 self.started = time.time() 37 self.stopped = 0 38 return self
39
40 - def stop(self):
41 if self.started > 0: 42 self.stopped = time.time() 43 return self
44
45 - def duration(self):
46 return ( self.stopped - self.started )
47
48 - def __str__(self):
49 if self.started == 0: 50 return 'not-running' 51 if self.started > 0 and self.stopped == 0: 52 return 'started: %d (running)' % self.started 53 duration = self.duration() 54 jmod = ( lambda m : (m[1], m[0]*1000) ) 55 if duration < 1: 56 ms = (duration*1000) 57 return '%d (ms)' % ms 58 if duration < 60: 59 m = modf(duration) 60 return '%d.%.3d (seconds)' % jmod(m) 61 m = modf(duration/60) 62 return '%d.%.3d (minutes)' % jmod(m)
63