# TimeCapture

Artifact: [androidx.benchmark:benchmark-common](https://developer.android.com/jetpack/androidx/releases/benchmark) [View Source](https://cs.android.com/search?q=file:androidx/benchmark/MetricCapture.kt+class:androidx.benchmark.TimeCapture) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.2.0)

*** ** * ** ***


```
@ExperimentalBenchmarkConfigApi
public final class TimeCapture extends MetricCapture
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.benchmark.MetricCapture](https://developer.android.com/reference/androidx/benchmark/MetricCapture) ||
|   | ↳ | [androidx.benchmark.TimeCapture](https://developer.android.com/reference/androidx/benchmark/TimeCapture) |

*** ** * ** ***

Time metric, which reports time in nanos, based on the time passed to `https://developer.android.com/reference/androidx/benchmark/TimeCapture#captureStop(kotlin.Long,kotlin.LongArray,kotlin.Int)`.

Reports elapsed time with the label from `name`, which defaults to `timeNs`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/benchmark/TimeCapture#TimeCapture(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html name)` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/benchmark/TimeCapture#capturePaused()()` Pause data collection. |
| `void` | `https://developer.android.com/reference/androidx/benchmark/TimeCapture#captureResumed()()` Resume data collection |
| `void` | `https://developer.android.com/reference/androidx/benchmark/TimeCapture#captureStart(kotlin.Long)(long timeNs)` Starts collecting data for a run. |
| `void` | `https://developer.android.com/reference/androidx/benchmark/TimeCapture#captureStop(kotlin.Long,kotlin.LongArray,kotlin.Int)(long timeNs, @https://developer.android.com/reference/androidx/annotation/NonNull long[] output, int offset)` Mark the end of a run, and store offset metrics in the output array, per sub metric. |

| ### Inherited methods |
|---|
| From [androidx.benchmark.MetricCapture](https://developer.android.com/reference/androidx/benchmark/MetricCapture) |---|---| | `boolean` | `https://developer.android.com/reference/androidx/benchmark/MetricCapture#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` | | `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html>` | `https://developer.android.com/reference/androidx/benchmark/MetricCapture#getNames()()` List of names of metrics produced by this MetricCapture. | | `int` | `https://developer.android.com/reference/androidx/benchmark/MetricCapture#hashCode()()` | |

## Public constructors

### TimeCapture

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.3.0)

```
public TimeCapture(@NonNull String name)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html name` | Metric name of the measured time, defaults to `timeNs`. |

## Public methods

### capturePaused

```
public void capturePaused()
```

Pause data collection.

### captureResumed

```
public void captureResumed()
```

Resume data collection

### captureStart

```
public void captureStart(long timeNs)
```

Starts collecting data for a run.

Called at the start of each run.

| Parameters |
|---|---|
| `long timeNs` | Current time, just before starting metrics. Can be used directly to drive a timing metric produced. |

### captureStop

```
public void captureStop(long timeNs, @NonNull long[] output, int offset)
```

Mark the end of a run, and store offset metrics in the output array, per sub metric.

To output values, store them in the output array offset by both the parameter offset, and their submetric index.

| Parameters |
|---|---|
| `long timeNs` | Time of metric capture start, in monotonic time (`https://developer.android.com/reference/java/lang/System.html#nanoTime()`) |
| `@https://developer.android.com/reference/androidx/annotation/NonNull long[] output` | LongArray sized to hold all simultaneous sub metric outputs, use `offset` as the initial position in `output` to start writing submetrics. |
| `int offset` | Offset into the output array to start writing sub metrics. |