]> git.pld-linux.org Git - projects/pld-builder.new.git/blame - PLD_Builder/stopwatch.py
Switch to https for client/request handler server and between builders communication...
[projects/pld-builder.new.git] / PLD_Builder / stopwatch.py
CommitLineData
dfff8bd5
MM
1# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
93b720ea
MM
3import time
4import resource
5
6class Time:
dfff8bd5
MM
7 def __init__(self):
8 x = resource.getrusage(resource.RUSAGE_CHILDREN)
9 self.user_time = x[0]
10 self.sys_time = x[1]
11 self.non_io_faults = x[6]
12 self.io_faults = x[7]
13 self.time = time.time()
14
15 def sub(self, x):
16 self.user_time -= x.user_time
17 self.sys_time -= x.sys_time
18 self.non_io_faults -= x.non_io_faults
19 self.io_faults -= x.io_faults
20 self.time -= x.time
21
22 def format(self):
23 return "user:%.2fs sys:%.2fs real:%.2fs (faults io:%d non-io:%d)" % \
e6376553 24 (self.user_time, self.sys_time, self.time, self.io_faults,
93b720ea 25 self.non_io_faults)
e6376553 26
93b720ea 27class Timer:
dfff8bd5
MM
28 def __init__(self):
29 self.starts = []
93b720ea 30
dfff8bd5
MM
31 def start(self):
32 self.starts.append(Time())
93b720ea 33
dfff8bd5
MM
34 def stop(self):
35 tmp = Time()
36 tmp.sub(self.starts.pop())
37 return tmp.format()
93b720ea
MM
38
39t = Timer()
40
41def start():
dfff8bd5 42 t.start()
93b720ea
MM
43
44def stop():
dfff8bd5 45 return t.stop()
This page took 0.572851 seconds and 4 git commands to generate.