mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +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;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -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 = <any>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;
|
||||
|
Reference in New Issue
Block a user