Skip to content

Commit 0a1c4cf

Browse files
committed
* Ability to sort the visualizer's profilers
1 parent c72ec92 commit 0a1c4cf

File tree

7 files changed

+231
-68
lines changed

7 files changed

+231
-68
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
* New `Slowest` Queries panel for cborm, acf, and qb/quick
2222
* New visualizer total db time as well as request time including percentage of the request time
2323
* Ability to export a profiler in json
24+
* Ability to sort the visualizer's profilers
2425

2526
### Fixed
2627

handlers/Main.cfc

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ component extends="coldbox.system.RestHandler" {
4242
* Visualize the request tracker
4343
*/
4444
any function index( event, rc, prc ){
45+
paramSorting( rc );
4546
return renderDebugger( argumentCollection = arguments );
4647
}
4748

@@ -113,45 +114,30 @@ component extends="coldbox.system.RestHandler" {
113114
* Get the profilers via ajax
114115
*/
115116
function renderProfilers( event, rc, prc ){
116-
// Sorting: timestamp, executionTime
117-
event.paramValue( "sortBy", "timestamp" ).paramValue( "sortOrder", "desc" );
118-
119-
// Get the profilers
120-
var aProfilers = variables.debuggerService.getProfilerStorage();
121-
122-
// Sorting?
123-
switch ( rc.sortBy ) {
124-
case "executionTime": {
125-
arraySort( aProfilers, function( e1, e2 ){
126-
if ( rc.sortOrder == "asc" ) {
127-
return ( arguments.e1.executionTime < arguments.e2.executionTime ? -1 : 1 );
128-
}
129-
return ( arguments.e1.executionTime > arguments.e2.executionTime ? -1 : 1 );
130-
} );
131-
break;
132-
}
133-
default: {
134-
arraySort( aProfilers, function( e1, e2 ){
135-
if ( rc.sortOrder == "asc" ) {
136-
return dateCompare( arguments.e1.timestamp, arguments.e2.timestamp );
137-
}
138-
return dateCompare( arguments.e2.timestamp, arguments.e1.timestamp );
139-
} );
140-
break;
141-
}
142-
}
143-
return renderView(
117+
return paramSorting( rc ).renderView(
144118
view : "main/partials/profilers",
145119
module: "cbdebugger",
146120
args : {
147121
environment : variables.debuggerService.getEnvironment(),
148-
profilers : aProfilers,
122+
profilers : variables.debuggerService.getProfilers( rc.sortBy, rc.sortOrder ),
149123
debuggerConfig : variables.debuggerConfig
150124
},
151125
prePostExempt: true
152126
);
153127
}
154128

129+
private function paramSorting( rc ){
130+
param rc.sortBy = "timestamp";
131+
param rc.sortOrder = "desc";
132+
if( !len( rc.sortBy ) ){
133+
rc.sortby = "timestamp";
134+
}
135+
if( !len( rc.sortOrder ) ){
136+
rc.sortOrder = "desc";
137+
}
138+
return this;
139+
}
140+
155141
/**
156142
* Get a profiler report via ajax
157143
*/

models/DebuggerService.cfc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,72 @@ component
269269
return {};
270270
}
271271

272+
/**
273+
* Get the current profilers using a sorting algorithm
274+
*
275+
* @sortBy The sort by key: timestamp, executionTime, etc
276+
* @sortOrder Asc/Desc
277+
*/
278+
array function getProfilers( string sortBy, string sortOrder = "desc" ){
279+
var aProfilers = getProfilerStorage();
280+
281+
// Sorting?
282+
switch ( arguments.sortBy ) {
283+
case "event": {
284+
arraySort( aProfilers, function( e1, e2 ){
285+
var results = compareNoCase( arguments.e1.coldbox.event, arguments.e2.coldbox.event );
286+
return ( sortOrder == "asc" ? results : results * -1 );
287+
} );
288+
break;
289+
}
290+
291+
case "inethost": {
292+
arraySort( aProfilers, function( e1, e2 ){
293+
var results = compareNoCase( arguments.e1.inethost, arguments.e2.inethost );
294+
return ( sortOrder == "asc" ? results : results * -1 );
295+
} );
296+
break;
297+
}
298+
299+
case "memoryDiff": {
300+
arraySort( aProfilers, function( e1, e2 ){
301+
var diff1 = arguments.e1.endFreeMemory - arguments.e1.startFreeMemory;
302+
var diff2 = arguments.e2.endFreeMemory - arguments.e2.startFreeMemory;
303+
var results = diff1 < diff2 ? -1 : 1;
304+
return ( sortOrder == "asc" ? results : results * -1 );
305+
} );
306+
break;
307+
}
308+
309+
case "statusCode": {
310+
arraySort( aProfilers, function( e1, e2 ){
311+
var results = arguments.e1.response.statusCode < arguments.e2.response.statusCode ? -1 : 1;
312+
return ( sortOrder == "asc" ? results : results * -1 );
313+
} );
314+
break;
315+
}
316+
317+
case "executionTime": {
318+
arraySort( aProfilers, function( e1, e2 ){
319+
var results = arguments.e1.executionTime < arguments.e2.executionTime ? -1 : 1;
320+
return ( sortOrder == "asc" ? results : results * -1 );
321+
} );
322+
break;
323+
}
324+
325+
// timestamp
326+
default: {
327+
arraySort( aProfilers, function( e1, e2 ){
328+
var results = dateCompare( arguments.e1.timestamp, arguments.e2.timestamp );
329+
return ( sortOrder == "asc" ? results : results * -1 );
330+
} );
331+
break;
332+
}
333+
}
334+
335+
return aProfilers;
336+
}
337+
272338
/**
273339
* Get the profiler storage array depending on the storage options
274340
*/

resources/assets/js/components/RequestTrackerPanel.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ export default ( isExpanded, refreshFrequency, hasReinitPassword, isVisualizer )
4545
this.currentProfileId = "";
4646
},
4747

48-
refreshProfilers(){
48+
refreshProfilers( sortBy = '', sortOrder = '' ){
4949
this.$refs.refreshLoader.classList.add( "cbd-spinner" );
50-
fetch( `${this.appUrl}cbDebugger/renderProfilers`, { headers: { "x-Requested-With": "XMLHttpRequest" } } )
50+
fetch(
51+
`${this.appUrl}cbDebugger/renderProfilers?sortBy=${sortBy}&sortOrder=${sortOrder}`,
52+
{ headers: { "x-Requested-With": "XMLHttpRequest" } }
53+
)
5154
.then( response => response.text() )
5255
.then( html => {
5356
this.clearState();

resources/assets/sass/cbdebugger.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
margin: auto;
1010
clear: both;
1111

12+
.cbd-sortable {
13+
cursor: pointer;
14+
}
15+
1216
code {
1317
padding: 0px;
1418
width: 100%;

views/main/panels/requestTrackerPanel.cfm

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@
6868

6969
<!--- Toolbar --->
7070
<div class="cbd-floatRight">
71+
7172
<!--- ************************************************ --->
7273
<!--- Visualizer Toolbar --->
7374
<!--- ************************************************ --->
7475
<cfif args.isVisualizer>
76+
7577
<!--- Auto Refresh Frequency --->
7678
<select
7779
@change="startDebuggerMonitor( $el.value )"
@@ -89,7 +91,7 @@
8991
<button
9092
type="button"
9193
title="Refresh the profilers"
92-
@click="refreshProfilers"
94+
@click="refreshProfilers()"
9395
>
9496
<svg
9597
xmlns="http://www.w3.org/2000/svg"
@@ -116,6 +118,7 @@
116118
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
117119
</svg>
118120
</button>
121+
119122
<!--- ************************************************ --->
120123
<!--- NON Visualizer Toolbar --->
121124
<!--- ************************************************ --->
@@ -161,47 +164,53 @@
161164
</button>
162165
</div>
163166

164-
<!--- Machine Info --->
165-
<div class="cbd-titleCell">
166-
Framework Info:
167-
</div>
168-
<div class="cbd-contentCell">
169-
#controller.getColdboxSettings().codename#
170-
#controller.getColdboxSettings().version#
171-
#controller.getColdboxSettings().suffix#
172-
</div>
167+
<!--- General Information --->
168+
<div>
169+
<!--- Machine Info --->
170+
<div class="cbd-titleCell">
171+
Framework Info:
172+
</div>
173+
<div class="cbd-contentCell">
174+
#controller.getColdboxSettings().codename#
175+
#controller.getColdboxSettings().version#
176+
#controller.getColdboxSettings().suffix#
177+
</div>
173178

174-
<!--- App Name + Environment --->
175-
<div class="cbd-titleCell">
176-
Application Name:
177-
</div>
178-
<div class="cbd-contentCell">
179-
#controller.getSetting( "AppName" )#
180-
<span class="cbd-text-purple">
181-
(environment=#controller.getSetting( "Environment" )#)
182-
</span>
183-
</div>
179+
<!--- App Name + Environment --->
180+
<div class="cbd-titleCell">
181+
Application Name:
182+
</div>
183+
<div class="cbd-contentCell">
184+
#controller.getSetting( "AppName" )#
185+
<span class="cbd-text-purple">
186+
(environment=#controller.getSetting( "Environment" )#)
187+
</span>
188+
</div>
184189

185-
<!--- App Name + Environment --->
186-
<div class="cbd-titleCell">
187-
CFML Engine:
188-
</div>
189-
<div class="cbd-contentCell">
190-
#args.environment.cfmlEngine#
191-
#args.environment.cfmlVersion#
192-
/
193-
Java #args.environment.javaVersion#
190+
<!--- App Name + Environment --->
191+
<div class="cbd-titleCell">
192+
CFML Engine:
193+
</div>
194+
<div class="cbd-contentCell">
195+
#args.environment.cfmlEngine#
196+
#args.environment.cfmlVersion#
197+
/
198+
Java #args.environment.javaVersion#
199+
</div>
194200
</div>
195201

202+
<!---**********************************************************************--->
196203
<!--- RENDER PROFILERS OR PROFILER REPORT, DEPENDING ON VISUALIZER FLAG --->
197-
<h2>Request History</h2>
204+
<!---**********************************************************************--->
205+
198206
<a name="cbd-profilers"></a>
199207
<div
200208
id="cbd-profilers"
201209
x-ref="cbd-profilers"
202210
>
203211
<!--- If visualizer, show all the profilers--->
204212
<cfif args.isVisualizer>
213+
<h2>Request History</h2>
205214
#renderView(
206215
view : "main/partials/profilers",
207216
module : "cbdebugger",

0 commit comments

Comments
 (0)