@@ -12,11 +12,11 @@ interface TimerInfo extends TimerInfoDefinition {
12
12
}
13
13
14
14
// Use object instead of map as it is a bit faster
15
- const timers : { [ index : string ] : TimerInfo } = { } ;
15
+ const timers : { [ index : string ] : TimerInfo } = { } ;
16
16
const anyGlobal = < any > global ;
17
17
const profileNames : string [ ] = [ ] ;
18
18
19
- let ENABLED = true ;
19
+ let ENABLED = false ;
20
20
let nativeTimeFunc : ( ) => number ;
21
21
22
22
export function enable ( ) {
@@ -51,7 +51,7 @@ export function start(name: string): void {
51
51
return ;
52
52
}
53
53
54
- let info = timers [ name ] ;
54
+ let info = timers [ name ] ;
55
55
56
56
if ( info ) {
57
57
if ( info . isRunning ) {
@@ -66,7 +66,7 @@ export function start(name: string): void {
66
66
currentStart : time ( ) ,
67
67
isRunning : true
68
68
} ;
69
- timers [ name ] = info ;
69
+ timers [ name ] = info ;
70
70
}
71
71
}
72
72
@@ -88,17 +88,17 @@ export function stop(name: string): TimerInfo {
88
88
let info = pauseInternal ( name ) ;
89
89
console . log ( `---- [${ name } ] STOP total: ${ info . totalTime } count:${ info . count } ` ) ;
90
90
91
- timers [ name ] = undefined ;
91
+ timers [ name ] = undefined ;
92
92
return info ;
93
93
}
94
94
95
95
export function isRunning ( name : string ) : boolean {
96
- const info = timers [ name ] ;
96
+ const info = timers [ name ] ;
97
97
return ! ! ( info && info . isRunning ) ;
98
98
}
99
99
100
100
function pauseInternal ( name : string ) : TimerInfo {
101
- const info = timers [ name ] ;
101
+ const info = timers [ name ] ;
102
102
103
103
if ( ! info ) {
104
104
throw new Error ( `No timer started: ${ name } ` ) ;
@@ -156,7 +156,7 @@ export function profile(name?: string): MethodDecorator {
156
156
157
157
export function dumpProfiles ( ) : void {
158
158
profileNames . forEach ( function ( name ) {
159
- const info = timers [ name ] ;
159
+ const info = timers [ name ] ;
160
160
161
161
if ( info ) {
162
162
console . log ( "---- [" + name + "] STOP total: " + info . totalTime + " count:" + info . count ) ;
@@ -167,6 +167,20 @@ export function dumpProfiles(): void {
167
167
} ) ;
168
168
}
169
169
170
+ export function resetProfiles ( ) : void {
171
+ profileNames . forEach ( function ( name ) {
172
+ const info = timers [ name ] ;
173
+
174
+ if ( info ) {
175
+ if ( ! info . isRunning ) {
176
+ timers [ name ] = undefined ;
177
+ } else {
178
+ console . log ( "---- timer with name [" + name + "] is currently running and won't be reset" ) ;
179
+ }
180
+ }
181
+ } ) ;
182
+ }
183
+
170
184
export function startCPUProfile ( name : string ) {
171
185
if ( ! ENABLED ) {
172
186
return ;
0 commit comments