mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 21:17:54 +00:00
Use modern (and actually correct on Windows!) API for getting CPU time.
This commit is contained in:
parent
30c03d085e
commit
65159c9961
@ -9,7 +9,9 @@ from __future__ import unicode_literals
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
from time import clock as process_time
|
||||
else:
|
||||
from time import process_time
|
||||
import time
|
||||
|
||||
from twisted.application import service
|
||||
@ -27,7 +29,7 @@ class CPUUsageMonitor(service.MultiService):
|
||||
|
||||
def __init__(self):
|
||||
service.MultiService.__init__(self)
|
||||
# we don't use time.clock() here, because the constructor is run by
|
||||
# we don't use process_time() here, because the constructor is run by
|
||||
# the twistd parent process (as it loads the .tac file), whereas the
|
||||
# rest of the program will be run by the child process, after twistd
|
||||
# forks. Instead, set self.initial_cpu as soon as the reactor starts
|
||||
@ -39,11 +41,11 @@ class CPUUsageMonitor(service.MultiService):
|
||||
TimerService(self.POLL_INTERVAL, self.check).setServiceParent(self)
|
||||
|
||||
def _set_initial_cpu(self):
|
||||
self.initial_cpu = time.clock()
|
||||
self.initial_cpu = process_time()
|
||||
|
||||
def check(self):
|
||||
now_wall = time.time()
|
||||
now_cpu = time.clock()
|
||||
now_cpu = process_time()
|
||||
self.samples.append( (now_wall, now_cpu) )
|
||||
while len(self.samples) > self.HISTORY_LENGTH+1:
|
||||
self.samples.pop(0)
|
||||
@ -68,7 +70,7 @@ class CPUUsageMonitor(service.MultiService):
|
||||
avg = self._average_N_minutes(15)
|
||||
if avg is not None:
|
||||
s["cpu_monitor.15min_avg"] = avg
|
||||
now_cpu = time.clock()
|
||||
now_cpu = process_time()
|
||||
s["cpu_monitor.total"] = now_cpu - self.initial_cpu
|
||||
return s
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user