2011-12-01 19:11:10 +00:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-01 19:11:10 +00:00
|
|
|
|
|
|
|
package org.mozilla.gecko.gfx;
|
|
|
|
|
2015-08-10 23:19:51 +00:00
|
|
|
import org.mozilla.gecko.annotation.RobocopTarget;
|
2013-12-06 19:43:10 +00:00
|
|
|
|
2011-12-01 19:11:10 +00:00
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.util.Log;
|
|
|
|
|
2012-07-28 00:53:54 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2011-12-01 19:11:10 +00:00
|
|
|
public class PanningPerfAPI {
|
|
|
|
private static final String LOGTAG = "GeckoPanningPerfAPI";
|
|
|
|
|
|
|
|
// make this large enough to avoid having to resize the frame time
|
|
|
|
// list, as that may be expensive and impact the thing we're trying
|
|
|
|
// to measure.
|
|
|
|
private static final int EXPECTED_FRAME_COUNT = 2048;
|
|
|
|
|
2014-07-26 03:14:47 +00:00
|
|
|
private static boolean mRecordingFrames;
|
2011-12-01 19:11:10 +00:00
|
|
|
private static List<Long> mFrameTimes;
|
2012-02-02 09:02:32 +00:00
|
|
|
private static long mFrameStartTime;
|
|
|
|
|
2014-07-26 03:14:47 +00:00
|
|
|
private static boolean mRecordingCheckerboard;
|
2012-02-02 09:02:32 +00:00
|
|
|
private static List<Float> mCheckerboardAmounts;
|
|
|
|
private static long mCheckerboardStartTime;
|
2011-12-01 19:11:10 +00:00
|
|
|
|
2012-11-29 12:03:52 +00:00
|
|
|
private static void initialiseRecordingArrays() {
|
2011-12-01 19:11:10 +00:00
|
|
|
if (mFrameTimes == null) {
|
|
|
|
mFrameTimes = new ArrayList<Long>(EXPECTED_FRAME_COUNT);
|
|
|
|
} else {
|
|
|
|
mFrameTimes.clear();
|
|
|
|
}
|
2012-11-29 12:03:52 +00:00
|
|
|
if (mCheckerboardAmounts == null) {
|
|
|
|
mCheckerboardAmounts = new ArrayList<Float>(EXPECTED_FRAME_COUNT);
|
|
|
|
} else {
|
|
|
|
mCheckerboardAmounts.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-06 19:43:10 +00:00
|
|
|
@RobocopTarget
|
2012-11-29 12:03:52 +00:00
|
|
|
public static void startFrameTimeRecording() {
|
|
|
|
if (mRecordingFrames || mRecordingCheckerboard) {
|
|
|
|
Log.e(LOGTAG, "Error: startFrameTimeRecording() called while already recording!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mRecordingFrames = true;
|
|
|
|
initialiseRecordingArrays();
|
2012-02-02 09:02:32 +00:00
|
|
|
mFrameStartTime = SystemClock.uptimeMillis();
|
2011-12-01 19:11:10 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 19:43:10 +00:00
|
|
|
@RobocopTarget
|
2011-12-01 19:11:10 +00:00
|
|
|
public static List<Long> stopFrameTimeRecording() {
|
2012-02-02 09:02:32 +00:00
|
|
|
if (!mRecordingFrames) {
|
2011-12-01 19:11:10 +00:00
|
|
|
Log.e(LOGTAG, "Error: stopFrameTimeRecording() called when not recording!");
|
|
|
|
return null;
|
|
|
|
}
|
2012-02-02 09:02:32 +00:00
|
|
|
mRecordingFrames = false;
|
2011-12-01 19:11:10 +00:00
|
|
|
return mFrameTimes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void recordFrameTime() {
|
|
|
|
// this will be called often, so try to make it as quick as possible
|
2012-02-02 09:02:32 +00:00
|
|
|
if (mRecordingFrames) {
|
|
|
|
mFrameTimes.add(SystemClock.uptimeMillis() - mFrameStartTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isRecordingCheckerboard() {
|
|
|
|
return mRecordingCheckerboard;
|
|
|
|
}
|
|
|
|
|
2013-12-06 19:43:10 +00:00
|
|
|
@RobocopTarget
|
2012-02-02 09:02:32 +00:00
|
|
|
public static void startCheckerboardRecording() {
|
2012-11-29 12:03:52 +00:00
|
|
|
if (mRecordingCheckerboard || mRecordingFrames) {
|
2012-02-02 09:02:32 +00:00
|
|
|
Log.e(LOGTAG, "Error: startCheckerboardRecording() called while already recording!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mRecordingCheckerboard = true;
|
2012-11-29 12:03:52 +00:00
|
|
|
initialiseRecordingArrays();
|
2012-02-02 09:02:32 +00:00
|
|
|
mCheckerboardStartTime = SystemClock.uptimeMillis();
|
|
|
|
}
|
|
|
|
|
2013-12-06 19:43:10 +00:00
|
|
|
@RobocopTarget
|
2012-02-02 09:02:32 +00:00
|
|
|
public static List<Float> stopCheckerboardRecording() {
|
|
|
|
if (!mRecordingCheckerboard) {
|
|
|
|
Log.e(LOGTAG, "Error: stopCheckerboardRecording() called when not recording!");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
mRecordingCheckerboard = false;
|
2012-11-29 12:03:52 +00:00
|
|
|
|
2012-12-07 15:11:05 +00:00
|
|
|
// We take the number of values in mCheckerboardAmounts here, as there's
|
|
|
|
// the possibility that this function is called while recordCheckerboard
|
|
|
|
// is still executing. As values are added to this list last, we use
|
|
|
|
// this number as the canonical number of recordings.
|
|
|
|
int values = mCheckerboardAmounts.size();
|
2015-04-10 20:41:37 +00:00
|
|
|
if (values == 0) {
|
|
|
|
Log.w(LOGTAG, "stopCheckerboardRecording() found no checkerboard amounts!");
|
|
|
|
return mCheckerboardAmounts;
|
|
|
|
}
|
2012-12-07 15:11:05 +00:00
|
|
|
|
2012-11-29 12:03:52 +00:00
|
|
|
// The score will be the sum of all the values in mCheckerboardAmounts,
|
|
|
|
// so weight the checkerboard values by time so that frame-rate and
|
|
|
|
// run-length don't affect score.
|
|
|
|
long lastTime = 0;
|
2012-12-07 15:11:05 +00:00
|
|
|
float totalTime = mFrameTimes.get(values - 1);
|
|
|
|
for (int i = 0; i < values; i++) {
|
2012-11-30 23:11:37 +00:00
|
|
|
long elapsedTime = mFrameTimes.get(i) - lastTime;
|
|
|
|
mCheckerboardAmounts.set(i, mCheckerboardAmounts.get(i) * elapsedTime / totalTime);
|
2012-12-07 15:11:05 +00:00
|
|
|
lastTime += elapsedTime;
|
2012-11-29 12:03:52 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 09:02:32 +00:00
|
|
|
return mCheckerboardAmounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void recordCheckerboard(float amount) {
|
|
|
|
// this will be called often, so try to make it as quick as possible
|
|
|
|
if (mRecordingCheckerboard) {
|
2012-11-29 12:03:52 +00:00
|
|
|
mFrameTimes.add(SystemClock.uptimeMillis() - mCheckerboardStartTime);
|
2012-02-02 09:02:32 +00:00
|
|
|
mCheckerboardAmounts.add(amount);
|
2011-12-01 19:11:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|