--- a/cubicweb/pyramid/debugtoolbar_panels.py Wed Jul 31 04:16:20 2019 +0200
+++ b/cubicweb/pyramid/debugtoolbar_panels.py Thu Aug 01 20:30:16 2019 +0200
@@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
+from collections import defaultdict
+
from pyramid_debugtoolbar.panels import DebugPanel
from cubicweb.debug import subscribe_to_debug_channel, unsubscribe_to_debug_channel
from cubicweb.misc.source_highlight import highlight_html, generate_css
@@ -25,6 +27,18 @@
"""
CubicWeb RQL debug panel
"""
+
+ """
+ Excepted formats:
+ SQL: {
+ 'rql_query_tracing_token': 'some_token',
+ 'args': {dict with some args},
+ 'rollback': False|True,
+ 'time': time_in_float,
+ 'sql':_sql_query_as_a_string,
+ }
+ """
+
name = 'RQL'
title = 'RQL queries'
nav_title = 'RQL'
@@ -36,20 +50,33 @@
def __init__(self, request):
self.data = {
'rql_queries': [],
+ 'sql_queries': [],
'highlight': highlight_html,
'generate_css': generate_css,
}
subscribe_to_debug_channel("rql", self.collect_rql_queries)
+ subscribe_to_debug_channel("sql", self.collect_sql_queries)
@property
def nav_subtitle(self):
return '%d' % len(self.data['rql_queries'])
def collect_rql_queries(self, rql_query):
+ rql_query["generated_sql_queries"] = []
+
+ # link sql queries to rql's one
+ for sql_query in self.data["sql_queries"]:
+ if sql_query["rql_query_tracing_token"] == rql_query["rql_query_tracing_token"]:
+ rql_query["generated_sql_queries"].append(sql_query)
+
self.data["rql_queries"].append(rql_query)
+ def collect_sql_queries(self, sql_query):
+ self.data["sql_queries"].append(sql_query)
+
def process_response(self, response):
unsubscribe_to_debug_channel("rql", self.collect_rql_queries)
+ unsubscribe_to_debug_channel("sql", self.collect_sql_queries)
def includeme(config):