mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d811d87b7a |
No files matched your search
@@ -8,13 +8,17 @@ import android.os.Build
|
||||
import android.os.PowerManager
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.core.SessionPart
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
class ClockLogComponent(private val logFile: File) : SessionPart() {
|
||||
class ClockLogComponent(
|
||||
private val logFile: File,
|
||||
private val paused: () -> Boolean = { SessionState.suspended },
|
||||
) : SessionPart() {
|
||||
@Volatile private var running = false
|
||||
private var stopped = false
|
||||
private var thread: Thread? = null
|
||||
@@ -55,26 +59,28 @@ class ClockLogComponent(private val logFile: File) : SessionPart() {
|
||||
limitLines(steps, ceiling, GpuLimits.first(minSources)).forEach { w.write(it + "\n") }
|
||||
w.flush()
|
||||
while (running && logFile.length() < MAX_BYTES) {
|
||||
val line = StringBuilder(time.format(Date()))
|
||||
for (p in policies) {
|
||||
val cur = firstNumber(File(p, "scaling_cur_freq").path)
|
||||
val max = firstNumber(File(p, "scaling_max_freq").path)
|
||||
val hw = firstNumber(File(p, "cpuinfo_max_freq").path)
|
||||
line.append(" ${p.name.removePrefix("policy").let { "p$it" }} ${mhz(cur)}/${mhz(max)}")
|
||||
if (hw != null && max != null && max < hw) line.append("(of ${mhz(hw)})")
|
||||
}
|
||||
if (ceiling == null) ceiling = ceilingSource(maxSources)?.also { w.write("gpu ceiling from: $it\n") }
|
||||
line.append(gpuField(gpu, ceiling, steps?.mhz?.last()))
|
||||
if (power != null && Build.VERSION.SDK_INT >= 29) {
|
||||
line.append(" | thermal ${power.currentThermalStatus}")
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
val h = power.getThermalHeadroom(10)
|
||||
if (!h.isNaN()) line.append(String.format(Locale.US, " headroom %.2f", h))
|
||||
if (!paused()) {
|
||||
val line = StringBuilder(time.format(Date()))
|
||||
for (p in policies) {
|
||||
val cur = firstNumber(File(p, "scaling_cur_freq").path)
|
||||
val max = firstNumber(File(p, "scaling_max_freq").path)
|
||||
val hw = firstNumber(File(p, "cpuinfo_max_freq").path)
|
||||
line.append(" ${p.name.removePrefix("policy").let { "p$it" }} ${mhz(cur)}/${mhz(max)}")
|
||||
if (hw != null && max != null && max < hw) line.append("(of ${mhz(hw)})")
|
||||
}
|
||||
if (ceiling == null) ceiling = ceilingSource(maxSources)?.also { w.write("gpu ceiling from: $it\n") }
|
||||
line.append(gpuField(gpu, ceiling, steps?.mhz?.last()))
|
||||
if (power != null && Build.VERSION.SDK_INT >= 29) {
|
||||
line.append(" | thermal ${power.currentThermalStatus}")
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
val h = power.getThermalHeadroom(10)
|
||||
if (!h.isNaN()) line.append(String.format(Locale.US, " headroom %.2f", h))
|
||||
}
|
||||
}
|
||||
batteryTenths()?.let { line.append(String.format(Locale.US, " | battery %.1f C", it / 10.0)) }
|
||||
w.write(line.append('\n').toString())
|
||||
w.flush()
|
||||
}
|
||||
batteryTenths()?.let { line.append(String.format(Locale.US, " | battery %.1f C", it / 10.0)) }
|
||||
w.write(line.append('\n').toString())
|
||||
w.flush()
|
||||
try { Thread.sleep(PERIOD_MS) } catch (e: InterruptedException) { break }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,9 @@ object MemoryLog {
|
||||
if (thread != null) return
|
||||
thread = Thread({
|
||||
while (!Thread.currentThread().isInterrupted) {
|
||||
runCatching { MemoryReadout.device()?.let { android.util.Log.i(TAG, line(it, MemoryReadout.split())) } }
|
||||
if (!SessionState.suspended) {
|
||||
runCatching { MemoryReadout.device()?.let { android.util.Log.i(TAG, line(it, MemoryReadout.split())) } }
|
||||
}
|
||||
try { Thread.sleep(PERIOD_MS) } catch (e: InterruptedException) { break }
|
||||
}
|
||||
}, "memory-log").apply { isDaemon = true; start() }
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Intent
|
||||
import android.os.BatteryManager
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
@@ -13,6 +14,7 @@ import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
@@ -36,6 +38,23 @@ class ClockLogComponentTest {
|
||||
assertTrue(log.readText(), log.readText().contains("| battery 42.3 C"))
|
||||
}
|
||||
|
||||
@Test fun aSuspendedSessionTakesNoSamplesUntilItResumes() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
context.sendStickyBroadcast(Intent(Intent.ACTION_BATTERY_CHANGED).putExtra(BatteryManager.EXTRA_TEMPERATURE, 412))
|
||||
val log = tmp.newFile("suspended-clocks.log")
|
||||
val suspended = AtomicBoolean(true)
|
||||
clocks = ClockLogComponent(log) { suspended.get() }.also { it.attach(context); it.start() }
|
||||
val headerDeadline = System.currentTimeMillis() + 5_000
|
||||
while (!log.readText().contains("gpu floor:") && System.currentTimeMillis() < headerDeadline) Thread.sleep(20)
|
||||
assertTrue(log.readText(), log.readText().contains("gpu floor:"))
|
||||
Thread.sleep(500)
|
||||
assertFalse(log.readText(), log.readText().contains("| battery"))
|
||||
suspended.set(false)
|
||||
val resumedDeadline = System.currentTimeMillis() + 5_000
|
||||
while (!log.readText().contains("| battery 41.2 C") && System.currentTimeMillis() < resumedDeadline) Thread.sleep(20)
|
||||
assertTrue(log.readText(), log.readText().contains("| battery 41.2 C"))
|
||||
}
|
||||
|
||||
@Test fun stoppedComponentCannotStartFromAnEarlierSnapshot() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val log = tmp.newFile("stopped-clocks.log")
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.shadows.ShadowLog
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
class MemoryLogTest {
|
||||
@Before fun clear() {
|
||||
MemoryLog.stop()
|
||||
ShadowLog.clear()
|
||||
}
|
||||
|
||||
@After fun reset() {
|
||||
MemoryLog.stop()
|
||||
SessionState.suspended = false
|
||||
}
|
||||
|
||||
@Test fun aRunningSessionLogsMemory() {
|
||||
SessionState.suspended = false
|
||||
MemoryLog.start()
|
||||
val deadline = System.currentTimeMillis() + 5_000
|
||||
while (ShadowLog.getLogsForTag("Memory").isEmpty() && System.currentTimeMillis() < deadline) Thread.sleep(20)
|
||||
assertTrue(ShadowLog.getLogsForTag("Memory").isNotEmpty())
|
||||
}
|
||||
|
||||
@Test fun aSuspendedSessionLogsNoMemory() {
|
||||
SessionState.suspended = true
|
||||
MemoryLog.start()
|
||||
Thread.sleep(1_500)
|
||||
assertTrue(ShadowLog.getLogsForTag("Memory").map { it.msg }.toString(), ShadowLog.getLogsForTag("Memory").isEmpty())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user