FrameMetricsAggregator
public class 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 final int |
ANIMATION_DURATION = 256A flag indicating that the metrics should track the animation duration. |
static final int |
ANIMATION_INDEX = 8The index in the metrics array where the data for |
static final int |
COMMAND_DURATION = 32A flag indicating that the metrics should track the command duration. |
static final int |
COMMAND_INDEX = 5The index in the metrics array where the data for |
static final int |
DELAY_DURATION = 128A flag indicating that the metrics should track the delay duration. |
static final int |
DELAY_INDEX = 7The index in the metrics array where the data for |
static final int |
DRAW_DURATION = 8A flag indicating that the metrics should track the draw duration. |
static final int |
DRAW_INDEX = 3The index in the metrics array where the data for |
static final int |
EVERY_DURATION = 511A flag indicating that the metrics should track all durations. |
static final int |
INPUT_DURATION = 2A flag indicating that the metrics should track the input duration. |
static final int |
INPUT_INDEX = 1The index in the metrics array where the data for |
static final int |
A flag indicating that the metrics should track the layout duration. |
static final int |
The index in the metrics array where the data for |
static final int |
SWAP_DURATION = 64A flag indicating that the metrics should track the swap duration. |
static final int |
SWAP_INDEX = 6The index in the metrics array where the data for |
static final int |
SYNC_DURATION = 16A flag indicating that the metrics should track the sync duration. |
static final int |
SYNC_INDEX = 4The index in the metrics array where the data for |
static final int |
TOTAL_DURATION = 1A flag indicating that the metrics should track the total duration. |
static final int |
TOTAL_INDEX = 0The index in the metrics array where the data for |
Public constructors |
|---|
|
Constructs a FrameMetricsAggregator object that will track |
FrameMetricsAggregator(int metricTypeFlags)Constructs a FrameMetricsAggregator object that will track the metrics specified bty |
Public methods |
|
|---|---|
void |
Starts recording frame metrics for the given activity. |
@Nullable SparseIntArray[] |
Returns the currently-collected metrics in an array of SparseIntArray objects. |
@Nullable SparseIntArray[] |
Stops recording metrics for |
@Nullable SparseIntArray[] |
reset()Resets the metrics data and returns the currently-collected metrics. |
@Nullable SparseIntArray[] |
stop()Stops recording metrics for all Activities currently being tracked. |
Constants
ANIMATION_DURATION
public static final int ANIMATION_DURATION = 256
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 to indicate all of the metrics that should be tracked for that activity.
ANIMATION_INDEX
public static final int ANIMATION_INDEX = 8
The index in the metrics array where the data for ANIMATION_DURATION is stored.
| See also | |
|---|---|
getMetrics |
COMMAND_DURATION
public static final int COMMAND_DURATION = 32
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 to indicate all of the metrics that should be tracked for that activity.
COMMAND_INDEX
public static final int COMMAND_INDEX = 5
The index in the metrics array where the data for SYNC_DURATION is stored.
| See also | |
|---|---|
getMetrics |
DELAY_DURATION
public static final int DELAY_DURATION = 128
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 to indicate all of the metrics that should be tracked for that activity.
DELAY_INDEX
public static final int DELAY_INDEX = 7
The index in the metrics array where the data for DELAY_DURATION is stored.
| See also | |
|---|---|
getMetrics |
DRAW_DURATION
public static final int DRAW_DURATION = 8
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 to indicate all of the metrics that should be tracked for that activity.
DRAW_INDEX
public static final int DRAW_INDEX = 3
The index in the metrics array where the data for DRAW_DURATION is stored.
| See also | |
|---|---|
getMetrics |
EVERY_DURATION
public static final int EVERY_DURATION = 511
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 to indicate the metrics that should be tracked for that activity.
INPUT_DURATION
public static final int INPUT_DURATION = 2
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 to indicate all of the metrics that should be tracked for that activity.
INPUT_INDEX
public static final int INPUT_INDEX = 1
The index in the metrics array where the data for INPUT_DURATION is stored.
| See also | |
|---|---|
getMetrics |
LAYOUT_MEASURE_DURATION
public static final int LAYOUT_MEASURE_DURATION = 4
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 to indicate all of the metrics that should be tracked for that activity.
LAYOUT_MEASURE_INDEX
public static final int LAYOUT_MEASURE_INDEX = 2
The index in the metrics array where the data for LAYOUT_MEASURE_DURATION is stored.
| See also | |
|---|---|
getMetrics |
SWAP_DURATION
public static final int SWAP_DURATION = 64
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 to indicate all of the metrics that should be tracked for that activity.
SWAP_INDEX
public static final int SWAP_INDEX = 6
The index in the metrics array where the data for COMMAND_DURATION is stored.
| See also | |
|---|---|
getMetrics |
SYNC_DURATION
public static final int SYNC_DURATION = 16
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 to indicate all of the metrics that should be tracked for that activity.
SYNC_INDEX
public static final int SYNC_INDEX = 4
The index in the metrics array where the data for SYNC_DURATION is stored.
| See also | |
|---|---|
getMetrics |
TOTAL_DURATION
public static final int TOTAL_DURATION = 1
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 to indicate all of the metrics that should be tracked for that activity.
TOTAL_INDEX
public static final int TOTAL_INDEX = 0
The index in the metrics array where the data for TOTAL_DURATION is stored.
| See also | |
|---|---|
getMetrics |
Public constructors
FrameMetricsAggregator
public FrameMetricsAggregator()
Constructs a FrameMetricsAggregator object that will track TOTAL_DURATION metrics. If more fine-grained metrics are needed, use FrameMetricsAggregator instead.
FrameMetricsAggregator
public FrameMetricsAggregator(int metricTypeFlags)
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 | |
|---|---|
int metricTypeFlags |
A bitwise collection of flags indicating which metrics should be recorded. |
Public methods
add
public void add(@NonNull Activity activity)
Starts recording frame metrics for the given activity.
getMetrics
public @Nullable SparseIntArray[] getMetrics()
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).
| Returns | |
|---|---|
@Nullable SparseIntArray[] |
An array whose index refers to the type of metric stored in that item's SparseIntArray object, e.g., data for |
remove
public @Nullable SparseIntArray[] remove(@NonNull Activity activity)
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.
| Returns | |
|---|---|
@Nullable SparseIntArray[] |
An array whose index refers to the type of metric stored in that item's SparseIntArray object, e.g., data for |
| See also | |
|---|---|
getMetrics |
reset
public @Nullable SparseIntArray[] reset()
Resets the metrics data and returns the currently-collected metrics.
| Returns | |
|---|---|
@Nullable SparseIntArray[] |
An array whose index refers to the type of metric stored in that item's SparseIntArray object, e.g., data for |
| See also | |
|---|---|
getMetrics |
stop
public @Nullable SparseIntArray[] stop()
Stops recording metrics for all Activities currently being tracked. Like remove, this method returns the currently-collected metrics. Calling stop() does not reset the metrics array; you must call reset to clear the data.
| Returns | |
|---|---|
@Nullable SparseIntArray[] |
An array whose index refers to the type of metric stored in that item's SparseIntArray object, e.g., data for |
| See also | |
|---|---|
remove |
|
getMetrics |