> 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.

# getPerformance

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

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

## 支持版本

前端库版本不低于 `0.0.42`。

## 支持平台

<table>
<thead>
<tr><th>平台</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>Android</td><td>支持</td></tr>
<tr><td>iOS</td><td>支持</td></tr>
<tr><td>PC</td><td>不支持</td></tr>
<tr><td>HarmonyOS</td><td>不支持</td></tr>
</tbody>
</table>

## 支持场景

<table>
<thead>
<tr><th>场景</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>页面</td><td>支持</td></tr>
<tr><td>卡片</td><td>支持</td></tr>
</tbody>
</table>

## 使用说明

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

## 调用方式

### 同步 API

```typescript
getPerformance(): Performance
```

## 入参

无。

## 调用示例

```typescript
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();
```

## 返回值

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

### 返回示例

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