smr-performance-monitor
Version:
smr-performance-monitor
146 lines (145 loc) • 4.43 kB
TypeScript
export interface IMetricEntry {
start: number;
end: number;
}
export declare type IPerformanceObserverType = "largest-contentful-paint" | "longtask" | "measure" | "navigation" | "paint" | "resource" | "first-input";
export declare type IPerformanceEntryInitiatorType = "css" | "fetch" | "img" | "other" | "script" | "xmlhttprequest";
export declare interface IPerformanceEntry {
decodedBodySize?: number;
duration: number;
entryType: IPerformanceObserverType;
initiatorType?: IPerformanceEntryInitiatorType;
name: string;
startTime: number;
loadTime: number;
renderTime: number;
}
export interface IPerformanceDataConsumption {
beacon: number;
css: number;
fetch: number;
img: number;
other: number;
script: number;
total: number;
xmlhttprequest: number;
}
export interface IPerformancePaintTiming {
name: string;
entryType: string;
startTime: number;
duration: number;
}
declare type EffectiveConnectionType = "2g" | "3g" | "4g" | "slow-2g";
export interface NetworkInformation {
downlink?: number;
downlinkMax?: number;
effectiveType?: EffectiveConnectionType;
onchange?: () => void;
rtt?: number;
saveData?: boolean;
hardwareConcurrency?: number;
}
export interface IPerformanceObserver {
observer: () => void;
disconnect: () => void;
}
export interface SmrNavigationTiming {
fetchTime?: number;
workerTime?: number;
totalTime?: number;
downloadTime?: number;
timeToFirstByte?: number;
headerSize?: number;
dnsLookupTime?: number;
pageLoadTime?: number;
}
export interface BasePerfCountType {
/** 页面完渲染 + 请求耗时 */
allRenderCount?: number;
/** DNS查询时间耗时 */
dnsCount?: number;
/** 获取TCP链接时间 */
tcpDnsCount?: number;
/** 获取请求响应耗时 */
reqCount?: number;
/** 获取DOM树解析耗时 */
dParseCount?: number;
/** 获取资源加载耗时 */
resLoadCount?: number;
/** 获取DOM READY耗时 */
dclCount?: number;
/** 获取首次渲染耗时 */
fcpCount?: number;
/** 获取页面完全加载耗时 */
pldCount?: number;
/** 获取onload时间 */
oldCount?: number;
}
export default class Performance {
/**
* 是否支持 performance 判断
*/
static supported(): boolean;
/**
* 是否支持 PerformanceObserver
* Firefox 58: https://bugzilla.mozilla.org/show_bug.cgi?id=1403027
*/
static supportedPerformanceObserver(): boolean;
navigationTimingCached: SmrNavigationTiming;
private perfObserver;
private basePerfCount;
private tcpLoadCount;
constructor();
/**
* 页面性能加载获取
* developers.google.com/web/fundamentals/performance/navigation-and-resource-timing
*/
getNavigationTiming(afteronLoad?: boolean): SmrNavigationTiming;
get tcpLoadCountInfo(): number;
/**
* 页面性能加载获取
* 旧版本 smartlink
*/
private calcBasePerfCount;
/**
* 获取 basePerfCount
*/
get basePerfCountInfo(): BasePerfCountType;
/**
* 网络连接信息 https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation
*/
get networkInformation(): NetworkInformation;
/**
* 当前 性能启动的持续时间 毫秒
*/
now(): number;
/**
* 使用performance 标记 mark_metricName_type
* @param metricName
* @param type
*/
mark(metricName: string, type: string): void;
/**
* 检查存在 performance start 标记 mark_metricName_type
* @param metricName
* @param type
*/
checkStartMarkName(markName: string): boolean;
/**
* 检测 两个标记点 (过程持续时间)
* @param metricName
* @param metric
* @returns
*/
measure(metricName: string): number;
/**
* PerformanceObserver subscribes to performance events as they happen
* and respond to them asynchronously.
*/
performanceObserver(eventType: IPerformanceObserverType, cb: (entries: any[]) => void): IPerformanceObserver;
private performanceObserverCb;
getStartMarkName(name: string): string;
getEndMarkName(name: string): string;
}
export {};