Skip to content

Commit eb0e8cb

Browse files
committed
Add qb debug panel
1 parent d75b630 commit eb0e8cb

File tree

4 files changed

+129
-6
lines changed

4 files changed

+129
-6
lines changed

ModuleConfig.cfc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,19 @@ component {
6464
// Register the interceptor, it has to be here due to loading of configuration files.
6565
controller
6666
.getInterceptorService()
67-
.registerInterceptor(
67+
.registerInterceptor(
6868
interceptorClass = "#moduleMapping#.interceptors.Debugger",
6969
interceptorName = "debugger@cbdebugger"
7070
);
71+
72+
if ( settings.debugger.showQBPanel && controller.getModuleService().isModuleRegistered( "qb" ) ) {
73+
controller
74+
.getInterceptorService()
75+
.registerInterceptor(
76+
interceptorClass = "#moduleMapping#.interceptors.QBCollector",
77+
interceptorName = "QBCollector@cbdebugger"
78+
);
79+
}
7180
}
7281

7382
/**
@@ -76,12 +85,12 @@ component {
7685
function onUnload(){
7786
// unregister interceptor
7887
controller.getInterceptorService().unregister( interceptorName="debugger@cbdebugger" );
79-
88+
8089
// Remove application helper
8190
var appHelperArray = controller.getSetting( "ApplicationHelper" );
8291
var mixinToRemove = "#moduleMapping#/models/Mixins.cfm";
8392
var mixinIndex = arrayFindNoCase( appHelperArray, mixinToRemove );
84-
93+
8594
// If the mixin is in the array
8695
if( mixinIndex ) {
8796
// Remove it
@@ -117,14 +126,16 @@ component {
117126
expandedRCPanel = false,
118127
showModulesPanel = true,
119128
expandedModulesPanel = false,
129+
showQBPanel = true,
130+
expandedQBPanel = false,
120131
showRCSnapshots = false,
121132
wireboxCreationProfiler=false
122133
};
123134

124135
// incorporate settings
125136
structAppend( configStruct.debugger, debuggerDSL, true );
126137
}
127-
138+
128139
// This appender is part of a module, so we need to register it after the modules have been loaded.
129140
function afterConfigurationLoad() {
130141
var logBox = controller.getLogBox();
@@ -139,6 +150,6 @@ component {
139150
root.addAppender( appenders[ 'tracer' ] );
140151
root.setLevelMax( 4 );
141152
root.setLevelMin( 0 );
142-
153+
143154
}
144155
}

includes/debug.cfm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,15 @@ Description :
302302
</div>
303303
</cfif>
304304

305+
<!--- **************************************************************--->
306+
<!--- qb debug --->
307+
<!--- **************************************************************--->
308+
<cfif instance.debuggerConfig.showQBPanel>
309+
<cfinclude template="panels/qbPanel.cfm">
310+
</cfif>
311+
305312
<div class="fw_renderTime">Approximate Debug Rendering Time: #GetTickCount()-DebugStartTime# ms</div>
306313

307314
</div>
308315
</cfoutput>
309-
<cfsetting enablecfoutputonly=false>
316+
<cfsetting enablecfoutputonly=false>

includes/panels/qbPanel.cfm

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<cfsetting enablecfoutputonly="true">
2+
<!-----------------------------------------------------------------------
3+
********************************************************************************
4+
Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
5+
www.coldbox.org | www.luismajano.com | www.ortussolutions.com
6+
********************************************************************************
7+
8+
Template : debug.cfm
9+
Author : Luis Majano
10+
Date : September 25, 2005
11+
Description :
12+
Debugging template for the application
13+
----------------------------------------------------------------------->
14+
<cfoutput>
15+
<div class="fw_titles" onClick="fw_toggle('fw_qbPanel')" >
16+
&nbsp;qb
17+
</div>
18+
<div class="fw_debugContent<cfif instance.debuggerConfig.expandedQBPanel>View</cfif>" id="fw_qbPanel">
19+
<cfif NOT getController().getModuleService().isModuleRegistered( "qb" )>
20+
qb is not installed or registered.
21+
<cfelse>
22+
<cfif NOT request.cbdebugger.keyExists( "qbQueries" ) OR request.cbdebugger.qbQueries.isEmpty()>
23+
No queries executed
24+
<cfelse>
25+
<table border="0" align="center" cellpadding="0" cellspacing="1" class="fw_debugTables">
26+
<thead>
27+
<tr>
28+
<th width="5%">Count</th>
29+
<th>Query</th>
30+
</tr>
31+
</thead>
32+
<tbody>
33+
<cfloop array="#request.cbdebugger.qbQueries.keyArray()#" index="sql">
34+
<tr>
35+
<td align="center">#request.cbdebugger.qbQueries[ sql ].len()#</td>
36+
<td>#sql#</td>
37+
</tr>
38+
<tr style="margin-right: 2em;">
39+
<td></td>
40+
<td style="width: 100%;">
41+
<table border="0" align="center" cellpadding="0" cellspacing="1" class="fw_debugTables">
42+
<thead>
43+
<tr>
44+
<th>Timestamp</th>
45+
<th>Execution Time</th>
46+
<th>Bindings</th>
47+
</tr>
48+
</thead>
49+
<tbody>
50+
<cfloop array="#request.cbdebugger.qbQueries[ sql ]#" index="q">
51+
<tr>
52+
<td>#TimeFormat(q.timestamp,"hh:MM:SS.l tt")#</td>
53+
<td>#q.executionTime# ms</td>
54+
<td><cfdump var="#q.bindings#" expand="false" /></td>
55+
</tr>
56+
</cfloop>
57+
</tbody>
58+
</table>
59+
</td>
60+
</tr>
61+
</cfloop>
62+
</tbody>
63+
</table>
64+
<!--- <table border="0" align="center" cellpadding="0" cellspacing="1" class="fw_debugTables">
65+
<thead>
66+
<tr>
67+
<th>Timestamp</th>
68+
<th width="80%">Query</th>
69+
<th align="center">Execution Time</th>
70+
<th>Bindings</th>
71+
</tr>
72+
</thead>
73+
<tbody>
74+
<cfloop array="#request.cbdebugger.qbQueries#" index="q">
75+
<tr <cfif debugTimers.currentrow mod 2 eq 0>class="even"</cfif>>
76+
<td>#TimeFormat(q.timestamp,"hh:MM:SS.l tt")#</td>
77+
<td>#q.sql#</td>
78+
<td>#q.executionTime# ms</td>
79+
<td><cfdump var="#q.bindings#" expand="false" /></td>
80+
</tr>
81+
</cfloop>
82+
</tbody>
83+
</table> --->
84+
</cfif>
85+
</cfif>
86+
</div>
87+
</cfoutput>
88+
<cfsetting enablecfoutputonly="false">

interceptors/QBCollector.cfc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* QB Collector Interecptor
3+
*/
4+
component extends="coldbox.system.Interceptor"{
5+
6+
// Before we capture.
7+
function postQBExecute( event, interceptData, rc, prc ) {
8+
param request.cbdebugger = {};
9+
param request.cbdebugger.qbQueries = {};
10+
if ( !structKeyExists( request.cbdebugger.qbQueries, arguments.interceptData.sql ) ) {
11+
request.cbdebugger.qbQueries[ arguments.interceptData.sql ] = [];
12+
}
13+
arguments.interceptData.timestamp = now();
14+
request.cbdebugger.qbQueries[ arguments.interceptData.sql ].append( arguments.interceptData )
15+
}
16+
17+
}

0 commit comments

Comments
 (0)