1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
30
32 self.started = 0
33 self.stopped = 0
34
36 self.started = time.time()
37 self.stopped = 0
38 return self
39
41 if self.started > 0:
42 self.stopped = time.time()
43 return self
44
46 return ( self.stopped - self.started )
47
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