mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 12:57:42 +08:00
Add resetProfiles method
This commit is contained in:
5
tns-core-modules/profiling/profiling.d.ts
vendored
5
tns-core-modules/profiling/profiling.d.ts
vendored
@ -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.
|
||||||
|
@ -12,11 +12,11 @@ interface TimerInfo extends TimerInfoDefinition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use object instead of map as it is a bit faster
|
// Use object instead of map as it is a bit faster
|
||||||
const timers: { [ index: string ]: TimerInfo } = {};
|
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() {
|
||||||
@ -51,7 +51,7 @@ export function start(name: string): void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let info = timers[ name ];
|
let info = timers[name];
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
if (info.isRunning) {
|
if (info.isRunning) {
|
||||||
@ -66,7 +66,7 @@ export function start(name: string): void {
|
|||||||
currentStart: time(),
|
currentStart: time(),
|
||||||
isRunning: true
|
isRunning: true
|
||||||
};
|
};
|
||||||
timers[ name ] = info;
|
timers[name] = info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,17 +88,17 @@ export function stop(name: string): TimerInfo {
|
|||||||
let info = pauseInternal(name);
|
let info = pauseInternal(name);
|
||||||
console.log(`---- [${name}] STOP total: ${info.totalTime} count:${info.count}`);
|
console.log(`---- [${name}] STOP total: ${info.totalTime} count:${info.count}`);
|
||||||
|
|
||||||
timers[ name ] = undefined;
|
timers[name] = undefined;
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isRunning(name: string): boolean {
|
export function isRunning(name: string): boolean {
|
||||||
const info = timers[ name ];
|
const info = timers[name];
|
||||||
return !!(info && info.isRunning);
|
return !!(info && info.isRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pauseInternal(name: string): TimerInfo {
|
function pauseInternal(name: string): TimerInfo {
|
||||||
const info = timers[ name ];
|
const info = timers[name];
|
||||||
|
|
||||||
if (!info) {
|
if (!info) {
|
||||||
throw new Error(`No timer started: ${name}`);
|
throw new Error(`No timer started: ${name}`);
|
||||||
@ -156,7 +156,7 @@ export function profile(name?: string): MethodDecorator {
|
|||||||
|
|
||||||
export function dumpProfiles(): void {
|
export function dumpProfiles(): void {
|
||||||
profileNames.forEach(function (name) {
|
profileNames.forEach(function (name) {
|
||||||
const info = timers[ name ];
|
const info = timers[name];
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
console.log("---- [" + name + "] STOP total: " + info.totalTime + " count:" + info.count);
|
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) {
|
export function startCPUProfile(name: string) {
|
||||||
if (!ENABLED) {
|
if (!ENABLED) {
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user