Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27920670cf |
No files matched your search
@@ -59,19 +59,8 @@ class GpuMemComponent(private val file: File, private val root: File) : SessionP
|
||||
private fun sessionPids(): List<String> =
|
||||
File("/proc").list()?.filter { it.isNotEmpty() && it.all(Char::isDigit) }.orEmpty()
|
||||
|
||||
private fun kgslMappedKb(pid: String): Long? = runCatching {
|
||||
var bytes = 0L
|
||||
File("/proc/$pid/maps").forEachLine { line ->
|
||||
if (line.endsWith("kgsl-3d0") || line.contains("/dev/dri/renderD")) {
|
||||
val dash = line.indexOf('-')
|
||||
val space = line.indexOf(' ')
|
||||
if (dash > 0 && space > dash) {
|
||||
bytes += line.substring(dash + 1, space).toLong(16) - line.substring(0, dash).toLong(16)
|
||||
}
|
||||
}
|
||||
}
|
||||
bytes / 1024
|
||||
}.getOrNull()
|
||||
private fun kgslMappedKb(pid: String): Long? =
|
||||
runCatching { File("/proc/$pid/maps").useLines(MemoryReadout::gpuMappedKb) }.getOrNull()
|
||||
|
||||
private fun write(bytes: Long) {
|
||||
try {
|
||||
|
||||
@@ -73,9 +73,27 @@ internal object MemoryReadout {
|
||||
}
|
||||
children[pid]?.let(queue::addAll)
|
||||
}
|
||||
return Split(game, droiddeck, gpuKb())
|
||||
return Split(game, droiddeck, gpuKb() ?: mappedGpuKb(seen))
|
||||
}
|
||||
|
||||
fun gpuMappedKb(maps: Sequence<String>): Long {
|
||||
var bytes = 0L
|
||||
maps.forEach { line ->
|
||||
if (line.endsWith("kgsl-3d0") || line.contains("/dev/dri/renderD")) {
|
||||
val dash = line.indexOf('-')
|
||||
val space = line.indexOf(' ')
|
||||
if (dash > 0 && space > dash) {
|
||||
bytes += line.substring(dash + 1, space).toLong(16) - line.substring(0, dash).toLong(16)
|
||||
}
|
||||
}
|
||||
}
|
||||
return bytes / 1024
|
||||
}
|
||||
|
||||
private fun mappedGpuKb(pids: Collection<Int>): Long? =
|
||||
pids.sumOf { pid -> runCatching { File("/proc/$pid/maps").useLines(::gpuMappedKb) }.getOrDefault(0L) }
|
||||
.takeIf { it > 0 }
|
||||
|
||||
private fun parentOf(pid: Int): Int? {
|
||||
val stat = runCatching { File("/proc/$pid/stat").readText() }.getOrNull() ?: return null
|
||||
val close = stat.lastIndexOf(')')
|
||||
|
||||
@@ -54,6 +54,20 @@ class MemoryReadoutTest {
|
||||
assertEquals(0L, MemoryReadout.androidKb(device, MemoryReadout.Split(gameKb = 6_000, droiddeckKb = 2_000, gpuKb = 1_000)))
|
||||
}
|
||||
|
||||
@Test fun gpuMemoryIsWhatTheGpuNodesMapIntoAProcess() {
|
||||
val maps = """
|
||||
7a00000000-7a00200000 rw-s 100000000 00:0c 512 /dev/dri/renderD128
|
||||
7a00200000-7a00600000 rw-s 100200000 00:0c 512 /dev/dri/renderD128
|
||||
7b00000000-7b00100000 rw-s 00000000 00:0d 300 /dev/kgsl-3d0
|
||||
7c00000000-7c40000000 rw-p 00000000 00:00 0 [anon:dalvik-main space]
|
||||
7d00000000-7d00400000 rw-s 00000000 00:0e 77 /dmabuf:
|
||||
7e00000000-7e00100000 r--p 00000000 fd:00 1234 /data/app/lib/arm64/libdroiddeck.so
|
||||
""".trimIndent()
|
||||
assertEquals(2048L + 4096L + 1024L, MemoryReadout.gpuMappedKb(maps.lineSequence()))
|
||||
assertEquals(0L, MemoryReadout.gpuMappedKb(maps.lineSequence().drop(3)))
|
||||
assertEquals(0L, MemoryReadout.gpuMappedKb(emptySequence()))
|
||||
}
|
||||
|
||||
@Test fun theLogLineSaysEveryPartInMegabytes() {
|
||||
val device = MemoryReadout.Device(totalKb = 11_379_920, availableKb = 1_048_576, swapTotalKb = 16_777_212, swapFreeKb = 8_388_606)
|
||||
val split = MemoryReadout.Split(gameKb = 2_097_152, droiddeckKb = 524_288, gpuKb = 3_145_728)
|
||||
|
||||
Reference in new issue
Block a user