python: Added more info to perf request objects.
authorFredrik Tolf <fredrik@dolda2000.com>
Thu, 12 May 2016 17:01:44 +0000 (19:01 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Thu, 12 May 2016 17:01:44 +0000 (19:01 +0200)
python/ashd/perf.py
python3/ashd/perf.py

index 97146a8..c74e443 100644 (file)
@@ -16,8 +16,13 @@ if pdm:
             self.method = env.get("REQUEST_METHOD")
             self.uri = env.get("REQUEST_URI")
             self.host = env.get("HTTP_HOST")
+            self.script_uri = env.get("SCRIPT_NAME")
+            self.script_path = env.get("SCRIPT_FILENAME")
+            self.pathinfo = env.get("PATH_INFO")
+            self.querystring = env.get("QUERY_STRING")
             self.remoteaddr = env.get("REMOTE_ADDR")
             self.remoteport = env.get("REMOTE_PORT")
+            self.scheme = env.get("wsgi.url_scheme")
 
     class reqfinish(pdm.perf.finishevent):
         def __init__(self, start, aborted, status):
index 6942424..3b8f63b 100644 (file)
@@ -3,6 +3,11 @@ try:
     import pdm.perf
 except:
     pdm = None
+try:
+    import resource
+    ru_thread = resource.RUSAGE_THREAD
+except:
+    ru_thread = None
 
 reqstat = {}
 
@@ -17,13 +22,25 @@ if pdm:
             self.method = env.get("REQUEST_METHOD")
             self.uri = env.get("REQUEST_URI")
             self.host = env.get("HTTP_HOST")
+            self.script_uri = env.get("SCRIPT_NAME")
+            self.script_path = env.get("SCRIPT_FILENAME")
+            self.pathinfo = env.get("PATH_INFO")
+            self.querystring = env.get("QUERY_STRING")
             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
 
     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
 
 class request(object):
     def __init__(self, env):