mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Add try catch for profiler decorator
This commit is contained in:
7
tns-core-modules/profiling/profiling.d.ts
vendored
7
tns-core-modules/profiling/profiling.d.ts
vendored
@@ -48,6 +48,13 @@ export declare function pause(name: string): TimerInfo;
|
||||
*/
|
||||
export declare function stop(name: string): TimerInfo;
|
||||
|
||||
/**
|
||||
* Returns true if a timer is currently running.
|
||||
* @param name Name of the timer.
|
||||
* @returns true is the timer is currently running.
|
||||
*/
|
||||
export declare function isRunning(name: string): boolean;
|
||||
|
||||
/**
|
||||
* Method decorator factory. It will intercept the method call and start and pause a timer before and after the method call.
|
||||
* Works only if profiling is enabled.
|
||||
|
||||
@@ -89,14 +89,19 @@ export function stop(name: string): TimerInfo {
|
||||
return info;
|
||||
}
|
||||
|
||||
export function isRunning(name: string): boolean {
|
||||
const info = timers.get(name);
|
||||
return !!(info && info.isRunning);
|
||||
}
|
||||
|
||||
function pauseInternal(name: string): TimerInfo {
|
||||
let info = timers.get(name);
|
||||
const info = timers.get(name);
|
||||
if (!info) {
|
||||
throw new Error(`No timer started: ${name}`);
|
||||
}
|
||||
|
||||
if (info.isRunning) {
|
||||
info.lastTime = Math.round(time() - info.currentStart);
|
||||
info.lastTime = time() - info.currentStart;
|
||||
info.totalTime += info.lastTime;
|
||||
info.count++;
|
||||
info.currentStart = 0;
|
||||
@@ -128,12 +133,11 @@ export function profile(name?: string): MethodDecorator {
|
||||
//editing the descriptor/value parameter
|
||||
descriptor.value = function () {
|
||||
start(name);
|
||||
|
||||
var result = originalMethod.apply(this, arguments);
|
||||
|
||||
pause(name)
|
||||
|
||||
return result;
|
||||
try {
|
||||
return originalMethod.apply(this, arguments);
|
||||
} finally {
|
||||
pause(name);
|
||||
}
|
||||
};
|
||||
|
||||
// return edited descriptor as opposed to overwriting the descriptor
|
||||
|
||||
Reference in New Issue
Block a user