# MiniStats

Class · category: Debug

Source: https://github.com/playcanvas/engine/blob/64089771243fe28a9b9d2b4de538b99b07c75097/src/extras/mini-stats/mini-stats.js#L120

MiniStats is a small graphical overlay that displays realtime performance metrics. By default,
it shows CPU and GPU durations, frame intervals, draw call count and estimated GPU resource
memory. It can also display additional counters from [AppBase#stats](https://api.playcanvas.com/engine/classes/AppBase.md#stats).

The default CPU timings, including render time, draw call count and memory estimates are
available in all builds. GPU timing requires device support and is enabled when MiniStats
creates its GPU timer. Some additional counters, such as [AppStats#primitiveCount](https://api.playcanvas.com/engine/classes/AppStats.md#primitivecount),
require a debug or profiler build. See [AppStats](https://api.playcanvas.com/engine/classes/AppStats.md) for measurement scope and availability.
In the detailed views, click a category heading to collapse or expand its sub-counters.
Click elsewhere in the overlay to change size. Collapsing a category preserves its sampling
and graph history. Resources is enabled and collapsed by default, and displays current counts
of existing tracked resources, including internal resources, in detailed views. Resource counts
refresh at textRefreshRate while visible, including their sum in the collapsed heading; they
have no average or peak. In graph views, resource histories use the latest sampled counts
and scale to accommodate the highest count seen.

## Constructors

### constructor

```ts
new MiniStats(app: AppBase, options?: MiniStatsOptions)
```

Create a new MiniStats instance.

**Parameters**

- `app` ([`AppBase`](https://api.playcanvas.com/engine/classes/AppBase.md)): The application.
- `options` ([`MiniStatsOptions`](https://api.playcanvas.com/engine/interfaces/MiniStatsOptions.md), optional): Options for the MiniStats instance.

**Example**

```ts
const miniStats = new MiniStats(app);
```

## Accessors

### cpuCollapsed

```ts
get cpuCollapsed(): boolean
set cpuCollapsed(value: boolean)
```

### enabled

```ts
get enabled(): boolean
set enabled(value: boolean)
```

### engineCollapsed

```ts
get engineCollapsed(): boolean
set engineCollapsed(value: boolean)
```

### gpuCollapsed

```ts
get gpuCollapsed(): boolean
set gpuCollapsed(value: boolean)
```

### resourcesCollapsed

```ts
get resourcesCollapsed(): boolean
set resourcesCollapsed(value: boolean)
```

### resourcesEnabled

```ts
get resourcesEnabled(): boolean
set resourcesEnabled(value: boolean)
```

### userCollapsed

```ts
get userCollapsed(): boolean
set userCollapsed(value: boolean)
```

### vramCollapsed

```ts
get vramCollapsed(): boolean
set vramCollapsed(value: boolean)
```

## Methods

### destroy

```ts
destroy(): void
```

Destroy the MiniStats instance and release its event listeners, textures and mesh.

**Example**

```ts
miniStats.destroy();
```

### getDefaultOptions

```ts
static getDefaultOptions(extraStats?: string[]): MiniStatsOptions
```

Returns options for three sizes: compact core counters, grouped averages, and grouped
averages and peaks with graph history. Engine counters appear first, starting with draw
calls and frame time, followed by User, CPU, GPU and VRAM. In the detailed views, Engine
and User have collapsible headings, omitted when empty.

**Parameters**

- `extraStats` (`string[]`, optional, default `[]`): Presets to include: 'gsplats', 'gsplatsCopy' or 'compute'.
  The 'compute' preset shows the compute dispatches and compute passes of each frame, on
  devices supporting compute shaders.

**Returns** [`MiniStatsOptions`](https://api.playcanvas.com/engine/interfaces/MiniStatsOptions.md): The default options for MiniStats.

**Example**

```ts
const options = MiniStats.getDefaultOptions(['gsplats']);
options.sizes[2].width = 280;
const miniStats = new MiniStats(app, options);
```
