my.getperformance()
基础库 2.9.9 或更高版本; 若版本较低,建议采取 兼容处理 。
支小宝客户端 支持
安诊儿客户端 支持
插件: 不支持。
主体: 企业支付宝小程序 、 个人支付宝小程序
相关文档: 小程序运行机制
获取小程序相关性能数据。
获取 performance 示例
page({
onready() {
_if (my.getperformance) {
// 获取 performance 实例
const performance = my.getperformance();
// 创建 observer
const observer = performance.createobserver((entrylist) => {
console.log(entrylist.getentries());
});
}
}
})
-
tip
this.getperformance()
返回值与 page / component 所在页面绑定,且返回值始终相同。 -
tip
setbuffersize
和setbatchtimeout
会对整个performance
生效。 -
tipcomponent 不能跨主体调用,否则返回
null
。例如:插件自定义组件无法获得宿凯发k8官方网娱乐官方主页面的performance
。 -
tip不同页面之间的
performance
的entry
是隔离的,即 a页面 无法监听 b页面 的 entry 变化。 -
tip
由于
observer
只会回调每次新增内容,若你需要完整内容,可通过performance.getentries()
获得,也可自行创建个数组存储。如:page({ data: { performancedata: [], }, onready() { const performancedata = this.data.performancedata; const performance = my.getperformance(); const observer = performance.createobserver((entrylist) => { performancedata.push(...entrylist.getentries()); }); observer.observe({ entrytypes: ['render'] }); }, });