From eaec022569ee1e2394020f28647f1820f35ad435 Mon Sep 17 00:00:00 2001 From: Peaksol Date: Thu, 31 Dec 2020 17:21:03 +0000 Subject: [PATCH 1/2] Typo --- docs/Run.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Run.md b/docs/Run.md index f48365e1e..61d821e80 100644 --- a/docs/Run.md +++ b/docs/Run.md @@ -26,7 +26,7 @@ Mirai Console 可以独立启动,也可以被嵌入到某个应用中。 #### 从 JCenter 下载模块 -mirai 在版本发布时会将发布的构建存放与 [mirai-bintray-repo]。 +mirai 在版本发布时会将发布的构建存放于 [mirai-bintray-repo]。 - mirai-core 会提供 [mirai-core-all] - mirai-console 与其各个模块都会提供 `-all` 的 Shadowed 构建 @@ -141,4 +141,4 @@ PluginManager.INSTANCE.loadPlugin(Plugin) PluginManager.INSTANCE.enablePlugin(Plugin) ``` -但注意:这种方法目前是实验性的——一些特定的功能如注册扩展可能不会正常工作。 \ No newline at end of file +但注意:这种方法目前是实验性的——一些特定的功能如注册扩展可能不会正常工作。 From c826ffd988a6f6f27810a291fa0c592d197669e6 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Fri, 1 Jan 2021 20:36:24 +0800 Subject: [PATCH 2/2] Resolve errors in Android --- .../src/command/BuiltInCommands.kt | 59 ++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/backend/mirai-console/src/command/BuiltInCommands.kt b/backend/mirai-console/src/command/BuiltInCommands.kt index 33141108d..35d3a91ac 100644 --- a/backend/mirai-console/src/command/BuiltInCommands.kt +++ b/backend/mirai-console/src/command/BuiltInCommands.kt @@ -355,6 +355,54 @@ public object BuiltInCommands { ConsoleCommandOwner, "status", "states", "状态", description = "获取 Mirai Console 运行状态" ), BuiltInCommandInternal { + + internal interface MemoryUsageGet { + val heapMemoryUsage: MUsage + val nonHeapMemoryUsage: MUsage + val objectPendingFinalizationCount:Int + } + internal val memoryUsageGet: MemoryUsageGet = kotlin.runCatching { + ByMemoryMXBean + }.getOrElse { ByRuntime } + + internal object ByMemoryMXBean : MemoryUsageGet { + val memoryMXBean = ManagementFactory.getMemoryMXBean() + val MemoryUsage.m: MUsage + get() = MUsage( + committed, init, used, max + ) + override val heapMemoryUsage: MUsage + get() = memoryMXBean.heapMemoryUsage.m + override val nonHeapMemoryUsage: MUsage + get() = memoryMXBean.nonHeapMemoryUsage.m + override val objectPendingFinalizationCount: Int + get() = memoryMXBean.objectPendingFinalizationCount + } + + internal object ByRuntime : MemoryUsageGet { + override val heapMemoryUsage: MUsage + get() { + val runtime = Runtime.getRuntime() + return MUsage( + committed = 0, + init = 0, + used = runtime.maxMemory() - runtime.freeMemory(), + max = runtime.maxMemory() + ) + } + override val nonHeapMemoryUsage: MUsage + get() = MUsage(-1, -1, -1, -1) + override val objectPendingFinalizationCount: Int + get() = -1 + } + + internal data class MUsage( + val committed: Long, + val init: Long, + val used: Long, + val max: Long, + ) + @Handler public suspend fun CommandSender.handle() { sendAnsiMessage { @@ -393,16 +441,14 @@ public object BuiltInCommands { } reset().append("\n\n") - val memoryMXBean = ManagementFactory.getMemoryMXBean() - append("Object Pending Finalization Count: ") .emeraldGreen() - .append(memoryMXBean.objectPendingFinalizationCount) + .append(memoryUsageGet.objectPendingFinalizationCount) .reset() .append("\n") val l1 = arrayOf("committed", "init", "used", "max") - val l2 = renderMemoryUsage(memoryMXBean.heapMemoryUsage) - val l3 = renderMemoryUsage(memoryMXBean.nonHeapMemoryUsage) + val l2 = renderMemoryUsage(memoryUsageGet.heapMemoryUsage) + val l3 = renderMemoryUsage(memoryUsageGet.nonHeapMemoryUsage) val lmax = calculateMax(l1, l2.first, l3.first) append(" ") @@ -451,7 +497,6 @@ public object BuiltInCommands { rendMU(l2) append("\nNon-Heap Memory: ") rendMU(l3) - renderMemoryUsage(memoryMXBean.nonHeapMemoryUsage) } } @@ -484,7 +529,7 @@ public object BuiltInCommands { } } - private fun AnsiMessageBuilder.renderMemoryUsage(usage: MemoryUsage) = arrayOf( + private fun AnsiMessageBuilder.renderMemoryUsage(usage: MUsage) = arrayOf( renderMemoryUsageNumber(usage.committed), renderMemoryUsageNumber(usage.init), renderMemoryUsageNumber(usage.used),