Add resetProfiles method

This commit is contained in:
vakrilov
2017-05-16 17:40:07 +03:00
parent d4e4841b59
commit f23c6c6455
2 changed files with 27 additions and 8 deletions

View File

@ -67,6 +67,11 @@ export declare function profile(name?: string): MethodDecorator;
*/ */
export declare function dumpProfiles(): void; export declare function dumpProfiles(): void;
/**
* Resets the timers for all methods instrumented with profile decorator.
*/
export function resetProfiles(): void;
/** /**
* Starts android cpu profiling. * Starts android cpu profiling.
* @param name Name of the cpu profiling session. * @param name Name of the cpu profiling session.

View File

@ -16,7 +16,7 @@ const timers: { [ index: string ]: TimerInfo } = {};
const anyGlobal = <any>global; const anyGlobal = <any>global;
const profileNames: string[] = []; const profileNames: string[] = [];
let ENABLED = true; let ENABLED = false;
let nativeTimeFunc: () => number; let nativeTimeFunc: () => number;
export function enable() { export function enable() {
@ -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) { export function startCPUProfile(name: string) {
if (!ENABLED) { if (!ENABLED) {
return; return;