This commit is contained in:
Horis
2024-11-14 11:25:22 +08:00
parent b780f37fb0
commit eb1df7a8aa
2 changed files with 8 additions and 6 deletions
@@ -28,9 +28,6 @@ import java.io.StringWriter
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date import java.util.Date
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.set
/** /**
* 异常管理类 * 异常管理类
@@ -172,12 +169,17 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler {
/** /**
* 进行堆转储 * 进行堆转储
*/ */
fun doHeapDump() { fun doHeapDump(manually: Boolean = false) {
val heapDir = appCtx val heapDir = appCtx
.externalCache .externalCache
.getFile("heapDump") .getFile("heapDump")
heapDir.createFolderReplace() heapDir.createFolderReplace()
val heapFile = heapDir.getFile("heap-dump-${System.currentTimeMillis()}.hprof") val fileName = if (manually) {
"heap-dump-manually-${System.currentTimeMillis()}.hprof"
} else {
"heap-dump-${System.currentTimeMillis()}.hprof"
}
val heapFile = heapDir.getFile(fileName)
val heapDumpName = heapFile.absolutePath val heapDumpName = heapFile.absolutePath
Debug.dumpHprofData(heapDumpName) Debug.dumpHprofData(heapDumpName)
} }
@@ -151,7 +151,7 @@ class AboutFragment : PreferenceFragmentCompat() {
} }
appCtx.toastOnUi("开始创建堆转储") appCtx.toastOnUi("开始创建堆转储")
System.gc() System.gc()
CrashHandler.doHeapDump() CrashHandler.doHeapDump(true)
val doc = FileDoc.fromUri(Uri.parse(backupPath), true) val doc = FileDoc.fromUri(Uri.parse(backupPath), true)
if (!copyHeapDump(doc)) { if (!copyHeapDump(doc)) {
appCtx.toastOnUi("未找到堆转储文件") appCtx.toastOnUi("未找到堆转储文件")