> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# DevTools

Renderer counters you can show on screen, and named traces for Lynx's performance timeline. `import { LynxDevTools, LynxPerformance, type DevToolsStats, type LynxTraceOptions } from '@blotch/angular-lynx';`

## Usage

```typescript title="src/app/debug-panel.ts"
import { Component, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxDevTools } from '@blotch/angular-lynx';

@Component({
  selector: 'app-debug-panel',
  imports: [LYNX_ELEMENTS],
  template: `
    <view (bindtap)="devtools.refresh()">
      <text>Change detection runs: {{ devtools.stats().cdCycles }}</text>
      <text>Elements created: {{ devtools.stats().elementCreated }}</text>
    </view>
  `,
})
export class DebugPanel {
  readonly devtools = inject(LynxDevTools);
}
```

## API

### `LynxDevTools`

```typescript
@Injectable({ providedIn: 'root' })
class LynxDevTools {}
```

Reads the counters that AngularLynx's renderer keeps. They count only in development builds. In a production build, they stay at `0`.

### `LynxDevTools.stats`

```typescript
readonly stats: Signal<DevToolsStats>;
```

The counters as a signal. It doesn't update by itself: call `refresh()` to read new values.

### `LynxDevTools.refresh()`

```typescript
refresh(): void;
```

Updates `stats` with the current counter values.

### `LynxDevTools.snapshot()`

```typescript
snapshot(): DevToolsStats;
```

Returns the current counter values once, without a signal.

### `LynxDevTools.reset()`

```typescript
reset(): void;
```

Sets every counter to `0` and updates `stats`.

### `LynxPerformance`

```typescript
@Injectable({ providedIn: 'root' })
class LynxPerformance {}
```

Adds your own named traces and marks to the performance recording that [Lynx DevTool](/guide/glossary.md#lynx-devtool) (the desktop debugger app) captures. Unlike the counters, it works in every build, not only development builds, so you can trace the build you ship. Every method does nothing when Lynx's tracing API isn't available.

In the web preview, the traces go to the browser's performance timeline instead. Each trace becomes a User Timing measure, and each mark a User Timing mark, with the options in its `detail`. Chrome DevTools shows them in the Performance panel's **Timings** track.

### `LynxPerformance.isRecording()`

```typescript
isRecording(): boolean;
```

Returns `true` while a recording is running. In the web preview, it always returns `true`, since the browser's performance timeline is always on.

### `LynxPerformance.profileStart()`

```typescript
profileStart(name: string, options?: LynxTraceOptions): void;
```

Starts a named trace. Pair each call with `profileEnd()`. Traces nest. See [`LynxTraceOptions`](#lynxtraceoptions) for the options.

### `LynxPerformance.profileEnd()`

```typescript
profileEnd(): void;
```

Ends the most recently started trace.

### `LynxPerformance.profileMark()`

```typescript
profileMark(name: string, options?: LynxTraceOptions): void;
```

Records a single point in time. It takes the same [options](#lynxtraceoptions) as `profileStart()`, so a `flowId` links a mark to traces too.

### `LynxPerformance.profileFlowId()`

```typescript
profileFlowId(): number;
```

Returns a new ID for linking traces, for example across threads. Returns `0` when tracing isn't available.

## Types

### `DevToolsStats`

```typescript
type DevToolsStats = {
  cdCycles: number;
  elementCreated: number;
  elementRemoved: number;
  flushCount: number;
  lastCdDurationMs: number;
};
```

| Field              | Description                                                                                                                                                           |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cdCycles`         | Change detection runs since start or the last `reset()`.                                                                                                              |
| `elementCreated`   | Lynx elements created.                                                                                                                                                |
| `elementRemoved`   | Lynx elements removed.                                                                                                                                                |
| `flushCount`       | Times the renderer sent a batch of changes to Lynx.                                                                                                                   |
| `lastCdDurationMs` | How long the most recent change detection run took, in milliseconds, including sending its changes to Lynx. Whole milliseconds on a device, finer in the web preview. |

### `LynxTraceOptions`

```typescript
type LynxTraceOptions = {
  flowId?: number;
  flowIds?: number[];
  args?: Record<string, string>;
};
```

The options of `profileStart()` and `profileMark()`, the same as Lynx's own `TraceOption`.

| Option    | Description                                                                                                         |
| --------- | ------------------------------------------------------------------------------------------------------------------- |
| `flowId`  | Links this trace to the others with the same ID, from `profileFlowId()`. Ignored when `flowIds` is set.             |
| `flowIds` | Links this trace to several flows at once.                                                                          |
| `args`    | Values recorded with the trace. Strings only: Lynx drops any other value, so convert numbers with `String()` first. |

## Related

- [Profiling performance](/guide/profiling.md)
- [Debugging](/guide/debugging.md)
