mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
fix(profiling): resetProfiles doesn't reset all profiles (#5425)
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { assert, assertEqual, assertFalse, assertTrue, assertThrows } from "../TKUnit";
|
import { assert, assertEqual, assertFalse, assertNull, assertTrue, assertThrows } from "../TKUnit";
|
||||||
import { enable, disable, profile, time, start, stop, timer, isRunning, resetProfiles } from "tns-core-modules/profiling";
|
import { enable, disable, profile, time, start, stop, timer, isRunning, resetProfiles } from "tns-core-modules/profiling";
|
||||||
|
|
||||||
enable();
|
enable();
|
||||||
@ -99,6 +99,19 @@ export function test_isRunning_withReentrancy() {
|
|||||||
assertFalse(isRunning(name), "isRunning should be false after second stop");
|
assertFalse(isRunning(name), "isRunning should be false after second stop");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function test_reset_profiles() {
|
||||||
|
resetProfiles();
|
||||||
|
const name = "test_reset_profiles";
|
||||||
|
|
||||||
|
start(name);
|
||||||
|
stop(name);
|
||||||
|
resetProfiles();
|
||||||
|
|
||||||
|
const res = timer(name);
|
||||||
|
|
||||||
|
assertNull(res);
|
||||||
|
}
|
||||||
|
|
||||||
export function test_start_stop() {
|
export function test_start_stop() {
|
||||||
resetProfiles();
|
resetProfiles();
|
||||||
const name = "test_start_stop";
|
const name = "test_start_stop";
|
||||||
|
@ -46,6 +46,7 @@ export function start(name: string): void {
|
|||||||
runCount: 1
|
runCount: 1
|
||||||
};
|
};
|
||||||
timers[name] = info;
|
timers[name] = info;
|
||||||
|
profileNames.push(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ export function isRunning(name: string): boolean {
|
|||||||
|
|
||||||
function countersProfileFunctionFactory<F extends Function>(fn: F, name: string, type: MemberType = MemberType.Instance): F {
|
function countersProfileFunctionFactory<F extends Function>(fn: F, name: string, type: MemberType = MemberType.Instance): F {
|
||||||
profileNames.push(name);
|
profileNames.push(name);
|
||||||
return <any>function() {
|
return <any>function () {
|
||||||
start(name);
|
start(name);
|
||||||
try {
|
try {
|
||||||
return fn.apply(this, arguments);
|
return fn.apply(this, arguments);
|
||||||
@ -105,7 +106,7 @@ function countersProfileFunctionFactory<F extends Function>(fn: F, name: string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
function timelineProfileFunctionFactory<F extends Function>(fn: F, name: string, type: MemberType = MemberType.Instance): F {
|
function timelineProfileFunctionFactory<F extends Function>(fn: F, name: string, type: MemberType = MemberType.Instance): F {
|
||||||
return type === MemberType.Instance ? <any>function() {
|
return type === MemberType.Instance ? <any>function () {
|
||||||
const start = time();
|
const start = time();
|
||||||
try {
|
try {
|
||||||
return fn.apply(this, arguments);
|
return fn.apply(this, arguments);
|
||||||
@ -113,7 +114,7 @@ function timelineProfileFunctionFactory<F extends Function>(fn: F, name: string,
|
|||||||
const end = time();
|
const end = time();
|
||||||
console.log(`Timeline: Modules: ${name} ${this} (${start}ms. - ${end}ms.)`);
|
console.log(`Timeline: Modules: ${name} ${this} (${start}ms. - ${end}ms.)`);
|
||||||
}
|
}
|
||||||
} : function() {
|
} : function () {
|
||||||
const start = time();
|
const start = time();
|
||||||
try {
|
try {
|
||||||
return fn.apply(this, arguments);
|
return fn.apply(this, arguments);
|
||||||
@ -154,10 +155,10 @@ try {
|
|||||||
if (appConfig && appConfig.profiling) {
|
if (appConfig && appConfig.profiling) {
|
||||||
enable(appConfig.profiling);
|
enable(appConfig.profiling);
|
||||||
}
|
}
|
||||||
} catch(e1) {
|
} catch (e1) {
|
||||||
try {
|
try {
|
||||||
console.log("Profiling startup failed to figure out defaults from package.json, error: " + e1);
|
console.log("Profiling startup failed to figure out defaults from package.json, error: " + e1);
|
||||||
} catch(e2) {
|
} catch (e2) {
|
||||||
// We can get here if an exception is thrown in the mksnapshot as there is no console there.
|
// We can get here if an exception is thrown in the mksnapshot as there is no console there.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user