[web] Enhance query log file
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 18 Nov 2016 18:16:21 +0100
changeset 11872 a997e5451737
parent 11871 5f71460236a4
child 11873 8758b42d6c72
[web] Enhance query log file * Add an overall page generation time * Don't log URL without any query (e.g. static files)
cubicweb/web/application.py
--- a/cubicweb/web/application.py	Thu Nov 24 14:26:12 2016 +0100
+++ b/cubicweb/web/application.py	Fri Nov 18 18:16:21 2016 +0100
@@ -252,15 +252,18 @@
             return set_cnx
 
         req.set_cnx = wrap_set_cnx(req.set_cnx)
+        tstart, cstart = time(), clock()
         try:
             return self.main_handle_request(req)
         finally:
             cnx = req.cnx
-            if cnx:
+            if cnx and cnx.executed_queries:
                 with self._logfile_lock:
+                    tend, cend = time(), clock()
                     try:
                         result = ['\n' + '*' * 80]
-                        result.append(req.url())
+                        result.append('%s -- (%.3f sec, %.3f CPU sec)' % (
+                            req.url(), tend - tstart, cend - cstart))
                         result += ['%s %s -- (%.3f sec, %.3f CPU sec)' % q
                                    for q in cnx.executed_queries]
                         cnx.executed_queries = []