From a49e437a4a0ab311e019e7e4092b36f0c69ca800 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Fri, 20 Dec 2024 02:50:50 +0100 Subject: [PATCH] Add "Environment" crash category --- .../engine/base/EngineConfiguration.kt | 4 +- .../crashcategory/EnvironmentCrashCategory.kt | 104 ++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EnvironmentCrashCategory.kt diff --git a/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt b/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt index 95d3ad8..577f92d 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt @@ -29,6 +29,7 @@ import de.staropensource.engine.base.implementation.logging.formatbuilder.SOSLSv import de.staropensource.engine.base.logging.Logger import de.staropensource.engine.base.implementable.logging.LoggerThreadingHandler import de.staropensource.engine.base.implementation.logging.crashcategory.EngineCrashCategory +import de.staropensource.engine.base.implementation.logging.crashcategory.EnvironmentCrashCategory import de.staropensource.engine.base.type.logging.ChannelSettings import de.staropensource.engine.base.type.logging.Feature import de.staropensource.engine.base.type.logging.Level @@ -145,7 +146,8 @@ class EngineConfiguration private constructor() { @JvmStatic var logCrashCategories: LinkedHashSet = linkedSetOf( InfoCrashCategory.instance, - EngineCrashCategory.instance + EngineCrashCategory.instance, + EnvironmentCrashCategory.instance ) /** diff --git a/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EnvironmentCrashCategory.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EnvironmentCrashCategory.kt new file mode 100644 index 0000000..a8a40e6 --- /dev/null +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EnvironmentCrashCategory.kt @@ -0,0 +1,104 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Authors + * Licensed under the GNU General Public License v3. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.engine.base.implementation.logging.crashcategory + +import de.staropensource.engine.base.implementable.logging.CrashCategory +import de.staropensource.engine.base.type.logging.Call +import de.staropensource.engine.base.type.logging.ChannelSettings +import de.staropensource.engine.base.utility.Environment +import kotlinx.datetime.LocalDateTime +import kotlinx.datetime.TimeZone +import kotlinx.datetime.toLocalDateTime + +/** + * [CrashCategory] implementation + * providing information about the + * environment the engine runs in. + * + * @since v1-alpha10 + */ +class EnvironmentCrashCategory private constructor() : CrashCategory { + /** + * Companion object of [EnvironmentCrashCategory]. + * + * @since v1-alpha10 + */ + companion object { + /** + * Global instance of [EnvironmentCrashCategory]. + * + * @since v1-alpha10 + */ + @JvmStatic + val instance: EnvironmentCrashCategory = EnvironmentCrashCategory() + } + + override fun check(): Boolean { + return true + } + + override fun getName(): String { + return "Environment" + } + + override fun execute( + call: Call, + channelSettings: ChannelSettings?, + throwable: Throwable?, + fatal: Boolean, + ): LinkedHashMap { + if (Environment.isElevated() == null) + return linkedMapOf( + Pair("Not available.", null) + ) + + // Create map + val map: LinkedHashMap = linkedMapOf( + Pair("General", linkedMapOf( + Pair("Operating system", Environment.getOperatingSystem()!!.humanFriendly()), + Pair("Elevated", if (Environment.isElevated()!!) "yes" else "no"), + Pair("Bitness", "${Environment.getBitness()!!} bits"), + )), + Pair("Memory", linkedMapOf( + Pair("Total", "${Environment.getMemoryTotal()!!} bytes"), + Pair("Available", "${Environment.getMemoryAvailable()!!} bytes"), + Pair("Used", "${Environment.getMemoryUsed()!!} bytes"), + Pair("Page size", "${Environment.getMemoryPageSize()!!} bytes"), + )), + Pair("CPU", linkedMapOf( + Pair("Logical processors", Environment.getCPULogicalCount()!!.toString()), + Pair("Physical processors", Environment.getCPUPhysicalCount()!!.toString()), + )), + Pair("GPUs", linkedMapOf()), + ) + + // -> Add graphics cards + @Suppress("UNCHECKED_CAST") + for (graphicsCard: Environment.GraphicsCard in Environment.getGPUs()!!) + (map["GPUs"] as LinkedHashMap).put(graphicsCard.getName(), linkedMapOf( + Pair("Device identifier", graphicsCard.getDeviceIdentifier()), + Pair("Manufacturer", graphicsCard.getManufacturer()), + Pair("Version", graphicsCard.getVersion()), + Pair("VRAM", "${graphicsCard.getVideoMemory()} bytes"), + )) + + return map + } +}