FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(profiling): resetProfiles doesn't reset all profiles by MartoYankov · Pull Request #5425 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 14 additions & 1 deletion tests/app/profiling/profiling-tests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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";

enable();
Expand Down Expand Up @@ -99,6 +99,19 @@ export function test_isRunning_withReentrancy() {
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() {
resetProfiles();
const name = "test_start_stop";
Expand Down
11 changes: 6 additions & 5 deletions tns-core-modules/profiling/profiling.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function start(name: string): void {
runCount: 1
};
timers[name] = info;
profileNames.push(name);
}
}

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

function countersProfileFunctionFactory<F extends Function>(fn: F, name: string, type: MemberType = MemberType.Instance): F {
profileNames.push(name);
return <any>function() {
return <any>function () {
start(name);
try {
return fn.apply(this, arguments);
Expand All @@ -105,15 +106,15 @@ function countersProfileFunctionFactory<F extends Function>(fn: F, name: string,
}

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();
try {
return fn.apply(this, arguments);
} finally {
const end = time();
console.log(`Timeline: Modules: ${name} ${this} (${start}ms. - ${end}ms.)`);
}
} : function() {
} : function () {
const start = time();
try {
return fn.apply(this, arguments);
Expand Down Expand Up @@ -154,10 +155,10 @@ try {
if (appConfig && appConfig.profiling) {
enable(appConfig.profiling);
}
} catch(e1) {
} catch (e1) {
try {
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.
}
}
Expand Down

Back | FazBrowse Home | New Git URL