# 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
class TimeCapture : MetricCapture
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.benchmark.MetricCapture](https://developer.android.com/reference/kotlin/androidx/benchmark/MetricCapture) ||
|   | ↳ | [androidx.benchmark.TimeCapture](https://developer.android.com/reference/kotlin/androidx/benchmark/TimeCapture) |

*** ** * ** ***

Time metric, which reports time in nanos, based on the time passed to `https://developer.android.com/reference/kotlin/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/kotlin/androidx/benchmark/TimeCapture#TimeCapture(kotlin.String)(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/benchmark/TimeCapture#capturePaused()()` Pause data collection. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/benchmark/TimeCapture#captureResumed()()` Resume data collection |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/benchmark/TimeCapture#captureStart(kotlin.Long)(timeNs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Starts collecting data for a run. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/benchmark/TimeCapture#captureStop(kotlin.Long,kotlin.LongArray,kotlin.Int)(timeNs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, output: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long-array/index.html, offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Mark the end of a run, and store offset metrics in the output array, per sub metric. |

| ### Inherited functions |
|---|
| From [androidx.benchmark.MetricCapture](https://developer.android.com/reference/kotlin/androidx/benchmark/MetricCapture) |---|---| | `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/benchmark/MetricCapture#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/benchmark/MetricCapture#hashCode()()` | |

| ### Inherited properties |
|---|
| From [androidx.benchmark.MetricCapture](https://developer.android.com/reference/kotlin/androidx/benchmark/MetricCapture) |---|---| | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | `https://developer.android.com/reference/kotlin/androidx/benchmark/MetricCapture#names()` List of names of metrics produced by this MetricCapture. | |

## Public constructors

### TimeCapture

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

```
TimeCapture(name: String = "timeNs")
```

| Parameters |
|---|---|
| `name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html = "timeNs"` | Metric name of the measured time, defaults to `timeNs`. |

## Public functions

### capturePaused

```
open fun capturePaused(): Unit
```

Pause data collection.

### captureResumed

```
open fun captureResumed(): Unit
```

Resume data collection

### captureStart

```
open fun captureStart(timeNs: Long): Unit
```

Starts collecting data for a run.

Called at the start of each run.

| Parameters |
|---|---|
| `timeNs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | Current time, just before starting metrics. Can be used directly to drive a timing metric produced. |

### captureStop

```
open fun captureStop(timeNs: Long, output: LongArray, offset: Int): Unit
```

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 |
|---|---|
| `timeNs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | Time of metric capture start, in monotonic time (`https://developer.android.com/reference/java/lang/System.html#nanoTime()`) |
| `output: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long-array/index.html` | LongArray sized to hold all simultaneous sub metric outputs, use `offset` as the initial position in `output` to start writing submetrics. |
| `offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Offset into the output array to start writing sub metrics. |