mobile/android/base/gfx/PanningPerfAPI.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 package org.mozilla.gecko.gfx;
michael@0 7
michael@0 8 import org.mozilla.gecko.mozglue.RobocopTarget;
michael@0 9
michael@0 10 import android.os.SystemClock;
michael@0 11 import android.util.Log;
michael@0 12
michael@0 13 import java.util.ArrayList;
michael@0 14 import java.util.List;
michael@0 15
michael@0 16 public class PanningPerfAPI {
michael@0 17 private static final String LOGTAG = "GeckoPanningPerfAPI";
michael@0 18
michael@0 19 // make this large enough to avoid having to resize the frame time
michael@0 20 // list, as that may be expensive and impact the thing we're trying
michael@0 21 // to measure.
michael@0 22 private static final int EXPECTED_FRAME_COUNT = 2048;
michael@0 23
michael@0 24 private static boolean mRecordingFrames = false;
michael@0 25 private static List<Long> mFrameTimes;
michael@0 26 private static long mFrameStartTime;
michael@0 27
michael@0 28 private static boolean mRecordingCheckerboard = false;
michael@0 29 private static List<Float> mCheckerboardAmounts;
michael@0 30 private static long mCheckerboardStartTime;
michael@0 31
michael@0 32 private static void initialiseRecordingArrays() {
michael@0 33 if (mFrameTimes == null) {
michael@0 34 mFrameTimes = new ArrayList<Long>(EXPECTED_FRAME_COUNT);
michael@0 35 } else {
michael@0 36 mFrameTimes.clear();
michael@0 37 }
michael@0 38 if (mCheckerboardAmounts == null) {
michael@0 39 mCheckerboardAmounts = new ArrayList<Float>(EXPECTED_FRAME_COUNT);
michael@0 40 } else {
michael@0 41 mCheckerboardAmounts.clear();
michael@0 42 }
michael@0 43 }
michael@0 44
michael@0 45 @RobocopTarget
michael@0 46 public static void startFrameTimeRecording() {
michael@0 47 if (mRecordingFrames || mRecordingCheckerboard) {
michael@0 48 Log.e(LOGTAG, "Error: startFrameTimeRecording() called while already recording!");
michael@0 49 return;
michael@0 50 }
michael@0 51 mRecordingFrames = true;
michael@0 52 initialiseRecordingArrays();
michael@0 53 mFrameStartTime = SystemClock.uptimeMillis();
michael@0 54 }
michael@0 55
michael@0 56 @RobocopTarget
michael@0 57 public static List<Long> stopFrameTimeRecording() {
michael@0 58 if (!mRecordingFrames) {
michael@0 59 Log.e(LOGTAG, "Error: stopFrameTimeRecording() called when not recording!");
michael@0 60 return null;
michael@0 61 }
michael@0 62 mRecordingFrames = false;
michael@0 63 return mFrameTimes;
michael@0 64 }
michael@0 65
michael@0 66 public static void recordFrameTime() {
michael@0 67 // this will be called often, so try to make it as quick as possible
michael@0 68 if (mRecordingFrames) {
michael@0 69 mFrameTimes.add(SystemClock.uptimeMillis() - mFrameStartTime);
michael@0 70 }
michael@0 71 }
michael@0 72
michael@0 73 public static boolean isRecordingCheckerboard() {
michael@0 74 return mRecordingCheckerboard;
michael@0 75 }
michael@0 76
michael@0 77 @RobocopTarget
michael@0 78 public static void startCheckerboardRecording() {
michael@0 79 if (mRecordingCheckerboard || mRecordingFrames) {
michael@0 80 Log.e(LOGTAG, "Error: startCheckerboardRecording() called while already recording!");
michael@0 81 return;
michael@0 82 }
michael@0 83 mRecordingCheckerboard = true;
michael@0 84 initialiseRecordingArrays();
michael@0 85 mCheckerboardStartTime = SystemClock.uptimeMillis();
michael@0 86 }
michael@0 87
michael@0 88 @RobocopTarget
michael@0 89 public static List<Float> stopCheckerboardRecording() {
michael@0 90 if (!mRecordingCheckerboard) {
michael@0 91 Log.e(LOGTAG, "Error: stopCheckerboardRecording() called when not recording!");
michael@0 92 return null;
michael@0 93 }
michael@0 94 mRecordingCheckerboard = false;
michael@0 95
michael@0 96 // We take the number of values in mCheckerboardAmounts here, as there's
michael@0 97 // the possibility that this function is called while recordCheckerboard
michael@0 98 // is still executing. As values are added to this list last, we use
michael@0 99 // this number as the canonical number of recordings.
michael@0 100 int values = mCheckerboardAmounts.size();
michael@0 101
michael@0 102 // The score will be the sum of all the values in mCheckerboardAmounts,
michael@0 103 // so weight the checkerboard values by time so that frame-rate and
michael@0 104 // run-length don't affect score.
michael@0 105 long lastTime = 0;
michael@0 106 float totalTime = mFrameTimes.get(values - 1);
michael@0 107 for (int i = 0; i < values; i++) {
michael@0 108 long elapsedTime = mFrameTimes.get(i) - lastTime;
michael@0 109 mCheckerboardAmounts.set(i, mCheckerboardAmounts.get(i) * elapsedTime / totalTime);
michael@0 110 lastTime += elapsedTime;
michael@0 111 }
michael@0 112
michael@0 113 return mCheckerboardAmounts;
michael@0 114 }
michael@0 115
michael@0 116 public static void recordCheckerboard(float amount) {
michael@0 117 // this will be called often, so try to make it as quick as possible
michael@0 118 if (mRecordingCheckerboard) {
michael@0 119 mFrameTimes.add(SystemClock.uptimeMillis() - mCheckerboardStartTime);
michael@0 120 mCheckerboardAmounts.add(amount);
michael@0 121 }
michael@0 122 }
michael@0 123 }

mercurial