# WorkMetricsInfo

Artifact: [androidx.work:work-analytics](https://developer.android.com/jetpack/androidx/releases/work) [View Source](https://cs.android.com/search?q=file:androidx/work/analytics/WorkMetricsInfo.kt+class:androidx.work.analytics.WorkMetricsInfo) Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

*** ** * ** ***


```
@ExperimentalWorkMetricsApi
class WorkMetricsInfo
```

<br />

*** ** * ** ***

Metrics info and diagnostics about a particular `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` period.

This represents the period of time between the run being requested and the work actually finishing. This may cover multiple run attempts (i.e. startWork calls) as the work may not finish due to being stopped, retried, etc.

A given `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` may have multiple periods and thus multiple `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo` associated with it.

For example, updating a worker with WorkManager.updateWork is treated as starting a new `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo` for the same `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest`. Similarly, a `https://developer.android.com/reference/kotlin/androidx/work/PeriodicWorkRequest` finishing starts a new `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo` for the new period.

## Summary

| ### Nested types |
|---|
| `enum https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo.State : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-enum/index.html<https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo.State>` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#WorkMetricsInfo(java.util.UUID,kotlin.Int,kotlin.String,kotlin.collections.Set,androidx.work.analytics.WorkMetricsInfo.State,kotlin.Long,kotlin.Long,kotlin.Long,kotlin.Long,kotlin.Long,kotlin.Int,kotlin.Int,kotlin.collections.Map,kotlin.Long)( workSpecId: https://developer.android.com/reference/java/util/UUID.html, generation: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, workerClassName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, tags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, state: https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo.State, enqueueTimeMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, unblockTimeMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, firstStartTimeMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, finishTimeMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, workerDurationMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, runAttemptCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, explicitRetryCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, stopReasonCounts: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>, totalRuntimeMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#enqueueTimeMillis()` The timestamp (since epoch) when the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` was initially enqueued or updated. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#explicitRetryCount()` The number of times this worker returned `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result#retry()` in this period. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#finishTimeMillis()` The timestamp (since epoch) at which this work period finished, either by succeeding, failing, cancelling, or being updated. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#firstStartTimeMillis()` The timestamp (since epoch) at which this work was first started. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#generation()` The specific generation of the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#runAttemptCount()` The number of times this work has started in this period. |
| `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo.State` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#state()` The current `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo.State` of the work. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#stopReasonCounts()` How many times this work stopped for each `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo#stopReason()` in this period. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#tags()` The set of tags associated with the work. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#totalRuntimeMillis()` The total time in milliseconds that this work ran across all its retries in this period. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#unblockTimeMillis()` The timestamp (since epoch) at which the work had all its prerequisite work finished, and it starts waiting for constraints |
| `https://developer.android.com/reference/java/util/UUID.html` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#workSpecId()` The unique identifier for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#workerClassName()` The worker class specified when the work request was enqueued. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo#workerDurationMillis()` The time in milliseconds it took for the worker to run when it actually returned a final result. |

## Public constructors

### WorkMetricsInfo

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

```
WorkMetricsInfo(
    workSpecId: UUID,
    generation: Int,
    workerClassName: String?,
    tags: Set<String>,
    state: WorkMetricsInfo.State,
    enqueueTimeMillis: Long,
    unblockTimeMillis: Long,
    firstStartTimeMillis: Long,
    finishTimeMillis: Long,
    workerDurationMillis: Long,
    runAttemptCount: Int = 0,
    explicitRetryCount: Int = 0,
    stopReasonCounts: Map<Int, Int> = emptyMap(),
    totalRuntimeMillis: Long = 0
)
```

## Public properties

### enqueueTimeMillis

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

```
val enqueueTimeMillis: Long
```

The timestamp (since epoch) when the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` was initially enqueued or updated. For a `https://developer.android.com/reference/kotlin/androidx/work/PeriodicWorkRequest`, this is set every time a period finishes.

### explicitRetryCount

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

```
val explicitRetryCount: Int
```

The number of times this worker returned `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result#retry()` in this period. This is separate from implicit retries such as stopping and starting or app kills.

### finishTimeMillis

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

```
val finishTimeMillis: Long
```

The timestamp (since epoch) at which this work period finished, either by succeeding, failing, cancelling, or being updated.

### firstStartTimeMillis

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

```
val firstStartTimeMillis: Long
```

The timestamp (since epoch) at which this work was first started.

### generation

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

```
val generation: Int
```

The specific generation of the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest`. The generation is incremented every time the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` is updated. See `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo#generation()`.

### runAttemptCount

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

```
val runAttemptCount: Int
```

The number of times this work has started in this period. This can occur multiple times for various reasons e.g. worker returns `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result#retry()`, worker is stopped, app is closed.

### state

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

```
val state: WorkMetricsInfo.State
```

The current `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfo.State` of the work.

### stopReasonCounts

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

```
val stopReasonCounts: Map<Int, Int>
```

How many times this work stopped for each `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo#stopReason()` in this period.

### tags

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

```
val tags: Set<String>
```

The set of tags associated with the work. See `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo#tags()`.

### totalRuntimeMillis

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

```
val totalRuntimeMillis: Long
```

The total time in milliseconds that this work ran across all its retries in this period.

### unblockTimeMillis

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

```
val unblockTimeMillis: Long
```

The timestamp (since epoch) at which the work had all its prerequisite work finished, and it starts waiting for constraints

### workSpecId

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

```
val workSpecId: UUID
```

The unique identifier for the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest`.

### workerClassName

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

```
val workerClassName: String?
```

The worker class specified when the work request was enqueued.

### workerDurationMillis

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

```
val workerDurationMillis: Long
```

The time in milliseconds it took for the worker to run when it actually returned a final result.