Skip to content

Commit c4035ef

Browse files
authored
Merge pull request #21 from coldbox-modules/add_qb_and_quick
Add qb and quick panel
2 parents d75b630 + 53bc8f0 commit c4035ef

File tree

10 files changed

+275
-12
lines changed

10 files changed

+275
-12
lines changed

ModuleConfig.cfc

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,28 @@ 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+
}
80+
81+
if ( settings.debugger.showQBPanel && controller.getModuleService().isModuleRegistered( "quick" ) ) {
82+
controller
83+
.getInterceptorService()
84+
.registerInterceptor(
85+
interceptorClass = "#moduleMapping#.interceptors.QuickCollector",
86+
interceptorName = "QuickCollector@cbdebugger"
87+
);
88+
}
7189
}
7290

7391
/**
@@ -76,12 +94,12 @@ component {
7694
function onUnload(){
7795
// unregister interceptor
7896
controller.getInterceptorService().unregister( interceptorName="debugger@cbdebugger" );
79-
97+
8098
// Remove application helper
8199
var appHelperArray = controller.getSetting( "ApplicationHelper" );
82100
var mixinToRemove = "#moduleMapping#/models/Mixins.cfm";
83101
var mixinIndex = arrayFindNoCase( appHelperArray, mixinToRemove );
84-
102+
85103
// If the mixin is in the array
86104
if( mixinIndex ) {
87105
// Remove it
@@ -117,14 +135,16 @@ component {
117135
expandedRCPanel = false,
118136
showModulesPanel = true,
119137
expandedModulesPanel = false,
138+
showQBPanel = true,
139+
expandedQBPanel = false,
120140
showRCSnapshots = false,
121141
wireboxCreationProfiler=false
122142
};
123143

124144
// incorporate settings
125145
structAppend( configStruct.debugger, debuggerDSL, true );
126146
}
127-
147+
128148
// This appender is part of a module, so we need to register it after the modules have been loaded.
129149
function afterConfigurationLoad() {
130150
var logBox = controller.getLogBox();
@@ -139,6 +159,6 @@ component {
139159
root.addAppender( appenders[ 'tracer' ] );
140160
root.setLevelMax( 4 );
141161
root.setLevelMin( 0 );
142-
162+
143163
}
144164
}

includes/css/cbox-debugger.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
cursor: pointer;
2828
color: black;
2929
}
30+
.fw_subtitles{
31+
font-size: 10px;
32+
font-weight: bold;
33+
color: black;
34+
border:1px solid #D3D3D3;
35+
background: #D7EBF9;
36+
padding:5px 5px 5px 5px;
37+
margin-bottom: 2px;
38+
-moz-border-radius: 5px;
39+
-webkit-border-radius: 5px;
40+
-khtml-border-radius: 5px;
41+
}
3042
.fw_profilers{
3143
font-size: 10px;
3244
font-weight:bold;
@@ -209,3 +221,30 @@
209221
background-color: #FFF6CC;
210222
border: 1px solid #999999;
211223
}
224+
.fw_badge_light{
225+
display: inline-block;
226+
padding: .25em .4em;
227+
font-weight: 700;
228+
line-height: 1;
229+
text-align: center;
230+
white-space: nowrap;
231+
vertical-align: baseline;
232+
border-radius: .25rem;
233+
color: black;
234+
background: #D7EBF9;
235+
border:1px solid #D3D3D3;
236+
}
237+
238+
.fw_badge_dark{
239+
display: inline-block;
240+
padding: .25em .4em;
241+
font-weight: 700;
242+
line-height: 1;
243+
text-align: center;
244+
white-space: nowrap;
245+
vertical-align: baseline;
246+
border-radius: .25rem;
247+
color: white;
248+
border: 1px solid #2694E8;
249+
background: #3BAAE3;
250+
}

includes/css/cbox-debugger.pack.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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/js/cbox-debugger.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,14 @@ function fw_toggleDiv(targetDiv, displayStyle){
6565
else{
6666
target.style.display = displayStyle;
6767
}
68-
}
68+
}
69+
70+
function fw_showGroupedQueries() {
71+
fw_toggleDiv("timelineQueries", "none");
72+
fw_toggleDiv("groupedQueries", "block");
73+
}
74+
75+
function fw_showTimelineQueries() {
76+
fw_toggleDiv("groupedQueries", "none");
77+
fw_toggleDiv("timelineQueries", "block");
78+
}

includes/js/cbox-debugger.pack.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/panels/qbPanel.cfm

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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+
<cfscript>
15+
var isQuickInstalled = getController().getModuleService().isModuleRegistered( "quick" );
16+
var isQBInstalled = getController().getModuleService().isModuleRegistered( "qb" );
17+
var totalQueries = request.cbdebugger.keyExists( "qbQueries" ) ? request.cbdebugger.qbQueries.all.len() : 0;
18+
var totalExecutionTime = !request.cbdebugger.keyExists( "qbQueries" ) ? 0 : request.cbdebugger.qbQueries.all.reduce( function( total, q ) {
19+
return total + q.executionTime;
20+
}, 0 );
21+
var totalEntities = request.cbdebugger.keyExists( "quick" ) ? request.cbdebugger.quick.total : 0;
22+
</cfscript>
23+
<cfoutput>
24+
<div class="fw_titles" onClick="fw_toggle('fw_qbPanel')" >
25+
&nbsp;<cfif isQuickInstalled>Quick &##47; </cfif>qb
26+
</div>
27+
<div class="fw_debugContent<cfif instance.debuggerConfig.expandedQBPanel>View</cfif>" id="fw_qbPanel">
28+
<div id="qbQueries">
29+
<cfif NOT isQBInstalled>
30+
qb is not installed or registered.
31+
<cfelse>
32+
<div class="fw_subtitles">&nbsp;Queries <span class="fw_badge_dark" style="margin-left: 1em;">#totalQueries#</span></div>
33+
<div style="padding: 1em;">
34+
<input type="button" style="font-size:10px" value="Grouped View" onClick="fw_showGroupedQueries()">
35+
<input type="button" style="font-size:10px" value="Timeline View" onClick="fw_showTimelineQueries()">
36+
</div>
37+
<cfif totalQueries EQ 0>
38+
No queries executed
39+
<cfelse>
40+
<div id="groupedQueries">
41+
<table border="0" align="center" cellpadding="0" cellspacing="1" class="fw_debugTables">
42+
<thead>
43+
<tr>
44+
<th width="5%">Count</th>
45+
<th>Query</th>
46+
</tr>
47+
</thead>
48+
<tbody>
49+
<cfloop array="#request.cbdebugger.qbQueries.grouped.keyArray()#" index="sql">
50+
<tr>
51+
<td align="center">#request.cbdebugger.qbQueries.grouped[ sql ].len()#</td>
52+
<td>#sql#</td>
53+
</tr>
54+
<tr style="margin-right: 2em;">
55+
<td></td>
56+
<td style="width: 100%;">
57+
<table border="0" align="center" cellpadding="0" cellspacing="1" class="fw_debugTables">
58+
<thead>
59+
<tr>
60+
<th width="15%">Timestamp</th>
61+
<th width="15%">Execution Time</th>
62+
<th>Bindings</th>
63+
</tr>
64+
</thead>
65+
<tbody>
66+
<cfloop array="#request.cbdebugger.qbQueries.grouped[ sql ]#" index="q">
67+
<tr>
68+
<td>#TimeFormat(q.timestamp,"hh:MM:SS.l tt")#</td>
69+
<td>#q.executionTime# ms</td>
70+
<td>
71+
<cfif NOT q.bindings.isEmpty()>
72+
<cfdump var="#q.bindings#" expand="false" />
73+
</cfif>
74+
</td>
75+
</tr>
76+
</cfloop>
77+
</tbody>
78+
</table>
79+
</td>
80+
</tr>
81+
</cfloop>
82+
</tbody>
83+
</table>
84+
</div>
85+
<div id="timelineQueries" style="display: none;">
86+
<table border="0" align="center" cellpadding="0" cellspacing="1" class="fw_debugTables">
87+
<thead>
88+
<tr>
89+
<th>Timestamp</th>
90+
<th width="80%">Query</th>
91+
<th align="center">Execution Time</th>
92+
<th>Bindings</th>
93+
</tr>
94+
</thead>
95+
<tbody>
96+
<cfloop array="#request.cbdebugger.qbQueries.all#" index="q">
97+
<tr>
98+
<td>#TimeFormat(q.timestamp,"hh:MM:SS.l tt")#</td>
99+
<td>#q.sql#</td>
100+
<td>#q.executionTime# ms</td>
101+
<td><cfdump var="#q.bindings#" expand="false" /></td>
102+
</tr>
103+
</cfloop>
104+
</tbody>
105+
</table>
106+
</div>
107+
<div style="margin-top: 0.5em; margin-left: 1em;">
108+
<div class="fw_debugTitleCell">
109+
Total Execution Time:
110+
</div>
111+
<div class="fw_debugContentCell">
112+
#totalExecutionTime# ms
113+
</div>
114+
</div>
115+
</cfif>
116+
</cfif>
117+
</div>
118+
<cfif isQuickInstalled>
119+
<hr />
120+
<div id="quickEntities" style="margin-top: 1em;">
121+
<div class="fw_subtitles">&nbsp;Entities <span class="fw_badge_dark" style="margin-left: 1em;">#totalEntities#</span></div>
122+
<cfif totalEntities EQ 0>
123+
No Quick entities loaded.
124+
<cfelse>
125+
<table border="0" align="center" cellpadding="0" cellspacing="1" class="fw_debugTables" style="margin-top: 1em;">
126+
<thead>
127+
<tr>
128+
<th width="5%">Count</th>
129+
<th>Mapping</th>
130+
</tr>
131+
</thead>
132+
<tbody>
133+
<cfloop collection="#request.cbdebugger.quick.byMapping#" item="mapping">
134+
<tr>
135+
<td align="center">#request.cbdebugger.quick.byMapping[ mapping ]#</td>
136+
<td>#mapping#</td>
137+
</tr>
138+
</cfloop>
139+
</tbody>
140+
</table>
141+
</cfif>
142+
</div>
143+
</cfif>
144+
</div>
145+
</cfoutput>
146+
<cfsetting enablecfoutputonly="false">

interceptors/QBCollector.cfc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
param request.cbdebugger.qbQueries.grouped = {};
11+
param request.cbdebugger.qbQueries.all = [];
12+
arguments.interceptData.timestamp = now();
13+
if ( !structKeyExists( request.cbdebugger.qbQueries.grouped, arguments.interceptData.sql ) ) {
14+
request.cbdebugger.qbQueries.grouped[ arguments.interceptData.sql ] = [];
15+
}
16+
request.cbdebugger.qbQueries.grouped[ arguments.interceptData.sql ].append( arguments.interceptData );
17+
request.cbdebugger.qbQueries.all.append( arguments.interceptData );
18+
}
19+
20+
}

0 commit comments

Comments
 (0)