Back to Uni App

Get Performance

docs/api/get-performance.md

2.3.39.7 KB
Original Source

uni.getPerformance

返回一个Performance对象实例

getPerformance 兼容性

Web微信小程序AndroidiOSHarmonyOSHarmonyOS(Vapor)
<a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a>4.413.914.254.61<a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a>

返回值

类型
Performance

Performance 的方法 @performance-values

createObserver(callback: PerformanceObserverCallback): PerformanceObserver @createobserver

createObserver 创建全局性能事件监听器

createObserver 兼容性
Web微信小程序AndroidiOSHarmonyOS
x4.41---
参数
名称类型必填默认值兼容性描述
callback(entries: PerformanceObserverEntryList) => void-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -
PerformanceObserverEntryList 的方法 @performanceobserverentrylist-values
getEntries(): PerformanceEntry[] @getentries

getEntries 该方法返回当前列表中的所有性能数据

getEntries 兼容性
Web微信小程序AndroidiOSHarmonyOS
x----
返回值
类型
Array<PerformanceEntry>

Array<PerformanceEntry> 的属性描述

名称类型必备默认值兼容性描述
entryTypestring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -指标类型
namestring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -指标名称
durationnumber-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -耗时 ms。仅对于表示阶段的指标有效。
startTimenumber-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -开始时间,不同指标的具体含义会有差异。
pathstring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -页面路径。仅 render 和 navigation 类型指标有效。
referrerPathstring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -页面跳转来源页面路径。仅 route 指标有效。
pageIdnumber-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -path 对应页面实例 Id(随机生成,不保证递增)。仅 render/navigation 指标有效。
referrerPageIdnumber-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -referrerPath对应页面实例 Id(随机生成,不保证递增)。仅 route 指标有效。
navigationStartnumber-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -路由真正响应开始时间。仅 navigation 类型指标有效。
navigationTypestring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -路由详细类型,与路由方法对应。仅 navigation 类型指标有效。
initDataRecvTimenumber-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -首次渲染参数在渲染层收到的时间。仅 firstRender 指标有效。
viewLayerRenderEndTimenumber-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -渲染层执行渲染结束时间。仅 firstRender 指标有效。
getEntriesByType(entryType: string): PerformanceEntry[] @getentriesbytype

getEntriesByType 获取当前列表中所有类型为 [entryType]的性能数据

getEntriesByType 兼容性
Web微信小程序AndroidiOSHarmonyOS
x----
参数
名称类型必填默认值兼容性描述
entryTypestring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -
返回值
类型
Array<PerformanceEntry>
getEntriesByName(name: string, entryType: string): PerformanceEntry[] @getentriesbyname

getEntriesByName 获取当前列表中所有名称为 [name] 且类型为 [entryType]的性能数据

getEntriesByName 兼容性
Web微信小程序AndroidiOSHarmonyOS
x----
参数
名称类型必填默认值兼容性描述
namestring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -
entryTypestring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -
返回值
类型
Array<PerformanceEntry>
返回值
类型
PerformanceObserver
PerformanceObserver 的方法 @performanceobserver-values
observe(options: PerformanceObserverOptions): void @observe

observe 开始监听

observe 兼容性
Web微信小程序AndroidiOSHarmonyOS
x----
参数
名称类型必填默认值兼容性描述
optionsPerformanceObserverOptions-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -

options 的属性描述

名称类型必备默认值兼容性描述
bufferedboolean-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -
entryTypesArray<string>-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -
typestring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -
disconnect(): void @disconnect

disconnect 停止监听

disconnect 兼容性
Web微信小程序AndroidiOSHarmonyOS
x----

getEntries(): PerformanceEntry[] @getentries

getEntries 该方法返回当前缓冲区中的所有性能数据

getEntries 兼容性
Web微信小程序AndroidiOSHarmonyOS
x4.41---
返回值
类型
Array<PerformanceEntry>

getEntriesByType(entryType: string): PerformanceEntry[] @getentriesbytype

getEntriesByType 获取当前缓冲区中所有类型为 [entryType]的性能数据

getEntriesByType 兼容性
Web微信小程序AndroidiOSHarmonyOS
x4.41---
参数
名称类型必填默认值兼容性描述
entryTypestring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -
返回值
类型
Array<PerformanceEntry>

getEntriesByName(name: string, entryType: string): PerformanceEntry[] @getentriesbyname

getEntriesByName 获取当前缓冲区中所有名称为 [name] 且类型为 [entryType]的性能数据

getEntriesByName 兼容性
Web微信小程序AndroidiOSHarmonyOS
x4.41---
参数
名称类型必填默认值兼容性描述
namestring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -
entryTypestring-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -
返回值
类型
Array<PerformanceEntry>

setBufferSize(size: number): void @setbuffersize

setBufferSize 设置缓冲区大小,默认缓冲 30 条性能数据

setBufferSize 兼容性
Web微信小程序AndroidiOSHarmonyOS
x4.41---
参数
名称类型必填默认值兼容性描述
sizenumber-Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -

参见

<!-- UTSAPIJSON.getPerformance.example -->

通用类型

GeneralCallbackResult

名称类型必备默认值兼容性描述
errMsgstring-Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: -错误信息