# API reference

## `myaku(options?)`

Starts profiling and returns the `Profiler`. If one is already running (`window.__MYAKU__`), returns that one.

| Option | Default | |
| --- | --- | --- |
| `size` | `600` | Frames kept |
| `budgetMs` | 1.5x the display's frame interval | Slower frames are hitches |
| `contexts` | `true` | Count draws, uploads and compiles on canvas contexts |
| `global` | `true` | Expose as `window.__MYAKU__` |
| `engines` | `true` | Add engine spans automatically ([details](./spans)) |

## `import "myaku/auto"`

Starts the profiler and shows the overlay.

## `Profiler`

| | |
| --- | --- |
| `report()` | A `Report` for the frames in the buffer |
| `hitches()` | Every slow frame in the buffer as a `Verdict`, oldest first |
| `explain(ago = 0)` | A `Verdict` for one frame (0 = the latest) |
| `frame(ago = 0)`, `frames(count?)` | Raw `Frame`s |
| `span(name, fn)` | Time `fn` under `name`; returns what `fn` returns |
| `begin(name)` | Start a span; call the returned function to end it |
| `addSpan(name, ms)` | Add measured time to a span |
| `subscribe(fn)` | Call `fn` after every frame; returns an unsubscribe function |
| `stop()` | Restore everything Myaku wrapped |
| `budgetMs`, `displayIntervalMs`, `overheadMs`, `length`, `size`, `support` | Properties |

## `adapt(profiler, game)`

Adds engine spans for a Phaser `Game`, a PixiJS `Application` or a three.js renderer. Returns `"phaser"`, `"pixi"`, `"three"` or `undefined`.

## `overlay(profiler, options?)`

Shows the corner graph. Options: `corner` (`"top-right"` by default) and `parent`. Returns `{ element, toggle(visible?), destroy() }`.

## `Frame`

`index`, `at`, `intervalMs`, `cpuMs`, `draws`, `uploads`, `uploadBytes`, `compiles`, `heapDropBytes`, `spans`.

## `Verdict`

`frame`, `at`, `intervalMs`, `budgetMs`, `cause`, `confidence`, `summary`, `hint`, `where?` (`source`, `fn`, `line?`, `char`) and `evidence`. See [Reading verdicts](./verdicts).

## `Report`

`frames`, `seconds`, `fps`, `budgetMs`, `displayIntervalMs`, `intervalMs` (`p50`, `p95`, `p99`, `max`), `cpuMs` (`p50`, `p95`, `max`), `hitches`, `hitchesPerMinute`, `causes`, `worst`, `spans`, `perFrame`, `overheadMs`, `support`. See [Reports](./reports).