# ProfilingCollector

> Captures request metrics and completed Yii profiler spans in the canonical Profiling panel payload.

[API reference](/docs/api/index.md) › [Yii3 Debug](/docs/extensions/yii3-debug/reference/index.md) › [Collector](/docs/extensions/yii3-debug/reference/collector/index.md) › ProfilingCollector

| final class | `Yii3\Debug\Collector\ProfilingCollector` |
| --- | --- |
| Implements | [`CollectorInterface`](https://github.com/php-forge/debug/blob/e4fbb8c3238a4d011ceef5e0094344abd50deaf4/src/CollectorInterface.php) |
| Source | [`src/Collector/ProfilingCollector.php`](https://github.com/yii3/debug/blob/main/src/Collector/ProfilingCollector.php#L28) |

Captures request metrics and completed Yii profiler spans in the canonical Profiling panel payload.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a profiling collector for live and already flushed spans. | `ProfilingCollector` |
| [`capture()`](#method-capture) | Encodes the captured spans into the Profiling panel payload. | `ProfilingCollector` |
| [`collectRequest()`](#method-collectRequest) | Records the request start when the middleware did not already supply it. | `ProfilingCollector` |
| [`collectRequestStart()`](#method-collectRequestStart) | Uses the request start already resolved by the middleware so summary and profiler timing share one origin. | `ProfilingCollector` |
| [`id()`](#method-id) | Returns the stable identifier of this collector. | `ProfilingCollector` |
| [`shutdown()`](#method-shutdown) | Stops capturing and clears the spans accumulated for the request. | `ProfilingCollector` |
| [`startup()`](#method-startup) | Starts capturing and resets the cursor into the profiler message list. | `ProfilingCollector` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(Yiisoft\Profiler\ProfilerInterface|null $profiler = null, Yii3\Debug\Profiling\DebugProfilerTarget|null $target = null)
```

Creates a profiling collector for live and already flushed spans.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$profiler` | `Yiisoft\Profiler\ProfilerInterface\|null` | Application profiler supplying the spans, or `null` when none is configured. |
| `$target` | [`Yii3\Debug\Profiling\DebugProfilerTarget`](/docs/extensions/yii3-debug/reference/profiling/debugprofilertarget/index.md)`\|null` | Target keeping the spans the profiler already flushed, or `null` when the profiler dispatches to no debugger target. |

### capture() <span id="method-capture"></span>

```php
public function capture(): array<string, mixed>|null
```

Encodes the captured spans into the Profiling panel payload.

**Returns**

`array<string, mixed>|null`: Encoded Profiling panel payload; `null` when the collector never started.

### collectRequest() <span id="method-collectRequest"></span>

```php
public function collectRequest(Psr\Http\Message\ServerRequestInterface $request): void
```

Records the request start when the middleware did not already supply it.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$request` | `Psr\Http\Message\ServerRequestInterface` | Request reaching the debugger middleware. |

### collectRequestStart() <span id="method-collectRequestStart"></span>

```php
public function collectRequestStart(float $start): void
```

Uses the request start already resolved by the middleware so summary and profiler timing share one origin.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$start` | `float` | Request start, in seconds. |

### id() <span id="method-id"></span>

```php
public function id(): string
```

Returns the stable identifier of this collector.

**Returns**

`string`: Stable ID pairing this collector with its panel.

### shutdown() <span id="method-shutdown"></span>

```php
public function shutdown(): void
```

Stops capturing and clears the spans accumulated for the request.

### startup() <span id="method-startup"></span>

```php
public function startup(): void
```

Starts capturing and resets the cursor into the profiler message list.