mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 22:36:00 +00:00
fix: Samsung boost retries a failed connection with reasons, and "not needed" when the game keeps up
- Samsung clocks: a failed connection is tried 4 times a session (again after 5, 15 and 30 s) and
again at the next game, instead of staying off until the app restarts. Each failed try is in
boost.log with the step it was on and the error ("failed while reading the service's level table
(EOFException)", "the service did not connect within 3 s ..."). The summary lists every failed try.
Only a phone without Samsung's firmware library is not asked again.
- The socket from a failed try is closed.
- Check the boost: when the game kept up without the boost for more than half of the boost's turns,
the verdict is "not needed for this game" instead of a percentage that reads as a loss.
This commit is contained in:
1 parent
0d82557957
commit
17b578b7cf
6 files changed
+165
-43
No files matched your search
@@ -25,7 +25,9 @@ import kotlin.math.roundToInt
|
||||
* stretch of game, and a steady change such as the phone warming up favours neither side. The first
|
||||
* [WARMUP_S] seconds of play (loading, shader compiles) and the first [SETTLE_S] seconds after each
|
||||
* switch are not counted. Seconds the boost should be on but is held back for heat or battery saver
|
||||
* are counted as [Side.heldBack]; too many and there is no verdict.
|
||||
* are counted as [Side.heldBack]; too many and there is no verdict. Seconds it is off because the
|
||||
* game keeps up without it are counted as [Side.idle]; if that is most of its turns, the boost is
|
||||
* not needed for the game.
|
||||
*/
|
||||
object BoostReport {
|
||||
private const val TAG = "BoostReport"
|
||||
@@ -36,6 +38,7 @@ object BoostReport {
|
||||
internal const val CHECK_MIN_S = 120 // counted seconds on each side before there is a verdict
|
||||
internal const val TOO_HOT = "too hot"
|
||||
internal const val BATTERY_SAVER = "battery saver"
|
||||
internal const val KEEPS_UP = "game keeps up"
|
||||
private const val CONFIRM_S = 2 // held this long before the clocks are compared
|
||||
private const val SAMPLES = 5
|
||||
private const val SAMPLE_MS = 200L
|
||||
@@ -58,17 +61,20 @@ object BoostReport {
|
||||
var hottest = 0
|
||||
/** Seconds the boost should have been on but was held back for heat or battery saver. */
|
||||
var heldBack = 0
|
||||
/** Seconds the boost could have been on but was off because the game kept up without it. */
|
||||
var idle = 0
|
||||
val seconds get() = fps.size
|
||||
val average get() = if (fps.isEmpty()) 0.0 else fps.average()
|
||||
/** The frame rate of the slowest 5 % of seconds. */
|
||||
val low get() = if (fps.isEmpty()) 0 else fps.sorted()[fps.size / 20]
|
||||
val draw get() = if (milliamps.isEmpty()) null else milliamps.average()
|
||||
|
||||
fun add(f: Int, ma: Int?, thermal: Int, held: Boolean = false) {
|
||||
fun add(f: Int, ma: Int?, thermal: Int, held: Boolean = false, idle: Boolean = false) {
|
||||
fps.add(f)
|
||||
ma?.let { milliamps.add(it) }
|
||||
hottest = maxOf(hottest, thermal)
|
||||
if (held) heldBack++
|
||||
if (idle) this.idle++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +129,10 @@ object BoostReport {
|
||||
return "too short to tell: play at least ${minutesForVerdict()} minutes with Check the boost on"
|
||||
}
|
||||
if (off.average < 1) return "unclear: the game showed no frames while the boost was paused"
|
||||
if (on.idle * 2 > on.seconds) {
|
||||
return "not needed for this game: it kept up without the boost for ${share(on.idle, on.seconds)} of the boost's turns, " +
|
||||
"so the boost was seldom on (${"%.1f".format(Locale.US, on.average)} fps in its turns, ${"%.1f".format(Locale.US, off.average)} fps paused)"
|
||||
}
|
||||
val gain = on.average / off.average - 1
|
||||
val lowGain = if (off.low > 0) on.low.toDouble() / off.low - 1 else 0.0
|
||||
val onDraw = on.draw
|
||||
@@ -167,6 +177,8 @@ object BoostReport {
|
||||
var lastFrameMs = 0L
|
||||
var charging = false
|
||||
var hottest = 0
|
||||
val samsungTries = SamsungPerf.tries
|
||||
var samsungFailures = 0
|
||||
}
|
||||
|
||||
private val letGoCounts = LinkedHashMap<String, Int>()
|
||||
@@ -234,6 +246,11 @@ object BoostReport {
|
||||
val fps = if (r.lastFrames < 0) 0 else (frames - r.lastFrames).toInt()
|
||||
r.lastFrames = frames
|
||||
watchClocks(r, gpuFile)
|
||||
val failed = r.samsungTries.failed
|
||||
while (r.samsungFailures < failed.size) {
|
||||
val n = ++r.samsungFailures
|
||||
line(r, "Samsung clocks: try $n of ${SamsungPerf.TRIES} to connect failed: ${failed[n - 1]}; ${SamsungPerf.retryNote(n)}")
|
||||
}
|
||||
if (fps < 1) return
|
||||
if (!r.started) {
|
||||
r.started = true
|
||||
@@ -261,7 +278,9 @@ object BoostReport {
|
||||
if (threads.isEmpty() && coresWhy != null) r.coresOff[coresWhy] = (r.coresOff[coresWhy] ?: 0) + 1
|
||||
if (!samsung && samsungWhy != null) r.samsungOff[samsungWhy] = (r.samsungOff[samsungWhy] ?: 0) + 1
|
||||
val off = if (samsung || threads.isNotEmpty()) null else offReasons(coresWhy, samsungWhy)
|
||||
val held = off != null && listOfNotNull(coresWhy, samsungWhy).any { it == TOO_HOT || it == BATTERY_SAVER }
|
||||
val reasons = listOfNotNull(coresWhy, samsungWhy)
|
||||
val held = off != null && reasons.any { it == TOO_HOT || it == BATTERY_SAVER }
|
||||
val idle = off != null && !held && reasons.any { it == KEEPS_UP }
|
||||
|
||||
val window = if (r.check) checkWindow(r.played) else null
|
||||
if (window != null) {
|
||||
@@ -271,7 +290,7 @@ object BoostReport {
|
||||
val span = if (r.played <= WARMUP_S + WINDOW_S) WINDOW_S else 2 * WINDOW_S
|
||||
line(r, "check: boost ${if (pause) "paused" else "on"} for $span s")
|
||||
}
|
||||
if (at >= SETTLE_S) (if (pause) r.checkOff else r.checkOn).add(fps, ma, thermal, held && !pause)
|
||||
if (at >= SETTLE_S) (if (pause) r.checkOff else r.checkOn).add(fps, ma, thermal, held && !pause, idle && !pause)
|
||||
}
|
||||
if (threads.isNotEmpty()) {
|
||||
r.coresBoosted++
|
||||
@@ -367,6 +386,12 @@ object BoostReport {
|
||||
"${r.clocks ?: "never held long enough to look at the clocks"}; let go early ${r.drops} times" +
|
||||
(if (counts.isNotEmpty()) "; DroidDeck let go: $counts" else "") +
|
||||
(if (r.samsungOff.isNotEmpty()) "; off ${offTimes(r.samsungOff)}" else ""))
|
||||
val failed = r.samsungTries.failed
|
||||
if (failed.isNotEmpty()) {
|
||||
line(r, "Samsung clocks: ${failed.size} of ${SamsungPerf.TRIES} tries to connect failed: " +
|
||||
failed.mapIndexed { i, why -> "${i + 1}) $why" }.joinToString("; ") +
|
||||
if (SamsungPerf.connected) "; connected after that" else "")
|
||||
}
|
||||
line(r, "game: ${all.average.roundToInt()} fps average, slowest 5 % of seconds ${all.low}; " +
|
||||
"boosted ${r.boosted.average.roundToInt()} fps for ${clock(r.boosted.seconds)}, not boosted ${r.unboosted.average.roundToInt()} fps for ${clock(r.unboosted.seconds)} " +
|
||||
"(not a fair comparison: the boost runs when the game falls behind)")
|
||||
@@ -399,6 +424,8 @@ object BoostReport {
|
||||
}
|
||||
val samsung = when {
|
||||
SamsungPerf.state.startsWith("not available") -> "Samsung clocks not available on this phone"
|
||||
!SamsungPerf.connected && r.samsungTries.failed.isNotEmpty() ->
|
||||
"Samsung clocks could not connect (${r.samsungTries.failed.last()})"
|
||||
r.samsungHeld == 0 -> "Samsung clocks never on (${mostly(r.samsungOff, r.played)})"
|
||||
r.drops > 0 -> "Samsung clocks working, but Samsung let go early ${r.drops} times"
|
||||
r.cpuRaised.isNullOrEmpty() && !r.gpuRaised -> "Samsung clocks asked for, but the phone shows no raised speed"
|
||||
@@ -415,7 +442,8 @@ object BoostReport {
|
||||
|
||||
private fun side(s: Side) = "${"%.1f".format(Locale.US, s.average)} fps, slowest 5 % ${s.low}" +
|
||||
(s.draw?.let { ", battery ${it.roundToInt()} mA" } ?: "") + ", hottest ${THERMAL.getOrElse(s.hottest) { "${s.hottest}" }}" +
|
||||
(if (s.heldBack > 0) ", held back for heat or battery saver ${share(s.heldBack, s.seconds)}" else "")
|
||||
(if (s.heldBack > 0) ", held back for heat or battery saver ${share(s.heldBack, s.seconds)}" else "") +
|
||||
(if (s.idle > 0) ", off because the game kept up ${share(s.idle, s.seconds)}" else "")
|
||||
|
||||
private fun share(part: Int, whole: Int) = if (whole == 0) "0 %" else "${part * 100 / whole} %"
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ object GameThreadHints {
|
||||
pm.isPowerSaveMode -> BoostReport.BATTERY_SAVER
|
||||
// Not SEVERE: the Odin 3 reports it once its skin reaches 50 C, a couple of minutes into any game.
|
||||
pm.currentThermalStatus >= PowerManager.THERMAL_STATUS_CRITICAL -> BoostReport.TOO_HOT
|
||||
pacedFor >= PACE_LEAVE_S -> "game keeps up"
|
||||
pacedFor >= PACE_LEAVE_S -> BoostReport.KEEPS_UP
|
||||
else -> null
|
||||
}
|
||||
val next = when {
|
||||
@@ -152,7 +152,7 @@ object GameThreadHints {
|
||||
internal fun offReason(spare: String?, boosted: Set<Int>, paced: Boolean, next: Set<Int>): String? = when {
|
||||
spare != null -> spare
|
||||
boosted.isNotEmpty() -> null
|
||||
paced -> "game keeps up"
|
||||
paced -> BoostReport.KEEPS_UP
|
||||
next.isEmpty() -> "no thread busy enough"
|
||||
else -> "Android refused the hint"
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import com.samsung.sdk.sperf.Boost
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
import java.io.InputStream
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
@@ -28,6 +30,10 @@ import kotlin.random.Random
|
||||
* cores online), asked for with a timeout of at most [HOLD_MS], so Samsung lets go on its own if the
|
||||
* app dies. Samsung may hold a request for less than asked (1 s on an SM8850 Galaxy Z Fold), so they
|
||||
* are renewed every [renewMs].
|
||||
*
|
||||
* A phone without the firmware library is not asked again until the app restarts. Where the library
|
||||
* is there, a failed connection is tried again [TRIES] times a session, each failure with its reason
|
||||
* in [Tries.failed], and again at the next session.
|
||||
*/
|
||||
object SamsungPerf {
|
||||
private const val TAG = "SamsungPerf"
|
||||
@@ -48,6 +54,8 @@ object SamsungPerf {
|
||||
private const val CORES = 4
|
||||
internal const val HOLD_MS = 5000
|
||||
private const val SEEN_HOLD_MS = 1000
|
||||
internal const val TRIES = 4
|
||||
private val RETRY_S = intArrayOf(5, 15, 30)
|
||||
|
||||
/** Half the hold, and no later than half the shortest hold Samsung has been seen to use. */
|
||||
internal fun renewMs(holdMs: Int): Long = (minOf(holdMs, SEEN_HOLD_MS) / 2).coerceAtLeast(100).toLong()
|
||||
@@ -80,66 +88,101 @@ object SamsungPerf {
|
||||
).filter { it.value > 0 }
|
||||
}
|
||||
|
||||
/** One session's tries to connect: why each failed, and whether all [TRIES] did. */
|
||||
internal class Tries {
|
||||
val failed = CopyOnWriteArrayList<String>()
|
||||
@Volatile var gaveUp = false
|
||||
}
|
||||
|
||||
/** What the log says after try [n] failed. */
|
||||
internal fun retryNote(n: Int): String =
|
||||
if (n < TRIES) "trying again in ${RETRY_S[n - 1]} s" else "no more tries until the next game"
|
||||
|
||||
/** A failed try's reason: the step it was on and what went wrong there. */
|
||||
internal fun failure(step: String, t: Throwable): String {
|
||||
val cause = (t as? InvocationTargetException)?.targetException ?: t
|
||||
return "failed while $step (${cause.javaClass.simpleName}${cause.message?.takeIf { it.isNotBlank() }?.let { ": $it" } ?: ""})"
|
||||
}
|
||||
|
||||
private val connectLock = Any()
|
||||
@Volatile private var floors: List<Floor>? = null
|
||||
@Volatile private var unavailable: String? = null
|
||||
private var socket: LocalSocket? = null // kept open for the process's life, as the SDK does
|
||||
@Volatile internal var tries = Tries()
|
||||
|
||||
/** Once per process. Null where there is no Samsung service, with the reason in [unavailable]. */
|
||||
private fun connect(): List<Floor>? = synchronized(connectLock) { connectLocked() }
|
||||
private class Failed(val why: String) : Exception(why)
|
||||
|
||||
private fun connectLocked(): List<Floor>? {
|
||||
/** Null where there is no Samsung service (the reason in [unavailable]) or this try failed (the reason in [t]). */
|
||||
private fun connect(t: Tries): List<Floor>? = synchronized(connectLock) { connectLocked(t) }
|
||||
|
||||
private fun connectLocked(t: Tries): List<Floor>? {
|
||||
floors?.let { return it }
|
||||
if (unavailable != null) return null
|
||||
try {
|
||||
System.loadLibrary(LIBRARY)
|
||||
} catch (_: UnsatisfiedLinkError) {
|
||||
unavailable = "no Samsung performance library"
|
||||
offWhy = unavailable
|
||||
Log.i(TAG, "not available: $unavailable")
|
||||
return null
|
||||
}
|
||||
var step = "looking up Samsung's performance service"
|
||||
var client: LocalSocket? = null
|
||||
try {
|
||||
val service = Class.forName("android.os.ServiceManager").getMethod("getService", String::class.java)
|
||||
.invoke(null, SERVICE) as IBinder? ?: return fail("no $SERVICE service")
|
||||
.invoke(null, SERVICE) as IBinder? ?: throw Failed("Samsung's performance service ($SERVICE) is not running")
|
||||
val name = "PERFSDK_SOC_" + Random.nextInt(36 * 36 * 36 * 36 * 36).toString(36).padStart(5, '0')
|
||||
step = "opening a socket for the service"
|
||||
val server = LocalServerSocket(name) // the service connects to it; Closeable only from Android 10
|
||||
val client = try {
|
||||
val accepted = try {
|
||||
step = "asking the service to connect"
|
||||
val init = call(service, CALL_INIT, { writeString(name) }, { readInt() })
|
||||
step = "asking the service for the package name"
|
||||
val pkg = call(service, CALL_PACKAGE, {}, { readString() })
|
||||
if (!pkg.isNullOrEmpty()) Boost.setPkgName(pkg)
|
||||
Log.i(TAG, "service: init $init, package $pkg")
|
||||
step = "waiting for the service to connect"
|
||||
val poll = StructPollfd().apply { fd = server.fileDescriptor; events = OsConstants.POLLIN.toShort() }
|
||||
if (Os.poll(arrayOf(poll), SOCKET_TIMEOUT_MS) < 1) return fail("$SERVICE did not connect")
|
||||
if (Os.poll(arrayOf(poll), SOCKET_TIMEOUT_MS) < 1) {
|
||||
throw Failed("the service did not connect within ${SOCKET_TIMEOUT_MS / 1000} s (it answered $init, package ${pkg ?: "none"})")
|
||||
}
|
||||
server.accept()
|
||||
} finally {
|
||||
server.close()
|
||||
}
|
||||
client.soTimeout = SOCKET_TIMEOUT_MS
|
||||
DataOutputStream(client.outputStream).apply { writeInt(Integer.reverseBytes(ASK_LEVELS)); flush() }
|
||||
val levels = readLevels(client.inputStream)
|
||||
socket = client
|
||||
client = accepted
|
||||
step = "reading the service's level table"
|
||||
accepted.soTimeout = SOCKET_TIMEOUT_MS
|
||||
DataOutputStream(accepted.outputStream).apply { writeInt(Integer.reverseBytes(ASK_LEVELS)); flush() }
|
||||
val levels = readLevels(accepted.inputStream)
|
||||
Log.i(TAG, "levels: cpu ${levels.cpu.joinToString()} / gpu ${levels.gpu.joinToString()} / " +
|
||||
"bus ${levels.bus.joinToString()}, max ${levels.maxTimeoutMs} ms")
|
||||
val found = floors(levels)
|
||||
if (found.isEmpty()) return fail("no usable levels")
|
||||
if (found.isEmpty()) {
|
||||
throw Failed("the level table has no usable floors (cpu ${levels.cpu.joinToString()} / gpu ${levels.gpu.joinToString()} / bus ${levels.bus.joinToString()})")
|
||||
}
|
||||
socket = accepted
|
||||
client = null
|
||||
floors = found
|
||||
return found
|
||||
} catch (_: UnsatisfiedLinkError) {
|
||||
return fail("no Samsung performance library")
|
||||
} catch (t: Throwable) {
|
||||
Log.w(TAG, "could not connect", t)
|
||||
return fail("could not connect (${t.javaClass.simpleName})")
|
||||
} catch (e: Throwable) {
|
||||
val why = (e as? Failed)?.why ?: failure(step, e)
|
||||
t.failed.add(why)
|
||||
offWhy = "could not connect"
|
||||
Log.w(TAG, "try ${t.failed.size} of $TRIES failed: $why", e.takeIf { it !is Failed })
|
||||
return null
|
||||
} finally {
|
||||
client?.let { runCatching { it.close() } }
|
||||
}
|
||||
}
|
||||
|
||||
private fun fail(why: String): List<Floor>? {
|
||||
unavailable = why
|
||||
offWhy = why
|
||||
Log.i(TAG, "not available: $why")
|
||||
return null
|
||||
}
|
||||
|
||||
private fun <T> call(service: IBinder, code: Int, write: Parcel.() -> Unit, read: Parcel.() -> T): T {
|
||||
val data = Parcel.obtain()
|
||||
val reply = Parcel.obtain()
|
||||
try {
|
||||
data.writeInterfaceToken(DESCRIPTOR)
|
||||
data.write()
|
||||
service.transact(code, data, reply, 0)
|
||||
if (!service.transact(code, data, reply, 0)) throw Failed("the service does not take call $code")
|
||||
reply.readException()
|
||||
return reply.read()
|
||||
} finally {
|
||||
@@ -165,7 +208,13 @@ object SamsungPerf {
|
||||
"connected, floors " + f.joinToString { "${TYPE_NAMES[it.type]} ${it.value}" } +
|
||||
", asked for $hold ms at a time, renewed every ${renewMs(hold)} ms"
|
||||
}
|
||||
?: "connecting"
|
||||
?: tries.let { t ->
|
||||
when {
|
||||
t.gaveUp -> "could not connect in $TRIES tries (last: ${t.failed.lastOrNull()})"
|
||||
t.failed.isNotEmpty() -> "connecting, try ${t.failed.size + 1} of $TRIES"
|
||||
else -> "connecting"
|
||||
}
|
||||
}
|
||||
|
||||
internal fun floorValue(type: Int): Int? = floors?.firstOrNull { it.type == type }?.value
|
||||
|
||||
@@ -179,7 +228,9 @@ object SamsungPerf {
|
||||
val app = context.applicationContext
|
||||
worker?.interrupt()
|
||||
offWhy = "starting"
|
||||
worker = Thread({ run(app) }, "samsung-boost").apply { isDaemon = true; start() }
|
||||
val t = Tries()
|
||||
tries = t
|
||||
worker = Thread({ run(app, t) }, "samsung-boost").apply { isDaemon = true; start() }
|
||||
return "samsung boost: watching"
|
||||
}
|
||||
|
||||
@@ -190,14 +241,26 @@ object SamsungPerf {
|
||||
worker = null
|
||||
}
|
||||
|
||||
private fun run(context: Context) {
|
||||
val floors = connect() ?: return
|
||||
val renew = renewMs(floors.minOf { it.timeoutMs })
|
||||
val pm = context.getSystemService(PowerManager::class.java)
|
||||
val frames = ArrayDeque<Long>()
|
||||
var pacedFor = 0
|
||||
private fun run(context: Context, t: Tries) {
|
||||
var boosting = false
|
||||
try {
|
||||
var found = connect(t)
|
||||
while (found == null && unavailable == null && t.failed.size < TRIES) {
|
||||
Thread.sleep(RETRY_S[t.failed.size - 1] * 1000L)
|
||||
found = connect(t)
|
||||
}
|
||||
if (found == null) {
|
||||
if (unavailable == null) {
|
||||
t.gaveUp = true
|
||||
offWhy = "could not connect in $TRIES tries"
|
||||
}
|
||||
return
|
||||
}
|
||||
val floors: List<Floor> = found
|
||||
val renew = renewMs(floors.minOf { it.timeoutMs })
|
||||
val pm = context.getSystemService(PowerManager::class.java)
|
||||
val frames = ArrayDeque<Long>()
|
||||
var pacedFor = 0
|
||||
while (!Thread.currentThread().isInterrupted) {
|
||||
frames.addLast(WaylandCompositor.gameFrameCount())
|
||||
if (frames.size > GameThreadHints.PACE_WINDOW_S + 1) frames.removeFirst()
|
||||
@@ -210,7 +273,7 @@ object SamsungPerf {
|
||||
fps < 1 -> "no frames"
|
||||
pm.isPowerSaveMode -> BoostReport.BATTERY_SAVER
|
||||
hot -> BoostReport.TOO_HOT
|
||||
pacedFor >= GameThreadHints.PACE_LEAVE_S -> "game keeps up"
|
||||
pacedFor >= GameThreadHints.PACE_LEAVE_S -> BoostReport.KEEPS_UP
|
||||
else -> null
|
||||
}
|
||||
offWhy = why
|
||||
@@ -238,8 +301,8 @@ object SamsungPerf {
|
||||
Thread.sleep(1000 - slept)
|
||||
}
|
||||
} catch (_: InterruptedException) {
|
||||
} catch (t: Throwable) {
|
||||
Log.w(TAG, "stopped", t)
|
||||
} catch (e: Throwable) {
|
||||
Log.w(TAG, "stopped", e)
|
||||
} finally {
|
||||
if (boosting) runCatching { Boost.releaseBoost() }
|
||||
holding = false
|
||||
|
||||
@@ -601,7 +601,7 @@
|
||||
<string name="perf_boost">Performance boost</string>
|
||||
<string name="perf_boost_hint">Asks the phone to run the game\'s busiest threads on its fastest cores while the game falls behind. Lets go when the game keeps up, the phone is hot or battery saver is on. Android 12 or newer. Samsung phones also raise their CPU, GPU and memory clocks. More battery use and heat. What it did is in boost.log in the session\'s logs.</string>
|
||||
<string name="perf_boost_check">Check the boost</string>
|
||||
<string name="perf_boost_check_hint">For testing: during a game the boost takes turns on and paused (one minute on, then two paused, two on, and so on), and boost.log ends with a fair comparison and a verdict. The first minute is not counted. Play at least 7 minutes, then turn this off. A phone that gets too hot gives no verdict.</string>
|
||||
<string name="perf_boost_check_hint">For testing: during a game the boost takes turns on and paused (one minute on, then two paused, two on, and so on), and boost.log ends with a fair comparison and a verdict. The first minute is not counted. Play at least 7 minutes, then turn this off. A phone that gets too hot gives no verdict. A game that runs well without the boost is marked as not needing it.</string>
|
||||
<string name="perf_gpu">GPU</string>
|
||||
<string name="perf_memory">Memory</string>
|
||||
<string name="perf_cap_off">Off</string>
|
||||
|
||||
@@ -86,6 +86,17 @@ class BoostReportTest {
|
||||
.startsWith("worth keeping"))
|
||||
}
|
||||
|
||||
@Test fun `a game that keeps up without the boost does not need it`() {
|
||||
val on = BoostReport.Side().apply { repeat(200) { add(58, null, 0, idle = it >= 12) } }
|
||||
val v = BoostReport.verdict(on, side(59))
|
||||
assertTrue(v, v.startsWith("not needed for this game: it kept up without the boost for 94 % of the boost's turns"))
|
||||
assertTrue(v, v.endsWith("(58.0 fps in its turns, 59.0 fps paused)"))
|
||||
val busy = BoostReport.Side().apply { repeat(200) { add(41, null, 0, idle = it < 96) } }
|
||||
assertTrue(BoostReport.verdict(busy, side(40)).startsWith("unclear, a small gain"))
|
||||
val short = BoostReport.Side().apply { repeat(100) { add(58, null, 0, idle = true) } }
|
||||
assertTrue(BoostReport.verdict(short, side(59)).startsWith("too short to tell"))
|
||||
}
|
||||
|
||||
@Test fun `the status names why the boost is off, once for a reason both parts give`() {
|
||||
assertEquals("too hot", BoostReport.offReasons("too hot", "too hot"))
|
||||
assertEquals("game keeps up, too hot", BoostReport.offReasons("game keeps up", "too hot"))
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.EOFException
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
|
||||
@@ -61,6 +62,25 @@ class SamsungPerfTest {
|
||||
assertEquals(100L, SamsungPerf.renewMs(50))
|
||||
}
|
||||
|
||||
@Test fun `a failed connection is tried again a few times, then at the next game`() {
|
||||
assertEquals(4, SamsungPerf.TRIES)
|
||||
assertEquals("trying again in 5 s", SamsungPerf.retryNote(1))
|
||||
assertEquals("trying again in 15 s", SamsungPerf.retryNote(2))
|
||||
assertEquals("trying again in 30 s", SamsungPerf.retryNote(3))
|
||||
assertEquals("no more tries until the next game", SamsungPerf.retryNote(4))
|
||||
}
|
||||
|
||||
@Test fun `a failed try names the step it was on and the error`() {
|
||||
assertEquals(
|
||||
"failed while reading the service's level table (EOFException)",
|
||||
SamsungPerf.failure("reading the service's level table", EOFException()),
|
||||
)
|
||||
assertEquals(
|
||||
"failed while looking up Samsung's performance service (SecurityException: not allowed)",
|
||||
SamsungPerf.failure("looking up Samsung's performance service", InvocationTargetException(SecurityException("not allowed"))),
|
||||
)
|
||||
}
|
||||
|
||||
@Test(expected = EOFException::class) fun `a short answer is refused`() {
|
||||
SamsungPerf.readLevels(ByteArrayInputStream(table(-1).copyOf(100)))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user