FrameMetricsAggregator

open class FrameMetricsAggregator
kotlin.Any
   ↳ androidx.core.app.FrameMetricsAggregator

This class can be used to record and return data about per-frame durations. It returns those results in an array per metric type, with the results indicating how many samples were recorded for each duration value. The details of the durations data are described in getMetrics().

For more information on the various metrics tracked, see the documentation for the FrameMetrics API added in API 24 as well as the GPU Profiling guide.

Summary

Constants
static Int

The index in the metrics array where the data for TOTAL_DURATION is stored.

static Int

The index in the metrics array where the data for INPUT_DURATION is stored.

static Int

The index in the metrics array where the data for LAYOUT_MEASURE_DURATION is stored.

static Int

The index in the metrics array where the data for DRAW_DURATION is stored.

static Int

The index in the metrics array where the data for SYNC_DURATION is stored.

static Int

The index in the metrics array where the data for SYNC_DURATION is stored.

static Int

The index in the metrics array where the data for COMMAND_DURATION is stored.

static Int

The index in the metrics array where the data for DELAY_DURATION is stored.

static Int

The index in the metrics array where the data for ANIMATION_DURATION is stored.

static Int

A flag indicating that the metrics should track the total duration.

static Int

A flag indicating that the metrics should track the input duration.

static Int

A flag indicating that the metrics should track the layout duration.

static Int

A flag indicating that the metrics should track the draw duration.

static Int

A flag indicating that the metrics should track the sync duration.

static Int

A flag indicating that the metrics should track the command duration.

static Int

A flag indicating that the metrics should track the swap duration.

static Int

A flag indicating that the metrics should track the delay duration.

static Int

A flag indicating that the metrics should track the animation duration.

static Int

A flag indicating that the metrics should track all durations.

Public constructors

Constructs a FrameMetricsAggregator object that will track TOTAL_DURATION metrics.

<init>(metricTypeFlags: Int)

Constructs a FrameMetricsAggregator object that will track the metrics specified bty metricTypeFlags, which is a value derived by OR'ing together metrics constants such as TOTAL_DURATION to specify all metrics that should be tracked.

Public methods
open Unit
add(@NonNull activity: Activity)

Starts recording frame metrics for the given activity.

open Array<SparseIntArray!>?

Stops recording metrics for all Activities currently being tracked.

open Array<SparseIntArray!>?
remove(@NonNull activity: Activity)

Stops recording metrics for activity and returns the collected metrics so far.

open Array<SparseIntArray!>?

Returns the currently-collected metrics in an array of SparseIntArray objects.

open Array<SparseIntArray!>?

Resets the metrics data and returns the currently-collected metrics.

Constants

TOTAL_INDEX

static val TOTAL_INDEX: Int

The index in the metrics array where the data for TOTAL_DURATION is stored.

Value: 0

See Also

INPUT_INDEX

static val INPUT_INDEX: Int

The index in the metrics array where the data for INPUT_DURATION is stored.

Value: 1

See Also

LAYOUT_MEASURE_INDEX

static val LAYOUT_MEASURE_INDEX: Int

The index in the metrics array where the data for LAYOUT_MEASURE_DURATION is stored.

Value: 2

See Also

DRAW_INDEX

static val DRAW_INDEX: Int

The index in the metrics array where the data for DRAW_DURATION is stored.

Value: 3

See Also

SYNC_INDEX

static val SYNC_INDEX: Int

The index in the metrics array where the data for SYNC_DURATION is stored.

Value: 4

See Also

COMMAND_INDEX

static val COMMAND_INDEX: Int

The index in the metrics array where the data for SYNC_DURATION is stored.

Value: 5

See Also

SWAP_INDEX

static val SWAP_INDEX: Int

The index in the metrics array where the data for COMMAND_DURATION is stored.

Value: 6

See Also

DELAY_INDEX

static val DELAY_INDEX: Int

The index in the metrics array where the data for DELAY_DURATION is stored.

Value: 7

See Also

ANIMATION_INDEX

static val ANIMATION_INDEX: Int

The index in the metrics array where the data for ANIMATION_DURATION is stored.

Value: 8

See Also

TOTAL_DURATION

static val TOTAL_DURATION: Int

A flag indicating that the metrics should track the total duration. This flag may be OR'd with the other flags here when calling FrameMetricsAggregator(int) to indicate all of the metrics that should be tracked for that activity.

Value: 1 << TOTAL_INDEX

INPUT_DURATION

static val INPUT_DURATION: Int

A flag indicating that the metrics should track the input duration. This flag may be OR'd with the other flags here when calling FrameMetricsAggregator(int) to indicate all of the metrics that should be tracked for that activity.

Value: 1 << INPUT_INDEX

LAYOUT_MEASURE_DURATION

static val LAYOUT_MEASURE_DURATION: Int

A flag indicating that the metrics should track the layout duration. This flag may be OR'd with the other flags here when calling FrameMetricsAggregator(int) to indicate all of the metrics that should be tracked for that activity.

Value: 1 << LAYOUT_MEASURE_INDEX

DRAW_DURATION

static val DRAW_DURATION: Int

A flag indicating that the metrics should track the draw duration. This flag may be OR'd with the other flags here when calling FrameMetricsAggregator(int) to indicate all of the metrics that should be tracked for that activity.

Value: 1 << DRAW_INDEX

SYNC_DURATION

static val SYNC_DURATION: Int

A flag indicating that the metrics should track the sync duration. This flag may be OR'd with the other flags here when calling FrameMetricsAggregator(int) to indicate all of the metrics that should be tracked for that activity.

Value: 1 << SYNC_INDEX

COMMAND_DURATION

static val COMMAND_DURATION: Int

A flag indicating that the metrics should track the command duration. This flag may be OR'd with the other flags here when calling FrameMetricsAggregator(int) to indicate all of the metrics that should be tracked for that activity.

Value: 1 << COMMAND_INDEX

SWAP_DURATION

static val SWAP_DURATION: Int

A flag indicating that the metrics should track the swap duration. This flag may be OR'd with the other flags here when calling FrameMetricsAggregator(int) to indicate all of the metrics that should be tracked for that activity.

Value: 1 << SWAP_INDEX

DELAY_DURATION

static val DELAY_DURATION: Int

A flag indicating that the metrics should track the delay duration. This flag may be OR'd with the other flags here when calling FrameMetricsAggregator(int) to indicate all of the metrics that should be tracked for that activity.

Value: 1 << DELAY_INDEX

ANIMATION_DURATION

static val ANIMATION_DURATION: Int

A flag indicating that the metrics should track the animation duration. This flag may be OR'd with the other flags here when calling FrameMetricsAggregator(int) to indicate all of the metrics that should be tracked for that activity.

Value: 1 << ANIMATION_INDEX

EVERY_DURATION

static val EVERY_DURATION: Int

A flag indicating that the metrics should track all durations. This is a shorthand for OR'ing all of the duration flags. This flag may be OR'd with the other flags here when calling FrameMetricsAggregator(int) to indicate the metrics that should be tracked for that activity.

Value: 0x1ff

Public constructors

<init>

FrameMetricsAggregator()

Constructs a FrameMetricsAggregator object that will track TOTAL_DURATION metrics. If more fine-grained metrics are needed, use FrameMetricsAggregator(int) instead.

<init>

FrameMetricsAggregator(metricTypeFlags: Int)

Constructs a FrameMetricsAggregator object that will track the metrics specified bty metricTypeFlags, which is a value derived by OR'ing together metrics constants such as TOTAL_DURATION to specify all metrics that should be tracked. For example, TOTAL_DURATION | DRAW_DURATION will track both the total and draw durations for every frame.

Parameters
metricTypeFlags Int: A bitwise collection of flags indicating which metrics should be recorded.

Public methods

add

open fun add(@NonNull activity: Activity): Unit

Starts recording frame metrics for the given activity.

Parameters
activity Activity: The Activity object which will have its metrics measured.

stop

@Nullable open fun stop(): Array<SparseIntArray!>?

Stops recording metrics for all Activities currently being tracked. Like , this method returns the currently-collected metrics. Calling stop() does not reset the metrics array; you must call reset() to clear the data.

Return
Array<SparseIntArray!>?: An array whose index refers to the type of metric stored in that item's SparseIntArray object, e.g., data for TOTAL_DURATION is stored in the [TOTAL_INDEX] item.

remove

@Nullable open fun remove(@NonNull activity: Activity): Array<SparseIntArray!>?

Stops recording metrics for activity and returns the collected metrics so far. Recording will continue if there are still other activities being tracked. Calling remove() does not reset the metrics array; you must call reset() to clear the data.

Parameters
activity Activity: The Activity to stop tracking metrics for.
Return
Array<SparseIntArray!>?: An array whose index refers to the type of metric stored in that item's SparseIntArray object, e.g., data for TOTAL_DURATION is stored in the [TOTAL_INDEX] item.

See Also

getMetrics

@Nullable open fun getMetrics(): Array<SparseIntArray!>?

Returns the currently-collected metrics in an array of SparseIntArray objects. The index of the array indicates which metric's data is stored in that SparseIntArray object. For example, results for total duration will be in the [TOTAL_INDEX] item.

The return value may be null if no metrics were tracked. This is especially true on releases earlier than API 24, as the FrameMetrics system does not exist on these earlier release. If the return value is not null, any of the objects at a given index in the array may still be null, which indicates that data was not being tracked for that type of metric. For example, if the FrameMetricsAggregator was created with a call to new FrameMetricsAggregator(TOTAL_DURATION | DRAW_DURATION), then the SparseIntArray at index INPUT_INDEX will be null.

For a given non-null SparseIntArray, the results stored are the number of samples at each millisecond value (rounded). For example, if a data sample consisted of total durations of 5.1ms, 5.8ms, 6.1ms, and 8.2ms, the SparseIntArray at [TOTAL_DURATION] would have key-value pairs (5, 1), (6, 2), (8, 1).

Return
Array<SparseIntArray!>?: An array whose index refers to the type of metric stored in that item's SparseIntArray object, e.g., data for TOTAL_DURATION is stored in the [TOTAL_INDEX] item.

reset

@Nullable open fun reset(): Array<SparseIntArray!>?

Resets the metrics data and returns the currently-collected metrics.

Return
Array<SparseIntArray!>?: An array whose index refers to the type of metric stored in that item's SparseIntArray object, e.g., data for TOTAL_DURATION is stored in the [TOTAL_INDEX] item.

See Also