8 clock_thread = time.CLOCK_THREAD_CPUTIME_ID
15 statistics = pdm.perf.staticdir()
16 statistics["req"] = pdm.perf.valueattr(reqstat)
17 requests = pdm.perf.eventobj()
19 class reqstart(pdm.perf.startevent):
20 def __init__(self, env):
22 self.method = env.get("REQUEST_METHOD")
23 self.uri = env.get("REQUEST_URI")
24 self.host = env.get("HTTP_HOST")
25 self.script_uri = env.get("SCRIPT_NAME")
26 self.script_path = env.get("SCRIPT_FILENAME")
27 self.pathinfo = env.get("PATH_INFO")
28 self.querystring = env.get("QUERY_STRING")
29 self.remoteaddr = env.get("REMOTE_ADDR")
30 self.remoteport = env.get("REMOTE_PORT")
31 self.scheme = env.get("wsgi.url_scheme")
32 if clock_thread is not None:
33 self.icpu = time.clock_gettime(clock_thread)
35 class reqfinish(pdm.perf.finishevent):
36 def __init__(self, start, aborted, status):
37 super().__init__(start, aborted)
40 if clock_thread is not None:
41 self.cputime = time.clock_gettime(clock_thread) - start.icpu
43 class request(object):
44 def __init__(self, env):
47 self.startev = reqstart(env)
48 requests.notify(self.startev)
50 def response(self, resp):
53 def finish(self, aborted):
57 if len(self.resp) > 0:
59 if isinstance(status, collections.ByteString):
60 status = status.decode("latin-1")
70 reqstat[key] = reqstat.setdefault(key, 0) + 1
72 requests.notify(reqfinish(self.startev, aborted, status))
77 def __exit__(self, *excinfo):
78 self.finish(bool(excinfo[0]))