Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Getting UI performance data using FrameMetrics - Android N preview
final FrameMetrics[] metrics = {null};
Window window = getActivity().getWindow();
Handler mHandler = new Handler();
window.addOnFrameMetricsAvailableListener(new Window.OnFrameMetricsAvailableListener() {
@Override
public void onFrameMetricsAvailable(Window window, FrameMetrics frameMetrics, int i) {
metrics[0] = new FrameMetrics(frameMetrics);
}
},mHandler);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
// Send this data to custom analytcis
Log.d("Metrics", "ANIMATION_DURATION: " + metrics[0].getMetric((FrameMetrics.ANIMATION_DURATION))/Math.pow(10,6));
Log.d("Metrics", "COMMAND_ISSUE_DURATION: " + metrics[0].getMetric(FrameMetrics.COMMAND_ISSUE_DURATION)/Math.pow(10,6));
Log.d("Metrics", "DRAW_DURATION: " + metrics[0].getMetric(FrameMetrics.DRAW_DURATION)/Math.pow(10,6));
Log.d("Metrics", "FIRST_DRAW_FRAME: " + metrics[0].getMetric(FrameMetrics.FIRST_DRAW_FRAME)/Math.pow(10,6));
Log.d("Metrics", "INPUT_HANDLING_DURATION: " + metrics[0].getMetric(FrameMetrics.INPUT_HANDLING_DURATION)/Math.pow(10,6));
Log.d("Metrics", "LAYOUT_MEASURE_DURATION: " + metrics[0].getMetric(FrameMetrics.LAYOUT_MEASURE_DURATION)/Math.pow(10,6));
Log.d("Metrics", "SWAP_BUFFERS_DURATION: " + metrics[0].getMetric(FrameMetrics.SWAP_BUFFERS_DURATION)/Math.pow(10,6));
Log.d("Metrics", "SYNC_DURATION: " + metrics[0].getMetric(FrameMetrics.SYNC_DURATION)/Math.pow(10,6));
Log.d("Metrics", "TOTAL_DURATION: " + metrics[0].getMetric(FrameMetrics.TOTAL_DURATION)/Math.pow(10,6));
Log.d("Metrics", "UNKNOWN_DELAY_DURATION: " + metrics[0].getMetric(FrameMetrics.UNKNOWN_DELAY_DURATION)/Math.pow(10,6));
);
}
}, 4000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment