-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1517 from V4Fire/kormanowsky/issues/1389
issues/1389 amendments by @kormanowsky
- Loading branch information
Showing
12 changed files
with
207 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
"packageManager": "[email protected]", | ||
"typings": "index.d.ts", | ||
"license": "MIT", | ||
"version": "4.0.0-beta.169", | ||
"version": "4.0.0-beta.170", | ||
"author": { | ||
"name": "kobezzza", | ||
"email": "[email protected]", | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Changelog | ||
========= | ||
|
||
> **Tags:** | ||
> - :boom: [Breaking Change] | ||
> - :rocket: [New Feature] | ||
> - :bug: [Bug Fix] | ||
> - :memo: [Documentation] | ||
> - :house: [Internal] | ||
> - :nail_care: [Polish] | ||
## 4.0.0-beta.170 (2024-12-19) | ||
|
||
#### :rocket: New Feature | ||
|
||
* Initial release |
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# core/performance | ||
|
||
The module provides an API for monitoring application performance at runtime. |
This file contains 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/*! | ||
* V4Fire Client Core | ||
* https://github.com/V4Fire/Client | ||
* | ||
* Released under the MIT license | ||
* https://github.com/V4Fire/Client/blob/master/LICENSE | ||
*/ | ||
|
||
export * from 'core/performance/measure'; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/*! | ||
* V4Fire Client Core | ||
* https://github.com/V4Fire/Client | ||
* | ||
* Released under the MIT license | ||
* https://github.com/V4Fire/Client/blob/master/LICENSE | ||
*/ | ||
|
||
/** | ||
* {@link Performance.measure} | ||
* @param args | ||
*/ | ||
export function measure(...args: Parameters<Performance['measure']>): CanUndef<ReturnType<Performance['measure']>> { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
if (typeof globalThis.performance?.measure !== 'undefined') { | ||
return performance.measure(...args); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*! | ||
* V4Fire Client Core | ||
* https://github.com/V4Fire/Client | ||
* | ||
* Released under the MIT license | ||
* https://github.com/V4Fire/Client/blob/master/LICENSE | ||
*/ | ||
|
||
//#unless node_js | ||
import { measure as webMeasure } from 'core/performance/measure/engines/web'; | ||
//#endunless | ||
|
||
/** | ||
* The measure method creates a named `PerformanceMeasure` object representing a time measurement between two marks | ||
* @param args | ||
*/ | ||
export function measure(...args: Parameters<Performance['measure']>): CanUndef<ReturnType<Performance['measure']>> { | ||
//#unless node_js | ||
return webMeasure(...args); | ||
//#endif | ||
} | ||
|
||
/** | ||
* Wraps given function `original` with performance measurement with name `measurement`. | ||
* Measurements are only enabled if IS_PROD is false. | ||
* | ||
* @param measurement | ||
* @param original | ||
*/ | ||
export function wrapWithMeasurement<TThis = unknown, TArgs extends unknown[] = unknown[], TResult = void>( | ||
measurement: string | ((this: TThis, ...args: TArgs) => CanNull<string>), | ||
original: (this: TThis, ...args: TArgs) => TResult | ||
): (this: TThis, ...args: TArgs) => TResult { | ||
if (IS_PROD) { | ||
return original; | ||
} | ||
|
||
return function wrapper(this: TThis, ...args: TArgs): TResult { | ||
const start = performance.now(); | ||
|
||
const result = original.apply(this, args); | ||
|
||
const end = performance.now(); | ||
|
||
let computedMeasurement: CanNull<string> = null; | ||
|
||
if (Object.isFunction(measurement)) { | ||
computedMeasurement = measurement.apply(this, args); | ||
|
||
} else { | ||
computedMeasurement = measurement; | ||
} | ||
|
||
if (computedMeasurement != null) { | ||
measure(computedMeasurement, {start, end}); | ||
} | ||
|
||
return result; | ||
}; | ||
} |