Optimize portable tile rendering and add optional memory saver
This commit is contained in:
parent
5bb15fa69e
commit
25ea43bea7
18 changed files with 918 additions and 63 deletions
124
tests/device/NavigationInstrumentation.java
Normal file
124
tests/device/NavigationInstrumentation.java
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
package tv.luma.launcher.tests;
|
||||
|
||||
import android.app.*;
|
||||
import android.content.*;
|
||||
import android.os.*;
|
||||
import android.view.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
|
||||
/** Real D-pad injection without spawning the Android input command/VM for every key. */
|
||||
public final class NavigationInstrumentation extends Instrumentation {
|
||||
private boolean testMemorySaver;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle b) {
|
||||
super.onCreate(b);
|
||||
testMemorySaver = b != null && "true".equals(b.getString("memorySaver"));
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
Bundle result = new Bundle();
|
||||
StringBuilder report = new StringBuilder();
|
||||
SharedPreferences prefs = getTargetContext().getSharedPreferences("luma", 0);
|
||||
boolean hadSetting = prefs.contains("memorySaver"),
|
||||
original = prefs.getBoolean("memorySaver", false);
|
||||
int status = Activity.RESULT_OK;
|
||||
HandlerThread listener = new HandlerThread("navigation-metrics");
|
||||
listener.start();
|
||||
try {
|
||||
if (testMemorySaver && !prefs.edit().putBoolean("memorySaver", true).commit())
|
||||
throw new AssertionError("could not save memory preference");
|
||||
Activity a =
|
||||
startActivitySync(
|
||||
new Intent(Intent.ACTION_MAIN)
|
||||
.setComponent(
|
||||
new ComponentName("tv.luma.launcher", "tv.luma.launcher.MainActivity"))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
Thread.sleep(3000);
|
||||
if (!((PowerManager) a.getSystemService(Context.POWER_SERVICE)).isInteractive())
|
||||
throw new AssertionError("screen asleep");
|
||||
for (int i = 0; i < 3; i++) sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
|
||||
Thread.sleep(500);
|
||||
List<long[]> frames = Collections.synchronizedList(new ArrayList<>());
|
||||
a.getWindow()
|
||||
.addOnFrameMetricsAvailableListener(
|
||||
(w, f, d) ->
|
||||
frames.add(
|
||||
new long[] {
|
||||
f.getMetric(FrameMetrics.TOTAL_DURATION),
|
||||
f.getMetric(FrameMetrics.DEADLINE),
|
||||
f.getMetric(FrameMetrics.GPU_DURATION),
|
||||
d
|
||||
}),
|
||||
new Handler(listener.getLooper()));
|
||||
int[] keys = {22, 22, 22, 22, 22, 21, 21, 21, 21, 21, 20, 20, 19, 19};
|
||||
for (int delay : new int[] {350, 80}) {
|
||||
frames.clear();
|
||||
long start = SystemClock.uptimeMillis();
|
||||
for (int round = 0; round < 3; round++)
|
||||
for (int key : keys) {
|
||||
sendKeyDownUpSync(key);
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
Thread.sleep(450);
|
||||
List<long[]> sample;
|
||||
synchronized (frames) {
|
||||
sample = new ArrayList<>(frames);
|
||||
}
|
||||
List<Long> total = new ArrayList<>(), gpu = new ArrayList<>();
|
||||
int missed = 0, dropped = 0;
|
||||
for (long[] f : sample) {
|
||||
total.add(f[0]);
|
||||
gpu.add(f[2]);
|
||||
if (f[1] > 0 && f[0] > f[1]) missed++;
|
||||
dropped += f[3];
|
||||
}
|
||||
Collections.sort(total);
|
||||
Collections.sort(gpu);
|
||||
if (total.size() < 40)
|
||||
throw new AssertionError("insufficient rendered frames " + total.size());
|
||||
report
|
||||
.append("delayMs=")
|
||||
.append(delay)
|
||||
.append(" frames=")
|
||||
.append(total.size())
|
||||
.append(" medianMs=")
|
||||
.append(total.get(total.size() / 2) / 1e6)
|
||||
.append(" p90Ms=")
|
||||
.append(total.get((int) (total.size() * .9)) / 1e6)
|
||||
.append(" p95Ms=")
|
||||
.append(total.get((int) (total.size() * .95)) / 1e6)
|
||||
.append(" deadlineMissed=")
|
||||
.append(missed)
|
||||
.append(" droppedCallbacks=")
|
||||
.append(dropped)
|
||||
.append(" gpuP90Ms=")
|
||||
.append(gpu.get((int) (gpu.size() * .9)) / 1e6)
|
||||
.append(" elapsedMs=")
|
||||
.append(SystemClock.uptimeMillis() - start)
|
||||
.append('\n');
|
||||
Thread.sleep(600);
|
||||
}
|
||||
report.append("PASS: normal and rapid real D-pad navigation\n");
|
||||
} catch (Throwable t) {
|
||||
report.append("FAIL: ").append(t).append('\n');
|
||||
status = Activity.RESULT_CANCELED;
|
||||
} finally {
|
||||
listener.quitSafely();
|
||||
if (testMemorySaver) {
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
if (hadSetting) edit.putBoolean("memorySaver", original);
|
||||
else edit.remove("memorySaver");
|
||||
if (!edit.commit()) {
|
||||
report.append("FAIL: could not restore memory preference\n");
|
||||
status = Activity.RESULT_CANCELED;
|
||||
}
|
||||
}
|
||||
}
|
||||
result.putString("stream", report.toString());
|
||||
finish(status, result);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue