Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Nov 14, 2024
1 parent 021e457 commit 9ea26b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions app/src/main/java/io/legado/app/help/CrashHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import java.io.StringWriter
import java.text.SimpleDateFormat
import java.util.Date
import java.util.concurrent.TimeUnit
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.set

/**
* 异常管理类
Expand Down Expand Up @@ -172,12 +169,17 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler {
/**
* 进行堆转储
*/
fun doHeapDump() {
fun doHeapDump(manually: Boolean = false) {
val heapDir = appCtx
.externalCache
.getFile("heapDump")
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
Debug.dumpHprofData(heapDumpName)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/legado/app/ui/about/AboutFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class AboutFragment : PreferenceFragmentCompat() {
}
appCtx.toastOnUi("开始创建堆转储")
System.gc()
CrashHandler.doHeapDump()
CrashHandler.doHeapDump(true)
val doc = FileDoc.fromUri(Uri.parse(backupPath), true)
if (!copyHeapDump(doc)) {
appCtx.toastOnUi("未找到堆转储文件")
Expand Down

0 comments on commit 9ea26b5

Please sign in to comment.