WorkMetricsInfo


@ExperimentalWorkMetricsApi
class WorkMetricsInfo


Metrics info and diagnostics about a particular 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 WorkRequest may have multiple periods and thus multiple WorkMetricsInfo associated with it.

For example, updating a worker with WorkManager.updateWork is treated as starting a new WorkMetricsInfo for the same WorkRequest. Similarly, a PeriodicWorkRequest finishing starts a new WorkMetricsInfo for the new period.

Summary

Nested types

Public constructors

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,
    explicitRetryCount: Int,
    stopReasonCounts: Map<IntInt>,
    totalRuntimeMillis: Long
)

Public properties

Long

The timestamp (since epoch) when the WorkRequest was initially enqueued or updated.

Int

The number of times this worker returned Result.retry in this period.

Long

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

Long

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

Int

The specific generation of the WorkRequest.

Int

The number of times this work has started in this period.

WorkMetricsInfo.State

The current WorkMetricsInfo.State of the work.

Map<IntInt>

How many times this work stopped for each WorkInfo.stopReason in this period.

Set<String>

The set of tags associated with the work.

Long

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

Long

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

UUID

The unique identifier for the WorkRequest.

String?

The worker class specified when the work request was enqueued.

Long

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

Public constructors

WorkMetricsInfo

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<IntInt> = emptyMap(),
    totalRuntimeMillis: Long = 0
)

Public properties

enqueueTimeMillis

val enqueueTimeMillisLong

The timestamp (since epoch) when the WorkRequest was initially enqueued or updated. For a androidx.work.PeriodicWorkRequest, this is set every time a period finishes.

explicitRetryCount

val explicitRetryCountInt

The number of times this worker returned Result.retry in this period. This is separate from implicit retries such as stopping and starting or app kills.

finishTimeMillis

val finishTimeMillisLong

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

firstStartTimeMillis

val firstStartTimeMillisLong

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

generation

val generationInt

The specific generation of the WorkRequest. The generation is incremented every time the WorkRequest is updated. See WorkInfo.generation.

runAttemptCount

val runAttemptCountInt

The number of times this work has started in this period. This can occur multiple times for various reasons e.g. worker returns Result.retry, worker is stopped, app is closed.

state

val stateWorkMetricsInfo.State

The current WorkMetricsInfo.State of the work.

stopReasonCounts

val stopReasonCountsMap<IntInt>

How many times this work stopped for each WorkInfo.stopReason in this period.

tags

val tagsSet<String>

The set of tags associated with the work. See WorkInfo.tags.

totalRuntimeMillis

val totalRuntimeMillisLong

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

unblockTimeMillis

val unblockTimeMillisLong

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

workSpecId

val workSpecIdUUID

The unique identifier for the WorkRequest.

workerClassName

val workerClassNameString?

The worker class specified when the work request was enqueued.

workerDurationMillis

val workerDurationMillisLong

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