From ed0f5678b38b85e64570610faa7ef1cab39f6c41 Mon Sep 17 00:00:00 2001 From: QIU Date: Sun, 16 Aug 2026 09:33:44 +0000 Subject: [PATCH] fix(cw): cap the crash-probe log file at 1 MiB CwProbe.step() appended one line per call with no size limit, rotation or cleanup, and it runs on every build: CwDeepDecoder is the only ICwDecoder implementation and writes infer_begin + infer_done every 1.5 s inference tick. Measured against the actual line format that is ~170 KB/hour, ~4 MB/day of unbounded growth in files/probe_cw.txt while CW audio is monitored, plus synchronous disk I/O on every inference. Truncate when the file exceeds 1 MiB instead of deleting, so the probe keeps the most recent diagnostics (the reason it exists: the last lines show where a flash-crash died). Simulated 10 h of continuous use: 2.7 MB written in total, file stays bounded around ~640 KB; previously it would have kept all 2.7 MB and grown without limit. --- .../java/com/rtbishop/look4sat/core/data/cw/CwProbe.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/cw/CwProbe.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/cw/CwProbe.kt index 3551d552..82d7aa24 100644 --- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/cw/CwProbe.kt +++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/cw/CwProbe.kt @@ -28,6 +28,12 @@ import android.util.Log */ internal object CwProbe { + /** Keep the diagnostic file bounded: the decoder writes two lines per + * 1.5 s inference tick (~170 KB/hour), so without a cap it grows without + * limit on every release build. Truncate instead of deleting so the + * probe keeps the last diagnostics before a crash. */ + private const val MAX_FILE_BYTES = 1_048_576L // 1 MiB + private var dir: java.io.File? = null fun init(context: Context) { @@ -39,6 +45,7 @@ internal object CwProbe { runCatching { val line = "${System.currentTimeMillis()} $label" val file = java.io.File(target, "probe_cw.txt") + if (file.length() > MAX_FILE_BYTES) file.delete() file.appendText("$line\n") Log.i("CwProbe", line) }