diff --git a/tns-core-modules/profiling/profiling.d.ts b/tns-core-modules/profiling/profiling.d.ts index e9e15b35b..047191096 100644 --- a/tns-core-modules/profiling/profiling.d.ts +++ b/tns-core-modules/profiling/profiling.d.ts @@ -67,6 +67,11 @@ export declare function profile(name?: string): MethodDecorator; */ export declare function dumpProfiles(): void; +/** + * Resets the timers for all methods instrumented with profile decorator. + */ +export function resetProfiles(): void; + /** * Starts android cpu profiling. * @param name Name of the cpu profiling session. diff --git a/tns-core-modules/profiling/profiling.ts b/tns-core-modules/profiling/profiling.ts index 75432bc8f..c168d0c3d 100644 --- a/tns-core-modules/profiling/profiling.ts +++ b/tns-core-modules/profiling/profiling.ts @@ -12,11 +12,11 @@ interface TimerInfo extends TimerInfoDefinition { } // Use object instead of map as it is a bit faster -const timers: { [ index: string ]: TimerInfo } = {}; +const timers: { [index: string]: TimerInfo } = {}; const anyGlobal = global; const profileNames: string[] = []; -let ENABLED = true; +let ENABLED = false; let nativeTimeFunc: () => number; export function enable() { @@ -51,7 +51,7 @@ export function start(name: string): void { return; } - let info = timers[ name ]; + let info = timers[name]; if (info) { if (info.isRunning) { @@ -66,7 +66,7 @@ export function start(name: string): void { currentStart: time(), isRunning: true }; - timers[ name ] = info; + timers[name] = info; } } @@ -88,17 +88,17 @@ export function stop(name: string): TimerInfo { let info = pauseInternal(name); console.log(`---- [${name}] STOP total: ${info.totalTime} count:${info.count}`); - timers[ name ] = undefined; + timers[name] = undefined; return info; } export function isRunning(name: string): boolean { - const info = timers[ name ]; + const info = timers[name]; return !!(info && info.isRunning); } function pauseInternal(name: string): TimerInfo { - const info = timers[ name ]; + const info = timers[name]; if (!info) { throw new Error(`No timer started: ${name}`); @@ -156,7 +156,7 @@ export function profile(name?: string): MethodDecorator { export function dumpProfiles(): void { profileNames.forEach(function (name) { - const info = timers[ name ]; + const info = timers[name]; if (info) { console.log("---- [" + name + "] STOP total: " + info.totalTime + " count:" + info.count); @@ -167,6 +167,20 @@ export function dumpProfiles(): void { }); } +export function resetProfiles(): void { + profileNames.forEach(function (name) { + const info = timers[name]; + + if (info) { + if (!info.isRunning) { + timers[name] = undefined; + } else { + console.log("---- timer with name [" + name + "] is currently running and won't be reset"); + } + } + }); +} + export function startCPUProfile(name: string) { if (!ENABLED) { return;