mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Add opt-in Steam storage diagnostics (#158)
This commit is contained in:
1 parent
32ea22e033
commit
b2bde1c14d
7 files changed
+440
-2
No files matched your search
@@ -316,6 +316,7 @@ class MainActivity : ComponentActivity() {
|
||||
private var backActionsInverted by mutableStateOf(false)
|
||||
private var renderer by mutableStateOf("vulkan")
|
||||
private var gameStorage by mutableStateOf("")
|
||||
private var storageDiagnostics by mutableStateOf(false)
|
||||
private var storageOptions by mutableStateOf<List<Pair<String, String>>>(emptyList())
|
||||
private val pickGameStorage = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { r ->
|
||||
if (r.resultCode == RESULT_OK) InAppFilePicker.pickedPath(r.data)?.let { path -> setGameStorage(path, GameStorage.labelFor(this, path)) }
|
||||
@@ -1127,6 +1128,7 @@ class MainActivity : ComponentActivity() {
|
||||
renderer = if (mode == SessionService.MODE_DESKTOP) renderer else null,
|
||||
gameStorage = if (mode == SessionService.MODE_STEAM) gameStorage else null,
|
||||
storageOptions = storageOptions,
|
||||
storageDiagnostics = mode == SessionService.MODE_STEAM && storageDiagnostics,
|
||||
fexPreset = if (mode == SessionService.MODE_STEAM) fexPreset else null,
|
||||
steamChannel = if (mode == SessionService.MODE_STEAM) steamChannel else null,
|
||||
steamDeckMode = mode == SessionService.MODE_STEAM && steamDeckMode,
|
||||
@@ -1196,6 +1198,10 @@ class MainActivity : ComponentActivity() {
|
||||
onPickGameStorageFolder = {
|
||||
pickGameStorage.launch(InAppFilePicker.buildDirIntent(this, "Choose the game storage folder", gameStorage.ifEmpty { null }))
|
||||
},
|
||||
onStorageDiagnostics = { on ->
|
||||
SessionPrefs.setStorageDiagnosticsEnabled(this, on)
|
||||
storageDiagnostics = on
|
||||
},
|
||||
onFexPreset = { id -> SessionPrefs.setFexPreset(this, id); fexPreset = id },
|
||||
onSteamChannel = { id -> SessionPrefs.setSteamChannel(this, id); steamChannel = id },
|
||||
onSteamDeckMode = { on ->
|
||||
@@ -1327,6 +1333,7 @@ class MainActivity : ComponentActivity() {
|
||||
refreshWifiDiscovery()
|
||||
renderer = SessionPrefs.desktopRenderer(this)
|
||||
gameStorage = SessionPrefs.gameStorage(this)
|
||||
storageDiagnostics = SessionPrefs.storageDiagnosticsEnabled(this)
|
||||
settingsMode = mode
|
||||
// The page opens at once, on what was last read; the slow part (driver files, a walk of the
|
||||
// added-games folders, the storage volumes) lands while it animates in.
|
||||
|
||||
@@ -448,6 +448,14 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("logs", on).apply()
|
||||
}
|
||||
|
||||
/** Steam storage-call diagnostics are opt-in because they add timing work to file operations. */
|
||||
fun storageDiagnosticsEnabled(context: Context): Boolean =
|
||||
prefs(context).getBoolean("storageDiagnostics", false)
|
||||
|
||||
fun setStorageDiagnosticsEnabled(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("storageDiagnostics", on).apply()
|
||||
}
|
||||
|
||||
// ── Per-mode display ────────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
|
||||
@@ -390,7 +390,7 @@ class SessionService : Service() {
|
||||
// whatever a session leaves behind. The client abandons tens of megabytes of streams a run.
|
||||
FileUtils.clear(File(cacheDir, "shm"))
|
||||
|
||||
val binds = sessionBinds(controllersOn, fakeInputDir)
|
||||
val binds = sessionBinds(controllersOn, fakeInputDir, sessionDir, guest)
|
||||
// The fast path is told exactly the rootfs and binds proot is given (ProotFastPath).
|
||||
val fastPathKey = if (ProotFastPath.enabled(this)) {
|
||||
val prootBinds = LinuxRuntime.binds(
|
||||
@@ -720,7 +720,12 @@ class SessionService : Service() {
|
||||
}
|
||||
|
||||
/** What proot binds into the guest: the pads, the battery, storage, the game library, added games and ROMs. */
|
||||
private fun sessionBinds(controllersOn: Boolean, fakeInputDir: File): ArrayList<String> {
|
||||
private fun sessionBinds(
|
||||
controllersOn: Boolean,
|
||||
fakeInputDir: File,
|
||||
sessionDir: File,
|
||||
guest: MutableList<String>,
|
||||
): ArrayList<String> {
|
||||
val binds = ArrayList<String>()
|
||||
if (controllersOn) binds.add(fakeInputDir.path + ":/dev/input")
|
||||
if (controllersOn) binds.addAll(deckBinds)
|
||||
@@ -779,6 +784,7 @@ class SessionService : Service() {
|
||||
// bannerlator-steam-library registers with the client. Nothing bound = the script removes
|
||||
// the entry, so the client never offers a place that is not there.
|
||||
val library = GameStorage.effective(this)
|
||||
var storageDiagnosticLibrary: File? = null
|
||||
if (library != null) {
|
||||
val problem = GameStorage.prepare(library.path)
|
||||
if (problem == null) {
|
||||
@@ -787,6 +793,7 @@ class SessionService : Service() {
|
||||
File(LinuxRuntime.rootDir(this), "mnt/bannerlator-sd").mkdirs()
|
||||
try {
|
||||
binds.addAll(SecondaryLibrary.binds(filesDir, File(library.path)))
|
||||
storageDiagnosticLibrary = File(library.path)
|
||||
Log.i(TAG, "game storage: ${library.path} -> /mnt/droiddeck-sd (\"${library.label}\"); prefixes and native tools private")
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "game storage: private directories could not be prepared; internal only this session", e)
|
||||
@@ -797,6 +804,26 @@ class SessionService : Service() {
|
||||
} else {
|
||||
Log.i(TAG, "game storage: internal only")
|
||||
}
|
||||
if (SessionState.mode == MODE_STEAM && SessionPrefs.storageDiagnosticsEnabled(this)) {
|
||||
val target = storageDiagnosticLibrary ?: File(LinuxRuntime.rootDir(this), "root/.local/share/Steam")
|
||||
val device = StorageDiagnostics.writeSnapshot(
|
||||
sessionDir, target,
|
||||
selectedLibrary = if (storageDiagnosticLibrary != null) "secondary" else "internal",
|
||||
removable = storageDiagnosticLibrary?.let {
|
||||
runCatching { Environment.isExternalStorageRemovable(it) }.getOrDefault(false)
|
||||
} ?: false,
|
||||
)
|
||||
if (device != null) {
|
||||
// guest already has the session command at this point. Put these with the `env -i`
|
||||
// assignments so they reach the Steam process instead of becoming script args.
|
||||
val envAt = guest.indexOf(LinuxRuntime.SESSION_SCRIPT).takeIf { it >= 0 } ?: guest.size
|
||||
guest.add(envAt, "BL_STORAGE_DIAGNOSTICS=1")
|
||||
guest.add(envAt + 1, "BL_STORAGE_DEVICE=$device")
|
||||
guest.add(envAt + 2, "BL_STORAGE_LOG=${File(sessionDir, "storage.log").absolutePath}")
|
||||
} else {
|
||||
Log.w(TAG, "storage diagnostics: selected library could not be identified; metadata snapshot only")
|
||||
}
|
||||
}
|
||||
// The user's own games folder (the Steam cog's "Added games"), bound at a fixed place so
|
||||
// the shortcuts the app writes point somewhere whatever storage the folder is on.
|
||||
for (root in com.droiddeck.launcher.frontend.AddedGames.roots(this)) {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.os.StatFs
|
||||
import android.system.Os
|
||||
import android.util.Log
|
||||
import java.io.File
|
||||
|
||||
/** The opt-in snapshot written beside a session's other logs. */
|
||||
object StorageDiagnostics {
|
||||
private const val TAG = "StorageDiagnostics"
|
||||
|
||||
/**
|
||||
* Records facts about the library actually selected for this session and returns its device
|
||||
* number for the preload shim. The path and volume ID stay out of the shared log.
|
||||
*/
|
||||
fun writeSnapshot(
|
||||
sessionDir: File,
|
||||
library: File,
|
||||
selectedLibrary: String,
|
||||
removable: Boolean,
|
||||
): Long? {
|
||||
val device = runCatching { Os.stat(library.absolutePath).st_dev }.getOrNull()
|
||||
val text = buildString {
|
||||
appendLine("DroidDeck storage diagnostics v1")
|
||||
appendLine("selected_library=$selectedLibrary")
|
||||
appendLine("volume_removable=$removable")
|
||||
appendLine("filesystem=${filesystemType(library) ?: "unknown"}")
|
||||
runCatching { StatFs(library.path) }.onSuccess { fs ->
|
||||
appendLine("block_size_bytes=${fs.blockSizeLong}")
|
||||
appendLine("total_bytes=${fs.totalBytes}")
|
||||
appendLine("available_bytes=${fs.availableBytes}")
|
||||
}.onFailure { appendLine("capacity_error=${it.javaClass.simpleName}") }
|
||||
appendLine("native_observation=${if (device != null) "enabled" else "unavailable"}")
|
||||
appendLine("public_symbol_interposition=${if (device != null) "enabled" else "unavailable"}")
|
||||
appendLine("direct_syscalls_and_libc_internal_calls=not_observed")
|
||||
appendLine("pwrite_timing=sampled_1_in_32")
|
||||
appendLine("per_process_allocation_detail_limit=64")
|
||||
appendLine("storage_log_limit_bytes=524288")
|
||||
}
|
||||
return try {
|
||||
File(sessionDir, "storage.log").writeText(text)
|
||||
device
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "could not write storage diagnostic snapshot", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/** The longest matching mount entry determines the filesystem for nested bindable folders. */
|
||||
private fun filesystemType(path: File): String? = runCatching {
|
||||
val canonical = path.canonicalPath
|
||||
File("/proc/mounts").useLines { lines ->
|
||||
lines.mapNotNull { line ->
|
||||
val fields = line.split(Regex("\\s+"))
|
||||
if (fields.size < 3) null else {
|
||||
val mount = unescapeMount(fields[1]).trimEnd('/').ifEmpty { "/" }
|
||||
val matches = canonical == mount ||
|
||||
(mount == "/" && canonical.startsWith('/')) || canonical.startsWith("$mount/")
|
||||
if (matches) mount.length to fields[2] else null
|
||||
}
|
||||
}.maxByOrNull { it.first }?.second?.takeIf { it.matches(Regex("[A-Za-z0-9._-]+")) }
|
||||
}
|
||||
}.getOrNull()
|
||||
|
||||
private fun unescapeMount(value: String): String = value
|
||||
.replace("\\040", " ")
|
||||
.replace("\\011", "\t")
|
||||
.replace("\\134", "\\")
|
||||
}
|
||||
@@ -70,6 +70,8 @@ class ModeSettings(
|
||||
val renderer: String?,
|
||||
val gameStorage: String? = null,
|
||||
val storageOptions: List<Pair<String, String>> = emptyList(),
|
||||
/** Steam only: record allocation and sampled storage timings in the next session's Share logs. */
|
||||
val storageDiagnostics: Boolean = false,
|
||||
val fexPreset: String? = null,
|
||||
/** Steam only: games are stretched to fill the screen (null = not a Steam page). */
|
||||
val forceFullscreen: Boolean? = null,
|
||||
@@ -130,6 +132,7 @@ class ModeSettingsActions(
|
||||
val onRenderer: (String) -> Unit,
|
||||
val onGameStorage: (path: String, label: String) -> Unit = { _, _ -> },
|
||||
val onPickGameStorageFolder: () -> Unit = {},
|
||||
val onStorageDiagnostics: (Boolean) -> Unit = {},
|
||||
val onFexPreset: (String) -> Unit = {},
|
||||
val onForceFullscreen: (Boolean) -> Unit = {},
|
||||
val onStretch16x9: (Boolean) -> Unit = {},
|
||||
@@ -457,6 +460,11 @@ fun ModeSettingsPage(s: ModeSettings, a: ModeSettingsActions) {
|
||||
}
|
||||
}
|
||||
}
|
||||
ToggleRow(
|
||||
host, "storageDiagnostics", stringResource(R.string.mode_storage_diagnostics),
|
||||
stringResource(R.string.mode_storage_diagnostics_hint), s.storageDiagnostics,
|
||||
onChange = a.onStorageDiagnostics,
|
||||
)
|
||||
}
|
||||
if (!steam && s.renderer != null) SettingsGroup(stringResource(R.string.mode_renderer)) {
|
||||
ChoiceRow(
|
||||
|
||||
Reference in new issue
Block a user