<br />

This library defines a protocol for test clients to communicate with the metrics recorder,
specifying:

- Metrics type: e.g., temperature, CPU, GPU, network, power.
- Test duration.
- Sampling rate.
- Record processed statistics: minimum, maximum, and average values.
- Statistic processing interval (if applicable).

Added: 17

## **PROTOCOLS**

## Recorder

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=116)*

A protocol for managing on-demand metrics logging.

<br />

### StartLogging

Initiates logging of specified metrics for the provided duration.
Supports concurrent logging of different metrics. Logging may be
terminated early with a call to `StopLogging`.

This call will fail if logging of the specified metric is already
active. For this reason, a client may wish to precede a `StartLogging`
call with a `StopLogging` call, after which the only reason for The
logger to be active would be a conflict with another client.

- request `client_id` String format Id of the client. Client may choose any Id with a maximum byte size of 8 (e.g., "ffxTest").
- request `metrics` Type of the metrics to be polled and logged.
- request `duration_ms` Duration of logging in milliseconds. After this duration, polling and logging will cease.
- request `output_samples_to_syslog` Toggle for outputting raw data to syslog.
- request `output_stats_to_syslog` Toggle for outputting any available statistics to syslog.
- error a \[fuchsia.metrics.test/MeticsLoggerError\] value indicating why the request failed.

#### Request

| Name | Type |
|---|---|
| `client_id` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#ClientId` |
| `metrics` | `vector<https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#Metric>` |
| `duration_ms` | `uint32` |
| `output_samples_to_syslog` | `bool` |
| `output_stats_to_syslog` | `bool` |

#### Response

| Name | Type |
|---|---|
| `payload` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#Recorder_StartLogging_Result` |

### StartLoggingForever

Initiates logging of specified metrics. Supports concurrent logging of
different metrics. Logging will only end upon a `StopLogging` call.

`StartLogging` should be preferred for usage in automated tests to
ensure that logging terminates even if the test crashes.

- request `client_id` String format Id of the client. Client may choose any Id with a maximum byte size of 8 (e.g., "ffxTest").
- request `metrics` Type of the metrics to be polled and logged.
- request `output_samples_to_syslog` Toggle for outputting raw data to syslog.
- request `output_stats_to_syslog` Toggle for outputting any available statistics to syslog.
- error a \[fuchsia.metrics.test/RecorderError\] value indicating why the request failed.

#### Request

| Name | Type |
|---|---|
| `client_id` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#ClientId` |
| `metrics` | `vector<https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#Metric>` |
| `output_samples_to_syslog` | `bool` |
| `output_stats_to_syslog` | `bool` |

#### Response

| Name | Type |
|---|---|
| `payload` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#Recorder_StartLoggingForever_Result` |

### StopLogging

Terminates all active logging tasks with the given client_id. It is
valid to call this method when logging is inactive.

- request `client_id` String format Id of the client.

<!-- -->

- response `status` A bool value indicating if existing logging was stopped (true) or there'sno existing logging for the client.

#### Request

| Name | Type |
|---|---|
| `client_id` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#ClientId` |

#### Response

| Name | Type |
|---|---|
| `stopped` | `bool` |

## **STRUCTS**

### CpuLoad

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=76)*

CPU Load metric details.

<br />

| Field | Type | Description | Default |
|---|---|---|---|
| `interval_ms` | `uint32` | Length of the polling interval in milliseconds. Must be smaller than `duration_ms` of the logging request. Must not be smaller than 500ms if `output_samples_to_syslog` is enabled in the logging request. | No default |

### GpuUsage

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=85)*

GPU Usage metric details.

<br />

| Field | Type | Description | Default |
|---|---|---|---|
| `interval_ms` | `uint32` | Length of the polling interval in milliseconds. Must be smaller than `duration_ms` of the logging request. Must not be smaller than 500ms if `output_samples_to_syslog` is enabled in the logging request. | No default |

### NetworkActivity

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=94)*

Network Activity metric details.

<br />

| Field | Type | Description | Default |
|---|---|---|---|
| `interval_ms` | `uint32` | Length of the polling interval in milliseconds. Must be smaller than `duration_ms` of the logging request. Must not be smaller than 500ms if `output_samples_to_syslog` is enabled in the logging request. | No default |

### Power

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=103)*

Power metric details.

<br />

| Field | Type | Description | Default |
|---|---|---|---|
| `sampling_interval_ms` | `uint32` | Length of the sampling interval in milliseconds. Must not be smaller than 500ms if `output_samples_to_syslog` is enabled in the logging request. Must be smaller than `duration_ms` of the logging request. | No default |
| `statistics_args` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#StatisticsArgs?` | Boxed(optional) statistics arguments. If none, statistics is disabled. | No default |

### Recorder_StartLoggingForever_Response

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=165)*

\<EMPTY\>

### Recorder_StartLogging_Response

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=143)*

\<EMPTY\>

### StatisticsArgs

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=53)*

| Field | Type | Description | Default |
|---|---|---|---|
| `statistics_interval_ms` | `uint32` | Length of the interval in milliseconds for summarizing statistics (e.g., min, max, avg). Must be equal to or larger than `sampling_interval_ms` in the metrics. Must be smaller than `duration_ms` of the logging request. Must not be smaller than 500ms if `output_stats_to_syslog` is enabled in the logging request. | No default |

### Temperature

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=64)*

Temperature metric details.

<br />

| Field | Type | Description | Default |
|---|---|---|---|
| `sampling_interval_ms` | `uint32` | Length of the sampling interval in milliseconds. Must not be smaller than 500ms if `output_samples_to_syslog` is enabled in the logging request. Must be smaller than `duration_ms` of the logging request. | No default |
| `statistics_args` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#StatisticsArgs?` | Boxed(optional) statistics arguments. If none, statistics is disabled. | No default |

## **ENUMS**

### RecorderError [strict](https://fuchsia.dev/fuchsia-src/reference/fidl/language/language#strict-vs-flexible)

Type: `uint32`

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=22)*

Errors associated with Recorder methods.
If the request contains any of the following errors, it will fail without
affecting the existing logging tasks.

<br />

| Name | Value | Description |
|---|---|---|
| ### NO_DRIVERS | `1` | Indicates that no driver is found for requested metric logging. |
| ### INVALID_SAMPLING_INTERVAL | `2` | Indicates that an invalid sampling interval was provided. |
| ### ALREADY_LOGGING | `3` | Requests to start logging will fail if logging is already active for a given client. |
| ### DUPLICATED_METRIC | `4` | Indicates that the logging request contains duplicated metric type. |
| ### TOO_MANY_ACTIVE_CLIENTS | `5` | Indicates that the total number of active clients has reached the allowed maxium (defined by `MAX_CONCURRENT_CLIENTS = 20` in the Recorder to keep memory use bounded). |
| ### INVALID_STATISTICS_INTERVAL | `6` | Indicates that statistics is enabled and an invalid statistics interval is provided. |
| ### INTERNAL | `7` | Indicates that the request failed due to an internal error. |

## **UNIONS**

### Metric [strict](https://fuchsia.dev/fuchsia-src/reference/fidl/language/language#strict-vs-flexible)

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=45)*

Metric type requested in Recorder methods.

| Ordinal | Variant | Type | Description |
|---|---|---|---|
| ### 1 | `temperature` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#Temperature` |   |
| ### 2 | `cpu_load` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#CpuLoad` |   |
| ### 3 | `power` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#Power` |   |
| ### 4 | `gpu_usage` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#GpuUsage` |   |
| ### 5 | `network_activity` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#NetworkActivity` |   |

<br />

### Recorder_StartLoggingForever_Result [strict](https://fuchsia.dev/fuchsia-src/reference/fidl/language/language#strict-vs-flexible)

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=165)*

| Ordinal | Variant | Type | Description |
|---|---|---|---|
| ### 1 | `response` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#Recorder_StartLoggingForever_Response` |   |
| ### 2 | `err` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#RecorderError` |   |

<br />

### Recorder_StartLogging_Result [strict](https://fuchsia.dev/fuchsia-src/reference/fidl/language/language#strict-vs-flexible)

*Defined in [fuchsia.power.metrics/recorder.fidl](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=143)*

| Ordinal | Variant | Type | Description |
|---|---|---|---|
| ### 1 | `response` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#Recorder_StartLogging_Response` |   |
| ### 2 | `err` | `https://fuchsia.dev/reference/fidl/fuchsia.power.metrics#RecorderError` |   |

<br />

## **ALIASES**

| Name | Value | Description |
|---|---|---|
| [ClientId](https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.power.metrics/recorder.fidl;l=16) | `string`\[`16`\] |   |