Skip to content

Commit 68d86fb

Browse files
authored
fix(profiling): resetProfiles doesn't reset all profiles (NativeScript#5425)
1 parent 714af6b commit 68d86fb

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

tests/app/profiling/profiling-tests.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert, assertEqual, assertFalse, assertTrue, assertThrows } from "../TKUnit";
1+
import { assert, assertEqual, assertFalse, assertNull, assertTrue, assertThrows } from "../TKUnit";
22
import { enable, disable, profile, time, start, stop, timer, isRunning, resetProfiles } from "tns-core-modules/profiling";
33

44
enable();
@@ -99,6 +99,19 @@ export function test_isRunning_withReentrancy() {
9999
assertFalse(isRunning(name), "isRunning should be false after second stop");
100100
}
101101

102+
export function test_reset_profiles() {
103+
resetProfiles();
104+
const name = "test_reset_profiles";
105+
106+
start(name);
107+
stop(name);
108+
resetProfiles();
109+
110+
const res = timer(name);
111+
112+
assertNull(res);
113+
}
114+
102115
export function test_start_stop() {
103116
resetProfiles();
104117
const name = "test_start_stop";

tns-core-modules/profiling/profiling.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function start(name: string): void {
4646
runCount: 1
4747
};
4848
timers[name] = info;
49+
profileNames.push(name);
4950
}
5051
}
5152

@@ -94,7 +95,7 @@ export function isRunning(name: string): boolean {
9495

9596
function countersProfileFunctionFactory<F extends Function>(fn: F, name: string, type: MemberType = MemberType.Instance): F {
9697
profileNames.push(name);
97-
return <any>function() {
98+
return <any>function () {
9899
start(name);
99100
try {
100101
return fn.apply(this, arguments);
@@ -105,15 +106,15 @@ function countersProfileFunctionFactory<F extends Function>(fn: F, name: string,
105106
}
106107

107108
function timelineProfileFunctionFactory<F extends Function>(fn: F, name: string, type: MemberType = MemberType.Instance): F {
108-
return type === MemberType.Instance ? <any>function() {
109+
return type === MemberType.Instance ? <any>function () {
109110
const start = time();
110111
try {
111112
return fn.apply(this, arguments);
112113
} finally {
113114
const end = time();
114115
console.log(`Timeline: Modules: ${name} ${this} (${start}ms. - ${end}ms.)`);
115116
}
116-
} : function() {
117+
} : function () {
117118
const start = time();
118119
try {
119120
return fn.apply(this, arguments);
@@ -154,10 +155,10 @@ try {
154155
if (appConfig && appConfig.profiling) {
155156
enable(appConfig.profiling);
156157
}
157-
} catch(e1) {
158+
} catch (e1) {
158159
try {
159160
console.log("Profiling startup failed to figure out defaults from package.json, error: " + e1);
160-
} catch(e2) {
161+
} catch (e2) {
161162
// We can get here if an exception is thrown in the mksnapshot as there is no console there.
162163
}
163164
}

0 commit comments

Comments
 (0)