From ee5b91f30ff0fb3f7e8c9cea9abeabadf1a982f7 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Fri, 13 May 2016 15:42:20 +0200 Subject: [PATCH] python3: Use higher-resolution CPU timer. --- python3/ashd/perf.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/python3/ashd/perf.py b/python3/ashd/perf.py index 3b8f63b..86fe43c 100644 --- a/python3/ashd/perf.py +++ b/python3/ashd/perf.py @@ -4,10 +4,10 @@ try: except: pdm = None try: - import resource - ru_thread = resource.RUSAGE_THREAD + import time + clock_thread = time.CLOCK_THREAD_CPUTIME_ID except: - ru_thread = None + clock_thread = None reqstat = {} @@ -29,18 +29,16 @@ if pdm: self.remoteaddr = env.get("REMOTE_ADDR") self.remoteport = env.get("REMOTE_PORT") self.scheme = env.get("wsgi.url_scheme") - if ru_thread is not None: - ru = resource.getrusage(ru_thread) - self.icpu = ru.ru_utime + ru.ru_stime + if clock_thread is not None: + self.icpu = time.clock_gettime(clock_thread) class reqfinish(pdm.perf.finishevent): def __init__(self, start, aborted, status): super().__init__(start, aborted) self.status = status self.cputime = 0 - if ru_thread is not None: - ru = resource.getrusage(ru_thread) - self.cputime = ru.ru_utime + ru.ru_stime - start.icpu + if clock_thread is not None: + self.cputime = time.clock_gettime(clock_thread) - start.icpu class request(object): def __init__(self, env): -- 2.11.0