| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff 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"; | ||
| 2 | 2 | import { enable, disable, profile, time, start, stop, timer, isRunning, resetProfiles } from "tns-core-modules/profiling"; | |
| 3 | 3 | ||
| 4 | 4 | enable(); | |
@@ -99,6 +99,19 @@ export function test_isRunning_withReentrancy() { | |||
| 99 | 99 | assertFalse(isRunning(name), "isRunning should be false after second stop"); | |
| 100 | 100 | } | |
| 101 | 101 | ||
| 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 | + | ||
| 102 | 115 | export function test_start_stop() { | |
| 103 | 116 | resetProfiles(); | |
| 104 | 117 | const name = "test_start_stop"; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,7 @@ export function start(name: string): void { | |||
| 46 | 46 | runCount: 1 | |
| 47 | 47 | }; | |
| 48 | 48 | timers[name] = info; | |
| 49 | + profileNames.push(name); | ||
| 49 | 50 | } | |
| 50 | 51 | } | |
| 51 | 52 | ||
@@ -94,7 +95,7 @@ export function isRunning(name: string): boolean { | |||
| 94 | 95 | ||
| 95 | 96 | function countersProfileFunctionFactory<F extends Function>(fn: F, name: string, type: MemberType = MemberType.Instance): F { | |
| 96 | 97 | profileNames.push(name); | |
| 97 | - return <any>function() { | ||
| 98 | + return <any>function () { | ||
| 98 | 99 | start(name); | |
| 99 | 100 | try { | |
| 100 | 101 | return fn.apply(this, arguments); | |
@@ -105,15 +106,15 @@ function countersProfileFunctionFactory<F extends Function>(fn: F, name: string, | |||
| 105 | 106 | } | |
| 106 | 107 | ||
| 107 | 108 | 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 () { | ||
| 109 | 110 | const start = time(); | |
| 110 | 111 | try { | |
| 111 | 112 | return fn.apply(this, arguments); | |
| 112 | 113 | } finally { | |
| 113 | 114 | const end = time(); | |
| 114 | 115 | console.log(`Timeline: Modules: ${name} ${this} (${start}ms. - ${end}ms.)`); | |
| 115 | 116 | } | |
| 116 | - } : function() { | ||
| 117 | + } : function () { | ||
| 117 | 118 | const start = time(); | |
| 118 | 119 | try { | |
| 119 | 120 | return fn.apply(this, arguments); | |
@@ -154,10 +155,10 @@ try { | |||
| 154 | 155 | if (appConfig && appConfig.profiling) { | |
| 155 | 156 | enable(appConfig.profiling); | |
| 156 | 157 | } | |
| 157 | - } catch(e1) { | ||
| 158 | + } catch (e1) { | ||
| 158 | 159 | try { | |
| 159 | 160 | console.log("Profiling startup failed to figure out defaults from package.json, error: " + e1); | |
| 160 | - } catch(e2) { | ||
| 161 | + } catch (e2) { | ||
| 161 | 162 | // We can get here if an exception is thrown in the mksnapshot as there is no console there. | |
| 162 | 163 | } | |
| 163 | 164 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments