mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(ios): fire onDisplayed event when first frame is ready to be displayed (#5344)
* feat: add a 'profiling: lifecycle' to track startup times * feat: log when displayed event fires * feat(ios): fire onDisplayed event when first frame is ready to be displayed
This commit is contained in:
committed by
Alexander Vakrilov
parent
5bae124604
commit
1c78e4784c
34
tns-core-modules/profiling/profiling.d.ts
vendored
34
tns-core-modules/profiling/profiling.d.ts
vendored
@@ -11,10 +11,25 @@ interface TimerInfo {
|
||||
|
||||
/**
|
||||
* Profiling mode to use.
|
||||
* - `counters` Accumulates method call counts and times until dumpProfiles is called and then prints agregated statistic in the console. This is the default.
|
||||
* - `counters` Accumulates method call counts and times until dumpProfiles is called and then prints aggregated statistic in the console. This is the default.
|
||||
* - `timeline` Outputs method names along start/end timestamps in the console on the go.
|
||||
* - `lifecycle` Outputs basic non-verbose times for startup, navigation, etc.
|
||||
*/
|
||||
type InstrumentationMode = "counters" | "timeline";
|
||||
type InstrumentationMode = "counters" | "timeline" | "lifecycle";
|
||||
|
||||
/**
|
||||
* Logging levels in order of verbosity.
|
||||
*/
|
||||
export enum Level {
|
||||
none,
|
||||
lifecycle,
|
||||
timeline,
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current logging level.
|
||||
*/
|
||||
export function level(): Level;
|
||||
|
||||
/**
|
||||
* Enables profiling.
|
||||
@@ -32,8 +47,9 @@ type InstrumentationMode = "counters" | "timeline";
|
||||
* ```
|
||||
*
|
||||
* @param type Profiling mode to use.
|
||||
* - "counters" - Accumulates method call counts and times until dumpProfiles is called and then prints agregated statistic in the console. This is the default.
|
||||
* - "counters" - Accumulates method call counts and times until dumpProfiles is called and then prints aggregated statistic in the console. This is the default.
|
||||
* - "timeline" - Outputs method names along start/end timestamps in the console on the go.
|
||||
* - "lifecycle" - Outputs basic non-verbose times for startup, navigation, etc.
|
||||
*/
|
||||
export declare function enable(type?: InstrumentationMode): void;
|
||||
|
||||
@@ -132,4 +148,14 @@ export function uptime(): number;
|
||||
/**
|
||||
* Logs important messages. Contrary to console.log's behavior, the profiling log should output even for release builds.
|
||||
*/
|
||||
export function log(message: string): void;
|
||||
export function log(message: string): void;
|
||||
|
||||
/**
|
||||
* Manually output profiling messages. The `@profile` decorator is useful when measuring times that function calls take on the stack
|
||||
* but when measuring times between longer periods (startup times, times between the navigatingTo - navigatedTo events etc.)
|
||||
* you can call this method and provide manually the times to be logged.
|
||||
* @param message A string message
|
||||
* @param start The start time (see `time()`)
|
||||
* @param end The end time (see `time()`)
|
||||
*/
|
||||
export function trace(message: string, start: number, end: number): void;
|
||||
@@ -10,9 +10,8 @@ export function uptime() {
|
||||
export function log(message: string): void {
|
||||
if ((<any>global).__nslog) {
|
||||
(<any>global).__nslog("CONSOLE LOG: " + message);
|
||||
} else {
|
||||
console.log(message);
|
||||
}
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
interface TimerInfo extends TimerInfoDefinition {
|
||||
@@ -130,12 +129,24 @@ const enum MemberType {
|
||||
Instance
|
||||
}
|
||||
|
||||
export enum Level {
|
||||
none,
|
||||
lifecycle,
|
||||
timeline,
|
||||
}
|
||||
let tracingLevel: Level = Level.none;
|
||||
|
||||
let profileFunctionFactory: <F extends Function>(fn: F, name: string, type?: MemberType) => F;
|
||||
export function enable(mode: InstrumentationMode = "counters") {
|
||||
profileFunctionFactory = mode && {
|
||||
counters: countersProfileFunctionFactory,
|
||||
timeline: timelineProfileFunctionFactory
|
||||
}[mode];
|
||||
|
||||
tracingLevel = {
|
||||
lifecycle: Level.lifecycle,
|
||||
timeline: Level.timeline,
|
||||
}[mode] || Level.none;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -294,3 +305,11 @@ export function stopCPUProfile(name: string) {
|
||||
__stopCPUProfiler(name);
|
||||
}
|
||||
}
|
||||
|
||||
export function level(): Level {
|
||||
return tracingLevel;
|
||||
}
|
||||
|
||||
export function trace(message: string, start: number, end: number): void {
|
||||
log(`Timeline: Modules: ${message} (${start}ms. - ${end}ms.)`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user