File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Server-Side Components/Script Includes/Execution Time Tracker Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ # Script Execution Time Tracker
3+
4+ This snippet helps developers measure how long their server-side scripts take to run in ServiceNow.
5+ Useful for performance optimization and debugging slow background scripts or Script Includes.
6+
7+ ## Example Use Case
8+ - Measure performance of a GlideRecord query or function execution.
9+ - Log the execution time to the system logs.
10+
11+ ## How It Works
12+ The script uses timestamps before and after execution to measure elapsed time.
13+
14+ ## Usage
15+ Wrap your logic between ` start ` and ` stop ` , or use the Script Include:
16+
17+ ``` javascript
18+ var timer = new ExecutionTimeTracker ();
19+ // ... your code ...
20+ timer .stop (' My Script' );
Original file line number Diff line number Diff line change 1+ var ExecutionTimeTracker = Class . create ( ) ;
2+ ExecutionTimeTracker . prototype = {
3+ initialize : function ( ) {
4+ this . startTime = new Date ( ) . getTime ( ) ;
5+ } ,
6+
7+ stop : function ( label ) {
8+ var endTime = new Date ( ) . getTime ( ) ;
9+ var duration = endTime - this . startTime ;
10+ gs . info ( ( label || 'Execution' ) + ' completed in ' + duration + ' ms' ) ;
11+ return duration ;
12+ } ,
13+
14+ type : 'ExecutionTimeTracker'
15+ } ;
You can’t perform that action at this time.
0 commit comments