1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 The I{metrics} module defines classes and other resources
18 designed for collecting and reporting performance metrics.
19 """
20
21 import time
22 from math import modf
23
25
26 - def __init__(self, started=0, stopped=0):
29
31 self.started = time.time()
32 self.stopped = 0
33 return self
34
36 if self.started > 0:
37 self.stopped = time.time()
38 return self
39
41 return ( self.stopped - self.started )
42
44 if self.started == 0:
45 return 'not-running'
46 if self.started > 0 and self.stopped == 0:
47 return 'started: %d (running)' % self.started
48 duration = self.duration()
49 jmod = ( lambda m : (m[1], m[0]*1000) )
50 if duration < 1:
51 ms = (duration*1000)
52 return '%d (ms)' % ms
53 if duration < 60:
54 m = modf(duration)
55 return '%d.%.3d (seconds)' % jmod(m)
56 m = modf(duration/60)
57 return '%d.%.3d (minutes)' % jmod(m)
58