Skip to content

Commit 6522d7c

Browse files
committed
we can now store profilers in cachebox
1 parent be8a3e6 commit 6522d7c

File tree

7 files changed

+118
-68
lines changed

7 files changed

+118
-68
lines changed

ModuleConfig.cfc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ component {
4545
debugPassword : "cb:null",
4646
// Request Tracker Options
4747
requestTracker : {
48+
// Store the request profilers in heap memory or in cachebox, default is cachebox
49+
storage : "cachebox",
50+
// Which cache region to store the profilers in
51+
cacheName : "template",
4852
// Track all cbdebugger events, by default this is off, turn on, when actually profiling yourself :) How Meta!
4953
trackDebuggerEvents : false,
5054
// Expand by default the tracker panel or not
5155
expanded : false,
5256
// Slow request threshold in milliseconds, if execution time is above it, we mark those transactions as red
5357
slowExecutionThreshold : 1000,
54-
// How many tracking profilers to keep in stack: Default is to monitor the last 20 requests
55-
maxProfilers : 25,
58+
// How many tracking profilers to keep in stack
59+
maxProfilers : 50,
5660
// If enabled, the debugger will monitor the creation time of CFC objects via WireBox
5761
profileWireBoxObjectCreation : false,
5862
// Profile model objects annotated with the `profile` annotation

handlers/Main.cfc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ component extends="coldbox.system.RestHandler" {
6161
debugStartTime : getTickCount(),
6262
refreshFrequency : rc.frequency,
6363
urlBase : event.buildLink( "" ),
64-
moduleSettings : variables.debuggerConfig.modules.enabled ? getSetting( "modules" ) : {},
65-
debuggerConfig : variables.debuggerConfig,
66-
debuggerService : variables.debuggerService,
67-
environment : variables.debuggerService.getEnvironment(),
68-
profilers : variables.debuggerService.getProfilers(),
69-
currentProfiler : variables.debuggerService.getProfilers()[ 1 ],
70-
manifestRoot : event.getModuleRoot( "cbDebugger" ) & "/includes"
64+
moduleSettings : variables.debuggerConfig.modules.enabled ? getSetting( "modules" ) : {},
65+
debuggerConfig : variables.debuggerConfig,
66+
debuggerService : variables.debuggerService,
67+
environment : variables.debuggerService.getEnvironment(),
68+
profilers : variables.debuggerService.getProfilerStorage(),
69+
currentProfiler : variables.debuggerService.getProfilerStorage()[ 1 ],
70+
manifestRoot : event.getModuleRoot( "cbDebugger" ) & "/includes"
7171
}
7272
);
7373
}
@@ -100,7 +100,7 @@ component extends="coldbox.system.RestHandler" {
100100
module: "cbdebugger",
101101
args : {
102102
environment : variables.debuggerService.getEnvironment(),
103-
profilers : variables.debuggerService.getProfilers(),
103+
profilers : variables.debuggerService.getProfilerStorage(),
104104
debuggerConfig : variables.debuggerConfig
105105
},
106106
prePostExempt: true

models/DebuggerService.cfc

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ component
3030
*/
3131
property name="cookieName";
3232

33-
/**
34-
* The collection of request profilers we track in the debugger
35-
*/
36-
property name="profilers" type="array";
37-
3833
/**
3934
* The debugger configuration struct
4035
*/
@@ -98,7 +93,11 @@ component
9893
"coldboxName" : variables.controller.getColdBoxSettings().codename,
9994
"coldboxVersion" : variables.controller.getColdBoxSettings().version,
10095
"coldboxSuffix" : variables.controller.getColdBoxSettings().suffix,
101-
"coldboxModules" : variables.controller.getModuleService().getLoadedModules()
96+
"appName" : variables.controller.getSetting( "appName" ),
97+
"appPath" : variables.controller.getSetting( "applicationPath" ),
98+
"appHash" : variables.controller.getAppHash(),
99+
"dockerHost" : ( isNull( cgi.local_host ) ? "" : cgi.local_host ),
100+
"dockerIp" : ( isNull( cgi.local_addr ) ? "0.0.0.0" : cgi.local_addr )
102101
};
103102

104103
// Initialize secret key
@@ -107,6 +106,13 @@ component
107106
return this;
108107
}
109108

109+
/**
110+
* Get the cache region configured for the debugger
111+
*/
112+
private function getCacheRegion(){
113+
return variables.controller.getCacheBox().getCache( variables.debuggerConfig.requestTracker.cacheName );
114+
}
115+
110116
/**
111117
* I generate a secret key value for the cookie which enables debug mode
112118
*/
@@ -221,14 +227,42 @@ component
221227
return request.cbDebugger;
222228
}
223229

230+
/**
231+
* Get the key used in the off heap storage
232+
*/
233+
function getStorageKey(){
234+
return "cbDebugger-#variables.environment.appName.replace( " ", "-", "all" )#";
235+
}
236+
224237
/**
225238
* Reset the request tracking profilers
226239
*/
227240
DebuggerService function resetProfilers(){
228-
variables.profilers = [];
241+
if ( variables.debuggerConfig.requestTracker.storage eq "cachebox" ) {
242+
getCacheRegion().set( getStorageKey(), [], 0, 0 );
243+
} else {
244+
variables.profilers = [];
245+
}
229246
return this;
230247
}
231248

249+
/**
250+
* Get the profiler storage array depending on the storage options
251+
*/
252+
array function getProfilerStorage(){
253+
if ( variables.debuggerConfig.requestTracker.storage eq "cachebox" ) {
254+
return getCacheRegion().getOrSet(
255+
getStorageKey(),
256+
function(){
257+
return [];
258+
},
259+
0
260+
);
261+
} else {
262+
return variables.profilers;
263+
}
264+
}
265+
232266
/**
233267
* Record a profiler and it's timers internally
234268
*
@@ -241,9 +275,14 @@ component
241275
required executionTime,
242276
exception = {}
243277
){
278+
var targetStorage = getProfilerStorage();
279+
244280
// size check, if passed, pop one
245-
if ( arrayLen( variables.profilers ) gte variables.debuggerConfig.requestTracker.maxProfilers ) {
246-
popProfiler();
281+
if ( arrayLen( targetStorage ) gte variables.debuggerConfig.requestTracker.maxProfilers ) {
282+
arrayDeleteAt(
283+
targetStorage,
284+
arrayLen( targetStorage )
285+
);
247286
}
248287

249288
// Build out the exception data to trace if any?
@@ -306,11 +345,14 @@ component
306345
{ requestTracker : request.cbDebugger }
307346
);
308347

309-
// New Profiler record to store into the stack
310-
arrayPrepend(
311-
variables.profilers,
312-
request.cbDebugger
313-
);
348+
// New Profiler record to store into the singleton stack
349+
arrayPrepend( targetStorage, request.cbDebugger );
350+
351+
// Are we using cache storage
352+
if ( variables.debuggerConfig.requestTracker.storage eq "cachebox" ) {
353+
// store indefintely using the debugger and app hash
354+
getCacheRegion().set( getStorageKey(), targetStorage, 0, 0 );
355+
}
314356

315357
return this;
316358
}
@@ -323,7 +365,7 @@ component
323365
* @return The profiler requested or an empty struct if not found
324366
*/
325367
struct function getProfilerById( required id ){
326-
return variables.profilers
368+
return getProfilerStorage()
327369
.filter( function( thisItem ){
328370
return arguments.thisItem.id.toString() == id;
329371
} )
@@ -333,17 +375,6 @@ component
333375
}, {} );
334376
}
335377

336-
/**
337-
* Pop a profiler record from the top
338-
*/
339-
DebuggerService function popProfiler(){
340-
arrayDeleteAt(
341-
variables.profilers,
342-
arrayLen( variables.profilers )
343-
);
344-
return this;
345-
}
346-
347378
/**
348379
* Push a new tracer into the debugger. This comes from LogBox, so we follow
349380
* the same patterns

readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,16 @@ moduleSettings = {
8686
debugPassword : "cb:null",
8787
// Request Tracker Options
8888
requestTracker : {
89+
// Store the request profilers in heap memory or in cachebox, default is cachebox
90+
storage : "cachebox",
91+
// Which cache region to store the profilers in
92+
cacheName : "template",
8993
// Expand by default the tracker panel or not
9094
expanded : true,
9195
// Slow request threshold in milliseconds, if execution time is above it, we mark those transactions as red
9296
slowExecutionThreshold : 1000,
9397
// How many tracking profilers to keep in stack: Default is to monitor the last 20 requests
94-
maxProfilers : 25,
98+
maxProfilers : 50,
9599
// If enabled, the debugger will monitor the creation time of CFC objects via WireBox
96100
profileWireBoxObjectCreation : false,
97101
// Profile model objects annotated with the `profile` annotation

test-harness/config/Coldbox.cfc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
debugPassword : "cb:null",
7676
// Request Tracker Options
7777
requestTracker : {
78+
storage : "cachebox",
79+
cacheName : "template",
7880
trackDebuggerEvents : false,
7981
// Expand by default the tracker panel or not
8082
expanded : true,

test-harness/tests/specs/DebuggerTest.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
3838
renderResults = true
3939
);
4040
expect( timer.getTimers() ).notToBeEmpty();
41-
expect( debuggerService.getProfilers() ).notToBeEmpty();
41+
expect( debuggerService.getProfilerStorage() ).notToBeEmpty();
4242
expect( debuggerService.getTracers() ).notToBeEmpty();
4343
} );
4444

4545
debug( timer.getTimers() );
46-
debug( debuggerService.getProfilers() );
46+
debug( debuggerService.getProfilerStorage() );
4747
debug( debuggerService.getTracers() );
4848
} );
4949
} );

views/main/partials/profilerReport.cfm

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,36 @@
3636
<div
3737
class="cbd-size13"
3838
>
39-
#args.profiler.requestData.method#
40-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
41-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
42-
</svg>
43-
#args.profiler.fullUrl#
39+
<span title="Status Code">
40+
<cfif args.profiler.response.statusCode gte 200 && args.profiler.response.statusCode lt 300 >
41+
<span class="cbd-text-green">
42+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
43+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
44+
</svg>
45+
#args.profiler.response.statusCode#
46+
</span>
47+
<cfelseif args.profiler.response.statusCode gte 300 && args.profiler.response.statusCode lt 400 >
48+
<span class="cbd-text-blue">
49+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
50+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
51+
</svg>
52+
#args.profiler.response.statusCode#
53+
</span>
54+
<cfelseif args.profiler.response.statusCode gte 400>
55+
<span class="cbd-text-red">
56+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
57+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
58+
</svg>
59+
#args.profiler.response.statusCode#
60+
</span>
61+
</cfif>
62+
</span>
63+
64+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
65+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 19l-7-7 7-7m8 14l-7-7 7-7" />
66+
</svg>
67+
68+
#args.profiler.requestData.method# : #args.profiler.fullUrl#
4469
</div>
4570

4671
<!--- Execution Time --->
@@ -103,30 +128,14 @@
103128
#args.profiler.threadInfo.replaceNoCase( "Thread", "" )#
104129
</div>
105130

106-
<div class="ml10" title="Status Code">
107-
<cfif args.profiler.response.statusCode gte 200 && args.profiler.response.statusCode lt 300 >
108-
<span class="cbd-text-green">
109-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
110-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
111-
</svg>
112-
#args.profiler.response.statusCode#
113-
</span>
114-
<cfelseif args.profiler.response.statusCode gte 300 && args.profiler.response.statusCode lt 400 >
115-
<span class="cbd-text-blue">
116-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
117-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
118-
</svg>
119-
#args.profiler.response.statusCode#
120-
</span>
121-
<cfelseif args.profiler.response.statusCode gte 400>
122-
<span class="cbd-text-red">
123-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
124-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
125-
</svg>
126-
#args.profiler.response.statusCode#
127-
</span>
128-
</cfif>
129-
</div>
131+
<cfif len( args.environment.dockerHost )>
132+
<div class="ml10" title="Docker Info">
133+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
134+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
135+
</svg>
136+
#args.environment.dockerHost# / #args.environment.dockerIp#
137+
</div>
138+
</cfif>
130139

131140
<div class="ml10" title="Response Content Type">
132141
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">

0 commit comments

Comments
 (0)