14 # details. |
14 # details. |
15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 |
18 |
|
19 from collections import defaultdict |
|
20 |
19 from pyramid_debugtoolbar.panels import DebugPanel |
21 from pyramid_debugtoolbar.panels import DebugPanel |
20 from cubicweb.debug import subscribe_to_debug_channel, unsubscribe_to_debug_channel |
22 from cubicweb.debug import subscribe_to_debug_channel, unsubscribe_to_debug_channel |
21 from cubicweb.misc.source_highlight import highlight_html, generate_css |
23 from cubicweb.misc.source_highlight import highlight_html, generate_css |
22 |
24 |
23 |
25 |
24 class RQLDebugPanel(DebugPanel): |
26 class RQLDebugPanel(DebugPanel): |
25 """ |
27 """ |
26 CubicWeb RQL debug panel |
28 CubicWeb RQL debug panel |
27 """ |
29 """ |
|
30 |
|
31 """ |
|
32 Excepted formats: |
|
33 SQL: { |
|
34 'rql_query_tracing_token': 'some_token', |
|
35 'args': {dict with some args}, |
|
36 'rollback': False|True, |
|
37 'time': time_in_float, |
|
38 'sql':_sql_query_as_a_string, |
|
39 } |
|
40 """ |
|
41 |
28 name = 'RQL' |
42 name = 'RQL' |
29 title = 'RQL queries' |
43 title = 'RQL queries' |
30 nav_title = 'RQL' |
44 nav_title = 'RQL' |
31 nav_subtitle_style = 'progress-bar-info' |
45 nav_subtitle_style = 'progress-bar-info' |
32 |
46 |
34 template = 'cubicweb.pyramid:debug_toolbar_templates/rql.dbtmako' |
48 template = 'cubicweb.pyramid:debug_toolbar_templates/rql.dbtmako' |
35 |
49 |
36 def __init__(self, request): |
50 def __init__(self, request): |
37 self.data = { |
51 self.data = { |
38 'rql_queries': [], |
52 'rql_queries': [], |
|
53 'sql_queries': [], |
39 'highlight': highlight_html, |
54 'highlight': highlight_html, |
40 'generate_css': generate_css, |
55 'generate_css': generate_css, |
41 } |
56 } |
42 subscribe_to_debug_channel("rql", self.collect_rql_queries) |
57 subscribe_to_debug_channel("rql", self.collect_rql_queries) |
|
58 subscribe_to_debug_channel("sql", self.collect_sql_queries) |
43 |
59 |
44 @property |
60 @property |
45 def nav_subtitle(self): |
61 def nav_subtitle(self): |
46 return '%d' % len(self.data['rql_queries']) |
62 return '%d' % len(self.data['rql_queries']) |
47 |
63 |
48 def collect_rql_queries(self, rql_query): |
64 def collect_rql_queries(self, rql_query): |
|
65 rql_query["generated_sql_queries"] = [] |
|
66 |
|
67 # link sql queries to rql's one |
|
68 for sql_query in self.data["sql_queries"]: |
|
69 if sql_query["rql_query_tracing_token"] == rql_query["rql_query_tracing_token"]: |
|
70 rql_query["generated_sql_queries"].append(sql_query) |
|
71 |
49 self.data["rql_queries"].append(rql_query) |
72 self.data["rql_queries"].append(rql_query) |
|
73 |
|
74 def collect_sql_queries(self, sql_query): |
|
75 self.data["sql_queries"].append(sql_query) |
50 |
76 |
51 def process_response(self, response): |
77 def process_response(self, response): |
52 unsubscribe_to_debug_channel("rql", self.collect_rql_queries) |
78 unsubscribe_to_debug_channel("rql", self.collect_rql_queries) |
|
79 unsubscribe_to_debug_channel("sql", self.collect_sql_queries) |
53 |
80 |
54 |
81 |
55 def includeme(config): |
82 def includeme(config): |
56 config.add_debugtoolbar_panel(RQLDebugPanel) |
83 config.add_debugtoolbar_panel(RQLDebugPanel) |