WorkMetricsInfo


@ExperimentalWorkMetricsApi
public final 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 enum WorkMetricsInfo.State extends Enum

Public constructors

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

final long

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

final int

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

final long

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

final long

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

final int

The specific generation of the WorkRequest.

final int

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

final @NonNull WorkMetricsInfo.State

The current WorkMetricsInfo.State of the work.

final @NonNull Map<@NonNull Integer, @NonNull Integer>

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

final @NonNull Set<@NonNull String>

The set of tags associated with the work.

final long

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

final long

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

final @NonNull UUID

The unique identifier for the WorkRequest.

final String

The worker class specified when the work request was enqueued.

final long

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

Public constructors

WorkMetricsInfo

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

public final long getEnqueueTimeMillis()

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.

getExplicitRetryCount

public final int getExplicitRetryCount()

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.

getFinishTimeMillis

public final long getFinishTimeMillis()

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

getFirstStartTimeMillis

public final long getFirstStartTimeMillis()

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

getGeneration

public final int getGeneration()

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

getRunAttemptCount

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 Result.retry, worker is stopped, app is closed.

getState

public final @NonNull WorkMetricsInfo.State getState()

The current WorkMetricsInfo.State of the work.

getStopReasonCounts

public final @NonNull Map<@NonNull Integer, @NonNull IntegergetStopReasonCounts()

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

getTags

public final @NonNull Set<@NonNull StringgetTags()

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

getTotalRuntimeMillis

public final long getTotalRuntimeMillis()

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

getUnblockTimeMillis

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

public final @NonNull UUID getWorkSpecId()

The unique identifier for the WorkRequest.

getWorkerClassName

public final String getWorkerClassName()

The worker class specified when the work request was enqueued.

getWorkerDurationMillis

public final long getWorkerDurationMillis()

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