has.getPerformance(): Performance
获取当前元服务性能相关信息。
起始版本: 2.0.6
返回值:
返回Performance对象。
示例:
const performance = has.getPerformance();
Performance.getEntries(): Array<PerformanceEntry>
该方法返回当前缓冲区中的所有性能数据。
起始版本: 2.0.6
示例:
const performance = has.getPerformance(); const entryArr = performance.getEntries();
Performance.getEntriesByType(string entryType): Array<PerformanceEntry>
获取当前缓冲区中所有类型为entryType的性能数据。
起始版本: 2.0.6
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| entryType | string | 是 | 指标类型。 |
示例:
const performance = has.getPerformance();
const entryArr = performance.getEntriesByType('navigation'); Performance.getEntriesByName(string name, string entryType): Array<PerformanceEntry>
获取当前缓冲区中所有名称为name且类型为entryType的性能数据。
起始版本: 2.0.6
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| name | string | 是 | 指标名称。 |
| entryType | string | 否 | 指标类型。 |
示例:
const performance = has.getPerformance();
const entryArr = performance.getEntriesByName('route', 'navigation'); Performance.createObserver(function callback): PerformanceObserver
创建全局性能事件监听器。
起始版本: 2.0.6
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| callback | function | 是 | 性能事件监听函数。 |
错误码信息:
| 错误码 | 错误信息 |
|---|---|
| 102 | Parameter error. Possible causes: listener should be a function. |
示例:
const callback = (entryList) => {
// 监听函数回调
};
const performance = has.getPerformance();
const observer = performance.createObserver(callback);
observer.observe({ entryTypes: ['navigation', 'render'] }); Performance.setBufferSize(number size): void
设置缓冲区大小,默认缓冲30条性能数据。
起始版本: 2.0.6
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| size | number | 是 | 性能缓存限制。范围[0, 1024]。 |
示例:
const performance = has.getPerformance(); performance.setBufferSize(10);
EntryList.getEntries(): Array<PerformanceEntry>
该方法返回当前列表中的所有性能数据。
起始版本: 2.0.6
示例:
const callback = (entryList) => {
const entryArr = entryList.getEntries();
};
const performance = has.getPerformance();
const observer = performance.createObserver(callback);
observer.observe({ entryTypes: ['navigation', 'render'] }); EntryList.getEntriesByType(string entryType): Array<PerformanceEntry>
获取当前列表中所有类型为entryType的性能数据。
起始版本: 2.0.6
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| entryType | string | 是 | 指标类型。 |
示例:
const callback = (entryList) => {
const entryArr = entryList.getEntriesByType('navigation');
};
const performance = has.getPerformance();
const observer = performance.createObserver(callback);
observer.observe({ entryTypes: ['navigation', 'render'] }); EntryList.getEntriesByName(string name, string entryType): Array<PerformanceEntry>
获取当前列表中所有名称为name且类型为entryType的性能数据。
起始版本: 2.0.6
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| name | string | 是 | 指标名称。 |
| entryType | string | 否 | 指标类型。 |
示例:
const callback = (entryList) => {
const entryArr = entryList.getEntriesByName('appLaunch', 'navigation');
};
const performance = has.getPerformance();
const observer = performance.createObserver(callback);
observer.observe({ entryTypes: ['navigation', 'render'] }); PerformanceObserver 对象,用于监听性能相关事件。
起始版本: 2.0.6
属性:
| 属性名 | 类型 | 必填 | 只读 | 描述 |
|---|---|---|---|---|
| supportedEntryTypes | Array | 是 | 是 | 获取当前支持的所有性能指标类型。 |
PerformanceObserver.observe(Object options): void
开始监听。
起始版本: 2.0.6
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| options | Object | 是 | 性能监听的指标类型集。 |
示例:
const callback = (entryList) => {
// 监听函数回调
};
const performance = has.getPerformance();
const observer = performance.createObserver(callback);
observer.observe({ entryTypes: ['navigation', 'render'] }); PerformanceObserver.disconnect(): void
停止监听。
起始版本: 2.0.6
示例:
const callback = (entryList) => {
// 监听函数回调
};
const performance = has.getPerformance();
const observer = performance.createObserver(callback);
observer.observe({ entryTypes: ['navigation', 'render'] });
observer.disconnect(); 单条性能数据。
起始版本: 2.0.6
属性:
| 属性名 | 类型 | 必填 | 只读 | 描述 |
|---|---|---|---|---|
| entryType | string | 否 | 是 | 指标类型。合法值见下表。 |
| name | string | 否 | 是 | 指标名称。合法值见下表。 |
| startTime | number | 否 | 是 | 开始时间,不同指标的具体含义会有差异。 |
| duration | number | 否 | 是 | 耗时,单位:ms。仅对于表示阶段的指标有效。 |
| path | string | 否 | 是 | 页面路径。仅render和navigation类型指标有效。 |
| referrerPath | string | 否 | 是 | 跳转来源的页面路径。仅route指标有效。 |
| pageId | number | 否 | 是 | path对应页面实例Id(随机生成,不保证递增)。仅render和navigation类型指标有效。 |
| referrerPageId | number | 否 | 是 | referrerPath对应页面实例Id(随机生成,不保证递增)。仅route指标有效。 |
| navigationStart | number | 否 | 是 | 路由真正响应开始时间。仅navigation类型指标有效。 |
| navigationType | string | 否 | 是 | 路由详细类型,与元服务路由方法对应。仅navigation类型指标有效。 |
| moduleName | string | 否 | 是 | 分包名,主包表示为APP。仅evaluateScript指标有效。 |
| fileList | Array<string> | 否 | 是 | 注入文件列表。仅evaluateScript指标有效。 |
| viewLayerReadyTime | number | 否 | 是 | 渲染层代码注入完成时间。仅firstRender指标有效。 |
| initDataSendTime | number | 否 | 是 | 首次渲染参数从逻辑层发出的时间。仅firstRender指标有效。 |
| initDataRecvTime | number | 否 | 是 | 首次渲染参数在渲染层收到的时间。仅firstRender指标有效。 |
| viewLayerRenderStartTime | number | 否 | 是 | 渲染层执行渲染开始时间。仅firstRender指标有效。 |
| viewLayerRenderEndTime | number | 否 | 是 | 渲染层执行渲染结束时间。仅firstRender指标有效。 |
| packageName | string | 否 | 是 | 代码包名称。仅downloadPackage指标有效。 |
| packageSize | number | 否 | 是 | 代码包大小,单位:B。仅downloadPackage指标有效。 |
| uri | string | 否 | 是 | 资源路径。仅resourceTiming指标有效。 |
| initiatorType | string | 否 | 是 | 初始化性能条目的资源类型。仅resourceTiming指标有效。合法值见下表。 |
| transferSize | number | 否 | 是 | 表示获取资源的大小(以八位字节为单位)的数字。仅resourceTiming指标有效。 |
| domainLookupStart | number | 否 | 是 | 解析域名开始时间。仅resourceTiming指标有效。 |
| domainLookupEnd | number | 否 | 是 | 解析域名结束时间。仅resourceTiming指标有效。 |
| 合法值 | 说明 |
|---|---|
| appLaunch | 元服务启动耗时(entryType: navigation)。 |
| route | 路由处理耗时(entryType: navigation)。 |
| firstRender | 页面首次渲染耗时(entryType: render)。 |
| firstPaint | 页面首次绘制(FP)时间点,无duration(entryType: render)。 |
| firstContentfulPaint | 页面首次内容绘制(FCP)时间点,无duration(entryType: render)。 |
| largestContentfulPaint | 页面最大内容绘制(LCP)时间点,无duration(entryType: render)。 |
| evaluateScript | 逻辑层JS代码注入耗时(entryType: script)。 |
| downloadPackage | 代码包下载耗时(entryType: loadPackage)。 |
| resourceTiming | 视图层资源加载耗时(entryType: resource)。 |