Skip to content

Commit 68b6349

Browse files
committed
* New life-cycle events: onDebuggerUnload, onDebuggerLoad
1 parent 232fd67 commit 68b6349

File tree

6 files changed

+78
-69
lines changed

6 files changed

+78
-69
lines changed

ModuleConfig.cfc

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ component {
140140
"beforeProfilerReportPanels",
141141
// After any individual profiler report panels are rendered
142142
"afterProfilerReportPanels",
143+
// Fires after the module has fully loaded and been configured with all runtime settings
144+
"onDebuggerLoad",
145+
// Fires after the module is unloaded
146+
"onDebuggerUnload",
143147
// When the request tracker has been created and placed in request scope
144148
"onDebuggerRequestTrackerCreation",
145149
// Before the request tracker is saved in the profiler, last chance to influence the recording
@@ -161,14 +165,14 @@ component {
161165
function onLoad(){
162166
// Only activate interceptions and collectors if master switch is on or in test mode disable it
163167
if ( variables.settings.enabled ) {
168+
var interceptorService = controller.getInterceptorService();
169+
164170
/******************** REQUEST COLLECTOR ************************************/
165171

166-
controller
167-
.getInterceptorService()
168-
.registerInterceptor(
169-
interceptorClass = "#moduleMapping#.interceptors.RequestCollector",
170-
interceptorName = "RequestCollector@cbdebugger"
171-
);
172+
interceptorService.registerInterceptor(
173+
interceptorClass = "#moduleMapping#.interceptors.RequestCollector",
174+
interceptorName = "RequestCollector@cbdebugger"
175+
);
172176

173177
/******************** OBJECT PROFILING ************************************/
174178

@@ -195,12 +199,10 @@ component {
195199
/******************** WIREBOX COLLECTOR ************************************/
196200

197201
if ( variables.settings.requestTracker.profileWireBoxObjectCreation ) {
198-
controller
199-
.getInterceptorService()
200-
.registerInterceptor(
201-
interceptorClass = "#moduleMapping#.interceptors.WireBoxCollector",
202-
interceptorName = "WireBoxCollector@cbdebugger"
203-
);
202+
interceptorService.registerInterceptor(
203+
interceptorClass = "#moduleMapping#.interceptors.WireBoxCollector",
204+
interceptorName = "WireBoxCollector@cbdebugger"
205+
);
204206
}
205207

206208
/******************** PROFILE INTERCEPTIONS ************************************/
@@ -234,34 +236,28 @@ component {
234236
/******************** QB COLLECTOR ************************************/
235237

236238
if ( variables.settings.qb.enabled && controller.getModuleService().isModuleRegistered( "qb" ) ) {
237-
controller
238-
.getInterceptorService()
239-
.registerInterceptor(
240-
interceptorClass = "#moduleMapping#.interceptors.QBCollector",
241-
interceptorName = "QBCollector@cbdebugger"
242-
);
239+
interceptorService.registerInterceptor(
240+
interceptorClass = "#moduleMapping#.interceptors.QBCollector",
241+
interceptorName = "QBCollector@cbdebugger"
242+
);
243243
}
244244

245245
/******************** QUICK COLLECTOR ************************************/
246246

247247
if ( variables.settings.qb.enabled && controller.getModuleService().isModuleRegistered( "quick" ) ) {
248-
controller
249-
.getInterceptorService()
250-
.registerInterceptor(
251-
interceptorClass = "#moduleMapping#.interceptors.QuickCollector",
252-
interceptorName = "QuickCollector@cbdebugger"
253-
);
248+
interceptorService.registerInterceptor(
249+
interceptorClass = "#moduleMapping#.interceptors.QuickCollector",
250+
interceptorName = "QuickCollector@cbdebugger"
251+
);
254252
}
255253

256254
/******************** CBORM COLLECTOR ************************************/
257255

258256
if ( variables.settings.cborm.enabled && controller.getModuleService().isModuleRegistered( "cborm" ) ) {
259-
controller
260-
.getInterceptorService()
261-
.registerInterceptor(
262-
interceptorClass = "#moduleMapping#.interceptors.CBOrmCollector",
263-
interceptorName = "CBOrmCollector@cbdebugger"
264-
);
257+
interceptorService.registerInterceptor(
258+
interceptorClass = "#moduleMapping#.interceptors.CBOrmCollector",
259+
interceptorName = "CBOrmCollector@cbdebugger"
260+
);
265261
}
266262

267263
/******************** ACFSQL COLLECTOR ************************************/
@@ -270,15 +266,16 @@ component {
270266
if (
271267
variables.settings.acfSql.enabled && !server.keyExists( "lucee" ) && server.coldfusion.productVersion.listFirst() gt "2016"
272268
) {
273-
controller
274-
.getInterceptorService()
275-
.registerInterceptor(
276-
interceptorClass = "#moduleMapping#.interceptors.ACFSqlCollector",
277-
interceptorName = "ACFSqlCollector@cbdebugger"
278-
);
269+
interceptorService.registerInterceptor(
270+
interceptorClass = "#moduleMapping#.interceptors.ACFSqlCollector",
271+
interceptorName = "ACFSqlCollector@cbdebugger"
272+
);
279273
} else {
280274
variables.settings.acfSql.enabled = false;
281275
}
276+
277+
// Announce debugger loaded
278+
interceptorService.announce( "onDebuggerLoad" );
282279
}
283280
// end master switch
284281
}
@@ -289,11 +286,15 @@ component {
289286
function onUnload(){
290287
// Only if we are enabled
291288
if ( variables.settings.enabled ) {
292-
controller.getInterceptorService().unregister( "RequestCollector@cbdebugger" );
293-
controller.getInterceptorService().unregister( "QBCollector@cbdebugger" );
294-
controller.getInterceptorService().unregister( "QuickCollector@cbdebugger" );
295-
controller.getInterceptorService().unregister( "CBOrmCollector@cbdebugger" );
296-
controller.getInterceptorService().unregister( "ACFSqlCollector@cbdebugger" );
289+
var interceptorService = controller.getInterceptorService();
290+
291+
interceptorService.announce( "onDebuggerUnload" );
292+
interceptorService.unregister( "RequestCollector@cbdebugger" );
293+
interceptorService.unregister( "WireBoxCollector@cbdebugger" );
294+
interceptorService.unregister( "QBCollector@cbdebugger" );
295+
interceptorService.unregister( "QuickCollector@cbdebugger" );
296+
interceptorService.unregister( "CBOrmCollector@cbdebugger" );
297+
interceptorService.unregister( "ACFSqlCollector@cbdebugger" );
297298
}
298299
}
299300

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
* New WireBoxCollector which is only used if enabled. This greatly accelerates the performance of the request collector since before they where in the same collector.
1717
* Ability to open CFCs that are profiled by the WireBox Collector in any Code Editor.
1818
* Ability to open the Handler events that are profiled by the Request Collector in any Code Editor.
19+
* New life-cycle events: onDebuggerUnload, onDebuggerLoad
1920

2021
### Fixed
2122

interceptors/RequestCollector.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ component extends="coldbox.system.Interceptor" {
1919
}
2020

2121
/**
22-
* Listen to app loads, in case we need to profile app inits and such
22+
* Listen to when the debugger loads for the first time, usually app starts or reinits
2323
*/
24-
function cbLoadInterceptorHelpers( event, interceptData, rc, prc ){
24+
function onDebuggerLoad( event, interceptData, rc, prc ){
2525
initRequestTracker( event );
2626
}
2727

models/DebuggerService.cfc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,6 @@ component
291291
required executionTime,
292292
exception = {}
293293
){
294-
var targetStorage = getProfilerStorage();
295-
296294
// Build out the exception data to trace if any?
297295
var exceptionData = {};
298296
if ( isObject( arguments.exception ) || !structIsEmpty( arguments.exception ) ) {
@@ -320,8 +318,13 @@ component
320318
createRequestTracker( arguments.event );
321319
}
322320

321+
// Event before recording
322+
variables.interceptorService.announce(
323+
"onDebuggerProfilerRecording",
324+
{ requestTracker : request.cbDebugger }
325+
);
326+
323327
// Close out the profiler
324-
param request.cbDebugger.startCount = 0;
325328
request.cbDebugger.append(
326329
{
327330
"endFreeMemory" : variables.jvmRuntime.freeMemory(),
@@ -348,13 +351,8 @@ component
348351
true
349352
);
350353

351-
// Event before recording
352-
variables.interceptorService.announce(
353-
"onDebuggerProfilerRecording",
354-
{ requestTracker : request.cbDebugger }
355-
);
356-
357354
// New Profiler record to store into the singleton stack
355+
var targetStorage = getProfilerStorage();
358356
arrayPrepend( targetStorage, request.cbDebugger );
359357

360358
// Are we using cache storage

models/Timer.cfc

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ component accessors="true" singleton threadsafe {
3939
"startedAt" : now(),
4040
"startCount" : getTickCount(),
4141
"method" : arguments.label,
42-
"stoppedAt" : now(),
42+
"stoppedAt" : "",
4343
"executionTime" : 0,
4444
"metadata" : arguments.metadata,
4545
"parent" : arguments.parent,
46-
"type" : arguments.type
46+
"type" : arguments.type,
47+
"times" : 1
4748
},
4849
true
4950
);
@@ -57,14 +58,12 @@ component accessors="true" singleton threadsafe {
5758
* @metadata The metadata to store as well after the stopping of the timer
5859
*/
5960
Timer function stop( required label, struct metadata = {} ){
60-
var timers = getTimers();
61-
62-
if ( timers.keyExists( arguments.label ) ) {
63-
timers[ arguments.label ].stoppedAt = now();
64-
timers[ arguments.label ].executionTime = getTickCount() - timers[ arguments.label ].startCount;
65-
timers[ arguments.label ].metadata.append( arguments.metadata );
61+
if ( timerExists( arguments.label ) ) {
62+
var timer = getTimer( arguments.label );
63+
timer.stoppedAt = now();
64+
timer.executionTime = getTickCount() - timer.startCount;
65+
timer.metadata.append( arguments.metadata );
6666
}
67-
6867
return this;
6968
}
7069

@@ -88,6 +87,24 @@ component accessors="true" singleton threadsafe {
8887
}
8988
}
9089

90+
/**
91+
* Get a specific timer from the timers stack
92+
*
93+
* @label The label to get
94+
*
95+
* @throws KeyNotFoundException - If the requested label doesn't exist
96+
*/
97+
struct function getTimer( required label ){
98+
return getTimers().find( arguments.label );
99+
}
100+
101+
/**
102+
* Verifies if the timer for the label exists or not
103+
*/
104+
boolean function timerExists( required label ){
105+
return getTimers().keyExists( arguments.label );
106+
}
107+
91108
/**
92109
* Do we have any timers at all
93110
*/

views/main/panels/requestTracker/debugTimersPanel.cfm

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@
2525
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 20l4-16m2 16l4-16M6 9h14M4 15h14" />
2626
</svg>
2727
#structCount( args.timers )#
28-
29-
<!--- Timers Sum --->
30-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
31-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
32-
</svg>
33-
#numberFormat( structReduce( args.timers, function( results, key, value ){
34-
return results + value.executionTime;
35-
}, 0 ) )# ms
3628
</div>
3729

3830
<div

0 commit comments

Comments
 (0)