10 statistics = pdm.perf.staticdir()
11 statistics["req"] = pdm.perf.valueattr(reqstat)
12 requests = pdm.perf.eventobj()
14 class reqstart(pdm.perf.startevent):
15 def __init__(self, env):
17 self.method = env.get("REQUEST_METHOD")
18 self.uri = env.get("REQUEST_URI")
19 self.host = env.get("HTTP_HOST")
20 self.remoteaddr = env.get("REMOTE_ADDR")
21 self.remoteport = env.get("REMOTE_PORT")
23 class reqfinish(pdm.perf.finishevent):
24 def __init__(self, start, aborted, status):
25 super().__init__(start, aborted)
28 class request(object):
29 def __init__(self, env):
32 self.startev = reqstart(env)
33 requests.notify(self.startev)
35 def response(self, resp):
38 def finish(self, aborted):
42 if len(self.resp) > 0:
44 if isinstance(status, collections.ByteString):
45 status = status.decode("latin-1")
55 reqstat[key] = reqstat.setdefault(key, 0) + 1
57 requests.notify(reqfinish(self.startev, aborted, status))
62 def __exit__(self, *excinfo):
63 self.finish(bool(excinfo[0]))