Compare commits

...
1 Commits
Author SHA1 Message Date
Bitsy 30cbbc4be1 fix(demo): mingwX64 compile — currentResidentMb via expect/actual
platform.posix.popen/pclose don't exist on mingw (Windows uses _popen/_pclose),
so the soak-test RSS helper failed :demo:compileKotlinMingwX64 (broke the v0.2.0
publish). Make currentResidentMb() an expect: posix (appleMain/linuxMain) reads
`ps -o rss=`, mingw returns -1 (the soak gate runs on macOS/Linux). Verified
:demo:compileKotlinMacosArm64 green.
2026-07-18 10:21:50 +02:00
4 changed files with 44 additions and 15 deletions
@@ -0,0 +1,18 @@
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.allocArray
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.toKString
// Current resident set (MB) via `ps -o rss=` (KB). See currentResidentMb in MainNative.kt.
@OptIn(ExperimentalForeignApi::class)
internal actual fun currentResidentMb(): Long {
val vPid = platform.posix.getpid()
val vFp = platform.posix.popen("ps -o rss= -p $vPid", "r") ?: return -1
val vKb = memScoped {
val vBuf = allocArray<kotlinx.cinterop.ByteVar>(64)
val vLine = platform.posix.fgets(vBuf, 64, vFp)?.toKString()?.trim()
vLine?.toLongOrNull() ?: -1L
}
platform.posix.pclose(vFp)
return if (vKb < 0) -1 else vKb / 1024
}
@@ -0,0 +1,18 @@
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.allocArray
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.toKString
// Current resident set (MB) via `ps -o rss=` (KB). See currentResidentMb in MainNative.kt.
@OptIn(ExperimentalForeignApi::class)
internal actual fun currentResidentMb(): Long {
val vPid = platform.posix.getpid()
val vFp = platform.posix.popen("ps -o rss= -p $vPid", "r") ?: return -1
val vKb = memScoped {
val vBuf = allocArray<kotlinx.cinterop.ByteVar>(64)
val vLine = platform.posix.fgets(vBuf, 64, vFp)?.toKString()?.trim()
vLine?.toLongOrNull() ?: -1L
}
platform.posix.pclose(vFp)
return if (vKb < 0) -1 else vKb / 1024
}
@@ -0,0 +1,3 @@
// Windows has no `ps`/popen; the memory soak (--soaktest) is a macOS/Linux gate
// (see scripts/verify-mac.sh), so current RSS is not sampled here.
internal actual fun currentResidentMb(): Long = -1L
+5 -15
View File
@@ -563,21 +563,11 @@ private fun runSoakTest() {
}
}
/* CURRENT resident set (MB) via `ps` — unlike getrusage ru_maxrss (monotonic peak),
this can DROP after GC, so it distinguishes a true leak (ratchets up) from K/N
allocator high-water. Portable across macOS/Linux (`ps -o rss=` prints KB). */
@OptIn(ExperimentalForeignApi::class)
private fun currentResidentMb(): Long {
val vPid = platform.posix.getpid()
val vFp = platform.posix.popen("ps -o rss= -p $vPid", "r") ?: return -1
val vKb = memScoped {
val vBuf = allocArray<kotlinx.cinterop.ByteVar>(64)
val vLine = platform.posix.fgets(vBuf, 64, vFp)?.toKString()?.trim()
vLine?.toLongOrNull() ?: -1L
}
platform.posix.pclose(vFp)
return if (vKb < 0) -1 else vKb / 1024
}
/* CURRENT resident set (MB): current RSS can DROP after GC, so it distinguishes a
true leak (ratchets up) from K/N allocator high-water, unlike getrusage's
monotonic peak. posix reads it from `ps`; mingw has no `ps`/popen and returns
-1 (the soak gate runs on macOS/Linux — see scripts/verify-mac.sh). */
internal expect fun currentResidentMb(): Long
private fun runNav3Test() {
val vShow = mutableStateOf(false)