This commit is contained in:
vakrilov
2017-05-12 17:22:00 +03:00
parent 08db23d613
commit 7e3fdb4505
2 changed files with 5 additions and 7 deletions

View File

@@ -53,7 +53,7 @@ export declare function stop(name: string): TimerInfo;
* Works only if profiling is enabled. * Works only if profiling is enabled.
* @param name Name of the timer which will be used for method calls. If not provided - the name of the method will be used. * @param name Name of the timer which will be used for method calls. If not provided - the name of the method will be used.
*/ */
export declare function profile(name?: string): (target, key, descriptor) => void; export declare function profile(name?: string): MethodDecorator;
/** /**
* Prints the timer for all methods instrumented with profile decorator. * Prints the timer for all methods instrumented with profile decorator.

View File

@@ -49,9 +49,8 @@ export function start(name: string): void {
return; return;
} }
let info: TimerInfo; let info = timers.get(name);
if (timers.has(name)) { if (info) {
info = timers.get(name);
if (info.isRunning) { if (info.isRunning) {
throw new Error(`Timer already running: ${name}`); throw new Error(`Timer already running: ${name}`);
} }
@@ -107,11 +106,10 @@ function pauseInternal(name: string): TimerInfo {
return info; return info;
} }
export function profile(name?: string): (target, key, descriptor) => void { export function profile(name?: string): MethodDecorator {
return (target, key, descriptor) => { return (target, key, descriptor) => {
if (!ENABLED) { if (!ENABLED) {
// Return the original descriptor if not enabled return;
return descriptor;
} }
// save a reference to the original method this way we keep the values currently in the // save a reference to the original method this way we keep the values currently in the