For AI agents: the complete documentation index is available at /apps-plugin/docs/llms.txt, the full documentation bundle is available at /apps-plugin/docs/llms-full.txt, and this page is available as Markdown at /apps-plugin/docs/js-api/basic/getPerformance.md.

getPerformance

获取当前应用插件的性能数据。

Entry 由客户端保存;getEntries*() 同步查询当前快照,observer 只接收新完成的 Entry。

支持版本

前端库版本不低于 0.0.42。

支持平台

平台支持情况
Android支持
iOS支持
PC不支持
HarmonyOS不支持

支持场景

场景支持情况
页面支持
卡片支持

使用说明

  • 仅在需要接收后续新完成的 Entry 时创建 observer;不再需要时调用 disconnect。

调用方式

同步 API

getPerformance(): Performance

入参

无。

调用示例

import { getPerformance } from '@doubao-dev/framework/api';

const performance = getPerformance();
const observer = performance.createObserver((entryList) => {
  console.log(entryList.getEntries());
});

performance.setBufferSize(100);
observer.observe({ entryTypes: ['render'] });
console.log(performance.getEntriesByType('render'));
observer.disconnect();

返回值

名称类型必返说明
createObserver(callback: PerformanceObserverCallback) => PerformanceObserver是创建性能观察者。调用返回对象的 `observe` 后,回调会接收之后新完成且匹配的 Entry。
getEntries() => PerformanceEntry[]是返回当前应用插件已记录的全部性能 Entry。
getEntriesByName(name: string, entryType?: string) => PerformanceEntry[]是返回指定名称的性能 Entry;传入 entryType 时同时按类型筛选。
getEntriesByType(entryType: string) => PerformanceEntry[]是返回指定 entryType 的性能 Entry。
setBufferSize(size: number) => void是设置客户端最多保留的性能 Entry 数量。

返回示例

[
  {
    "entryType": "render",
    "name": "firstRender",
    "startTime": 1730000000000,
    "duration": 42,
    "path": "pages/index/index",
    "pageId": 1
  }
]