1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and limitations under the 13 * License. 14 * 15 */ 16 17 package com.android.benchmark.ui.automation; 18 19 import android.support.annotation.IntDef; 20 21 import java.io.DataInput; 22 import java.io.DataInputStream; 23 import java.io.IOException; 24 import java.util.Arrays; 25 26 public class FrameTimingStats { 27 @IntDef ({ 28 Index.FLAGS, 29 Index.INTENDED_VSYNC, 30 Index.VSYNC, 31 Index.OLDEST_INPUT_EVENT, 32 Index.NEWEST_INPUT_EVENT, 33 Index.HANDLE_INPUT_START, 34 Index.ANIMATION_START, 35 Index.PERFORM_TRAVERSALS_START, 36 Index.DRAW_START, 37 Index.SYNC_QUEUED, 38 Index.SYNC_START, 39 Index.ISSUE_DRAW_COMMANDS_START, 40 Index.SWAP_BUFFERS, 41 Index.FRAME_COMPLETED, 42 }) 43 public @interface Index { 44 int FLAGS = 0; 45 int INTENDED_VSYNC = 1; 46 int VSYNC = 2; 47 int OLDEST_INPUT_EVENT = 3; 48 int NEWEST_INPUT_EVENT = 4; 49 int HANDLE_INPUT_START = 5; 50 int ANIMATION_START = 6; 51 int PERFORM_TRAVERSALS_START = 7; 52 int DRAW_START = 8; 53 int SYNC_QUEUED = 9; 54 int SYNC_START = 10; 55 int ISSUE_DRAW_COMMANDS_START = 11; 56 int SWAP_BUFFERS = 12; 57 int FRAME_COMPLETED = 13; 58 59 int FRAME_STATS_COUNT = 14; // must always be last 60 } 61 62 private final long[] mStats; 63 64 FrameTimingStats(long[] stats) { 65 mStats = Arrays.copyOf(stats, Index.FRAME_STATS_COUNT); 66 } 67 68 public FrameTimingStats(DataInputStream inputStream) throws IOException { 69 mStats = new long[Index.FRAME_STATS_COUNT]; 70 update(inputStream); 71 } 72 73 public void update(DataInputStream inputStream) throws IOException { 74 for (int i = 0; i < mStats.length; i++) { 75 mStats[i] = inputStream.readLong(); 76 } 77 } 78 79 public long get(@Index int index) { 80 return mStats[index]; 81 } 82 83 public long[] data() { 84 return mStats; 85 } 86 } 87