Add "Environment" crash category

This commit is contained in:
JeremyStar™ 2024-12-20 02:50:50 +01:00
parent 01b2955c39
commit a49e437a4a
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 107 additions and 1 deletions

View file

@ -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<CrashCategory> = linkedSetOf(
InfoCrashCategory.instance,
EngineCrashCategory.instance
EngineCrashCategory.instance,
EnvironmentCrashCategory.instance
)
/**

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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<String, Any?> {
if (Environment.isElevated() == null)
return linkedMapOf(
Pair("Not available.", null)
)
// Create map
val map: LinkedHashMap<String, Any?> = linkedMapOf(
Pair("General", linkedMapOf<String, String>(
Pair("Operating system", Environment.getOperatingSystem()!!.humanFriendly()),
Pair("Elevated", if (Environment.isElevated()!!) "yes" else "no"),
Pair("Bitness", "${Environment.getBitness()!!} bits"),
)),
Pair("Memory", linkedMapOf<String, String>(
Pair("Total", "${Environment.getMemoryTotal()!!} bytes"),
Pair("Available", "${Environment.getMemoryAvailable()!!} bytes"),
Pair("Used", "${Environment.getMemoryUsed()!!} bytes"),
Pair("Page size", "${Environment.getMemoryPageSize()!!} bytes"),
)),
Pair("CPU", linkedMapOf<String, String>(
Pair("Logical processors", Environment.getCPULogicalCount()!!.toString()),
Pair("Physical processors", Environment.getCPUPhysicalCount()!!.toString()),
)),
Pair("GPUs", linkedMapOf<String, Any>()),
)
// -> Add graphics cards
@Suppress("UNCHECKED_CAST")
for (graphicsCard: Environment.GraphicsCard in Environment.getGPUs()!!)
(map["GPUs"] as LinkedHashMap<String, Any>).put(graphicsCard.getName(), linkedMapOf<String, String>(
Pair("Device identifier", graphicsCard.getDeviceIdentifier()),
Pair("Manufacturer", graphicsCard.getManufacturer()),
Pair("Version", graphicsCard.getVersion()),
Pair("VRAM", "${graphicsCard.getVideoMemory()} bytes"),
))
return map
}
}