Skip to content

Commit edd3e2d

Browse files
committed
timer delegates
1 parent 900013d commit edd3e2d

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Added
1313

1414
* ColdBox 7 support
15+
* New `TimerDelegate` that can be used to add timer functions to any model
1516
* Timer service rewritten to support nesting and included metadata
1617
* Ability to open views and layouts from the execution timers in any Code Editor
1718
* 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.

models/TimerDelegate.cfc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
3+
* www.ortussolutions.com
4+
* ---
5+
* This delegate allows objects to be able to time themselves into the debugger
6+
*/
7+
component accessors="true" singleton threadsafe {
8+
9+
// DI
10+
property name="timer" inject="Timer@cbdebugger";
11+
12+
/**
13+
* Start a timer with a tracking label
14+
*
15+
* @label The tracking label to register
16+
*
17+
* @return A unique tracking hash you must use to stop the timer
18+
*/
19+
function startCBTimer( required label ){
20+
return variables.timer.start( arguments.label );
21+
}
22+
23+
/**
24+
* End a code timer with a tracking hash. If the tracking hash is not tracked we ignore it
25+
*
26+
* @labelHash The timer label hash to stop
27+
*/
28+
function stopCBTimer( required labelHash ){
29+
return variables.timer.stop( arguments.labelHash );
30+
}
31+
32+
/**
33+
* Time the execution of the passed closure that we will execution for you
34+
*
35+
* @label The label to use as a timer label
36+
* @closure The target to execute and time
37+
* @metadata A struct of metadata to store in the execution timer
38+
*/
39+
function cbTimeIt(
40+
required label,
41+
required closure,
42+
struct metadata = {}
43+
){
44+
return variables.timer.timeIt( argumentCollection = arguments );
45+
}
46+
47+
}

readme.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ moduleSettings = {
105105
requestTracker : {
106106
// Track all cbdebugger events, by default this is off, turn on, when actually profiling yourself :) How Meta!
107107
trackDebuggerEvents : false,
108-
// Store the request profilers in heap memory or in cachebox, default is cachebox. Options are: local, cachebox
109-
storage : "cachebox",
108+
// Store the request profilers in heap memory or in cachebox, default is memory. Options are: memory, cachebox
109+
storage : "memory",
110110
// Which cache region to store the profilers in if storage == cachebox
111111
cacheName : "template",
112112
// Expand by default the tracker panel or not
@@ -266,6 +266,23 @@ This module will also register a few methods in all your handlers/interceptors/l
266266
)
267267
```
268268

269+
## Timer Delegate
270+
271+
We have included a ColdBox 7 Timer delegate: `TimerDelegate@cbDebguger` that can add timing capabilities to any CFC
272+
273+
```js
274+
component delegates="TimerDelegate@cbDebguger"{
275+
276+
...
277+
startCBTimer();
278+
stopCBTimer();
279+
timeIt();
280+
...
281+
282+
}
283+
284+
```
285+
269286
## Debugger Events
270287

271288
The debugger also announces several events that you can listen to and extend the debugging and profiling capabilities:

test-harness/box.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@
66
"description":"",
77
"dependencies":{
88
"coldbox":"be",
9-
"JSONPrettyPrint":"^1.4.1",
109
"quick":"^4.2.4",
11-
"cborm":"^3.0.0+184",
12-
"sqlformatter":"^1.0.1"
10+
"cborm":"^4.0.0"
1311
},
1412
"devDependencies":{
1513
"testbox":"*"
1614
},
1715
"installPaths":{
1816
"coldbox":"coldbox/",
1917
"testbox":"testbox/",
20-
"JSONPrettyPrint":"modules/JSONPrettyPrint/",
2118
"quick":"modules/quick/",
22-
"cborm":"modules/cborm/",
23-
"sqlformatter":"modules/sqlformatter/"
19+
"cborm":"modules/cborm/"
2420
}
2521
}

0 commit comments

Comments
 (0)