cubicweb/pyramid/debugtoolbar_panels.py
author Laurent Peuch <cortex@worlddomination.be>
Thu, 14 Nov 2019 01:01:00 +0100
changeset 12765 771c99f16780
parent 12764 fb97669efcaa
child 12766 682d0790997f
permissions -rw-r--r--
[debug-toolbar] add sql panel Closes #17219873
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     1
# copyright 2019 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     3
#
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     4
# This file is part of CubicWeb.
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     5
#
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     9
# any later version.
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    10
#
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    14
# details.
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    15
#
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    18
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    19
from pyramid_debugtoolbar.panels import DebugPanel
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    20
from cubicweb.debug import subscribe_to_debug_channel, unsubscribe_to_debug_channel
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    21
from cubicweb.misc.source_highlight import highlight_html, generate_css
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    22
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    23
12764
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    24
class CubicWebDebugPanel(DebugPanel):
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    25
    """
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    26
    CubicWeb general debug panel
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    27
    """
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    28
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    29
    """
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    30
    Excepted formats:
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    31
    Controller: {
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    32
        "kind": ctrlid,
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    33
        "request": req,
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    34
        "path": req.path,
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    35
        "controller": controller,
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    36
    }
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    37
    """
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    38
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    39
    name = 'CubicWeb'
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    40
    nav_title = 'CubicWeb'
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    41
    title = 'CubicWeb general panel'
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    42
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    43
    has_content = True
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    44
    template = 'cubicweb.pyramid:debug_toolbar_templates/cw.dbtmako'
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    45
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    46
    def __init__(self, request):
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    47
        self.data = {'controller': None}
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    48
        subscribe_to_debug_channel("controller", self.collect_controller)
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    49
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    50
    def collect_controller(self, controller):
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    51
        self.data["controller"] = controller
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    52
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    53
    def process_response(self, response):
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    54
        unsubscribe_to_debug_channel("controller", self.collect_controller)
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    55
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
    56
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    57
class RQLDebugPanel(DebugPanel):
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    58
    """
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    59
    CubicWeb RQL debug panel
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    60
    """
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    61
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    62
    """
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    63
    Excepted formats:
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    64
    SQL: {
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    65
        'rql_query_tracing_token': 'some_token',
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    66
        'args': {dict with some args},
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    67
        'rollback': False|True,
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    68
        'time': time_in_float,
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    69
        'sql':_sql_query_as_a_string,
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    70
    }
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    71
    """
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    72
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    73
    name = 'RQL'
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    74
    title = 'RQL queries'
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    75
    nav_title = 'RQL'
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    76
    nav_subtitle_style = 'progress-bar-info'
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    77
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    78
    has_content = True
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    79
    template = 'cubicweb.pyramid:debug_toolbar_templates/rql.dbtmako'
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    80
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    81
    def __init__(self, request):
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    82
        self.data = {
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    83
            'rql_queries': [],
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    84
            'sql_queries': [],
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    85
            'highlight': highlight_html,
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    86
            'generate_css': generate_css,
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    87
        }
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    88
        subscribe_to_debug_channel("rql", self.collect_rql_queries)
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    89
        subscribe_to_debug_channel("sql", self.collect_sql_queries)
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    90
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    91
    @property
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    92
    def nav_subtitle(self):
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    93
        return '%d' % len(self.data['rql_queries'])
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    94
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    95
    def collect_rql_queries(self, rql_query):
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    96
        rql_query["generated_sql_queries"] = []
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    97
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    98
        # link sql queries to rql's one
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
    99
        for sql_query in self.data["sql_queries"]:
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   100
            if sql_query["rql_query_tracing_token"] == rql_query["rql_query_tracing_token"]:
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   101
                rql_query["generated_sql_queries"].append(sql_query)
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   102
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   103
        self.data["rql_queries"].append(rql_query)
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   104
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   105
    def collect_sql_queries(self, sql_query):
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   106
        self.data["sql_queries"].append(sql_query)
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   107
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   108
    def process_response(self, response):
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   109
        unsubscribe_to_debug_channel("rql", self.collect_rql_queries)
12761
10b8352b0208 [debug-toolbar/rql] display sql queries generated by rql ones
Laurent Peuch <cortex@worlddomination.be>
parents: 12760
diff changeset
   110
        unsubscribe_to_debug_channel("sql", self.collect_sql_queries)
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   111
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   112
12765
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   113
class SQLDebugPanel(DebugPanel):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   114
    """
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   115
    CubicWeb SQL debug panel
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   116
    """
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   117
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   118
    """
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   119
    Excepted formats:
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   120
    SQL: {
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   121
        'rql_query_tracing_token': 'some_token',
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   122
        'args': {dict with some args},
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   123
        'rollback': False|True,
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   124
        'time': time_in_float,
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   125
        'sql':_sql_query_as_a_string,
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   126
    }
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   127
    """
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   128
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   129
    name = 'SQL'
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   130
    title = 'SQL queries'
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   131
    nav_title = 'SQL'
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   132
    nav_subtitle_style = 'progress-bar-info'
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   133
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   134
    has_content = True
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   135
    template = 'cubicweb.pyramid:debug_toolbar_templates/sql.dbtmako'
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   136
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   137
    def __init__(self, request):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   138
        self.data = {
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   139
            'rql_queries': [],
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   140
            'sql_queries': [],
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   141
            'highlight': highlight_html,
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   142
            'generate_css': generate_css,
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   143
        }
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   144
        subscribe_to_debug_channel("rql", self.collect_rql_queries)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   145
        subscribe_to_debug_channel("sql", self.collect_sql_queries)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   146
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   147
    @property
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   148
    def nav_subtitle(self):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   149
        return len(self.data['sql_queries'])
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   150
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   151
    def collect_rql_queries(self, rql_query):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   152
        self.data["rql_queries"].append(rql_query)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   153
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   154
        # link sql queries to rql's one
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   155
        for sql_query in self.data["sql_queries"]:
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   156
            if sql_query["rql_query_tracing_token"] == rql_query["rql_query_tracing_token"]:
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   157
                sql_query["from_rql_query"] = rql_query
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   158
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   159
    def collect_sql_queries(self, sql_query):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   160
        sql_query["from_rql_query"] = None
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   161
        self.data["sql_queries"].append(sql_query)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   162
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   163
    def process_response(self, response):
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   164
        unsubscribe_to_debug_channel("rql", self.collect_rql_queries)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   165
        unsubscribe_to_debug_channel("sql", self.collect_sql_queries)
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   166
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   167
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   168
def includeme(config):
12764
fb97669efcaa [debug-toolbar] add cw general panel with controller
Laurent Peuch <cortex@worlddomination.be>
parents: 12763
diff changeset
   169
    config.add_debugtoolbar_panel(CubicWebDebugPanel)
12760
d5ae5abd0876 [debug-toolbar/rql] add RQL panel
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
   170
    config.add_debugtoolbar_panel(RQLDebugPanel)
12765
771c99f16780 [debug-toolbar] add sql panel
Laurent Peuch <cortex@worlddomination.be>
parents: 12764
diff changeset
   171
    config.add_debugtoolbar_panel(SQLDebugPanel)