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.
This commit is contained in:
1 parent
aac1fa0da5
commit
ed0f5678b3
1 file changed
+7
@@ -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)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user