# 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
public final class WorkMetricsInfo
```

<br />

*** ** * ** ***

Metrics info and diagnostics about a particular `https://developer.android.com/reference/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/androidx/work/WorkRequest` may have multiple periods and thus multiple `https://developer.android.com/reference/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/androidx/work/analytics/WorkMetricsInfo` for the same `https://developer.android.com/reference/androidx/work/WorkRequest`. Similarly, a `https://developer.android.com/reference/androidx/work/PeriodicWorkRequest` finishing starts a new `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo` for the new period.

## Summary

| ### Nested types |
|---|
| `public enum https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State extends https://developer.android.com/reference/java/lang/Enum.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State>` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/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)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html workSpecId, int generation, https://developer.android.com/reference/java/lang/String.html workerClassName, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> tags, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State state, long enqueueTimeMillis, long unblockTimeMillis, long firstStartTimeMillis, long finishTimeMillis, long workerDurationMillis, int runAttemptCount, int explicitRetryCount, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html> stopReasonCounts, long totalRuntimeMillis )` |

| ### Public methods |
|---|---|
| `final long` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getEnqueueTimeMillis()()` The timestamp (since epoch) when the `https://developer.android.com/reference/androidx/work/WorkRequest` was initially enqueued or updated. |
| `final int` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getExplicitRetryCount()()` The number of times this worker returned `https://developer.android.com/reference/androidx/work/ListenableWorker.Result#retry()` in this period. |
| `final long` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getFinishTimeMillis()()` The timestamp (since epoch) at which this work period finished, either by succeeding, failing, cancelling, or being updated. |
| `final long` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getFirstStartTimeMillis()()` The timestamp (since epoch) at which this work was first started. |
| `final int` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getGeneration()()` The specific generation of the `https://developer.android.com/reference/androidx/work/WorkRequest`. |
| `final int` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getRunAttemptCount()()` The number of times this work has started in this period. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getState()()` The current `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo.State` of the work. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html>` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getStopReasonCounts()()` How many times this work stopped for each `https://developer.android.com/reference/androidx/work/WorkInfo#stopReason()` in this period. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html>` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getTags()()` The set of tags associated with the work. |
| `final long` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getTotalRuntimeMillis()()` The total time in milliseconds that this work ran across all its retries in this period. |
| `final long` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getUnblockTimeMillis()()` The timestamp (since epoch) at which the work had all its prerequisite work finished, and it starts waiting for constraints |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getWorkSpecId()()` The unique identifier for the `https://developer.android.com/reference/androidx/work/WorkRequest`. |
| `final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getWorkerClassName()()` The worker class specified when the work request was enqueued. |
| `final long` | `https://developer.android.com/reference/androidx/work/analytics/WorkMetricsInfo#getWorkerDurationMillis()()` 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)

```
public WorkMetricsInfo(
    @NonNull UUID workSpecId,
    int generation,
    String workerClassName,
    @NonNull Set<@NonNull String> tags,
    @NonNull WorkMetricsInfo.State state,
    long enqueueTimeMillis,
    long unblockTimeMillis,
    long firstStartTimeMillis,
    long finishTimeMillis,
    long workerDurationMillis,
    int runAttemptCount,
    int explicitRetryCount,
    @NonNull Map<@NonNull Integer, @NonNull Integer> stopReasonCounts,
    long totalRuntimeMillis
)
```

## Public methods

### getEnqueueTimeMillis

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

```
public final long getEnqueueTimeMillis()
```

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

### getExplicitRetryCount

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

```
public final int getExplicitRetryCount()
```

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

### getFinishTimeMillis

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

```
public final long getFinishTimeMillis()
```

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

### getFirstStartTimeMillis

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

```
public final long getFirstStartTimeMillis()
```

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

### getGeneration

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

```
public final int getGeneration()
```

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

### getRunAttemptCount

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

```
public final int getRunAttemptCount()
```

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/androidx/work/ListenableWorker.Result#retry()`, worker is stopped, app is closed.

### getState

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

```
public final @NonNull WorkMetricsInfo.State getState()
```

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

### getStopReasonCounts

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

```
public final @NonNull Map<@NonNull Integer, @NonNull Integer> getStopReasonCounts()
```

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

### getTags

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

```
public final @NonNull Set<@NonNull String> getTags()
```

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

### getTotalRuntimeMillis

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

```
public final long getTotalRuntimeMillis()
```

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

### getUnblockTimeMillis

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

```
public final long getUnblockTimeMillis()
```

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

### getWorkSpecId

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

```
public final @NonNull UUID getWorkSpecId()
```

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

### getWorkerClassName

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

```
public final String getWorkerClassName()
```

The worker class specified when the work request was enqueued.

### getWorkerDurationMillis

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

```
public final long getWorkerDurationMillis()
```

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