Use new DataSize.toPerfectRepresentationString
This commit is contained in:
parent
ba7578cba9
commit
f1a366d431
4 changed files with 37 additions and 27 deletions
|
@ -20,6 +20,7 @@
|
|||
package de.staropensource.engine.base.implementable
|
||||
|
||||
import de.staropensource.engine.base.Engine.Companion.logger
|
||||
import de.staropensource.engine.base.extension.toStringType
|
||||
import de.staropensource.engine.base.utility.misc.StackTraceUtils
|
||||
|
||||
/**
|
||||
|
@ -103,21 +104,7 @@ abstract class Event {
|
|||
var value: Any?
|
||||
for (argument: String in arguments.keys) {
|
||||
value = arguments[argument]
|
||||
append("\n${argument} = ")
|
||||
|
||||
// Pretty formatting
|
||||
if (value is Enum<*>)
|
||||
append("${value::class.qualifiedName ?: "<anonymous enum>"}.${value.name}")
|
||||
else if (value is CharSequence)
|
||||
append("\"${value}\"")
|
||||
else if (value is Char)
|
||||
append("'${value}'")
|
||||
else if (value is Byte)
|
||||
append("0x${value.toHexString(HexFormat.UpperCase)}")
|
||||
else if (value is ByteArray)
|
||||
append("0x[ ${value.toHexString(HexFormat.UpperCase)} ]")
|
||||
else
|
||||
append(value.toString())
|
||||
append("\n${argument} = ${arguments[argument]?.toStringType()}")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -22,10 +22,8 @@ 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.DataSize
|
||||
import de.staropensource.engine.base.utility.Environment
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.toLocalDateTime
|
||||
|
||||
/**
|
||||
* [CrashCategory] implementation
|
||||
|
@ -65,7 +63,7 @@ class EnvironmentCrashCategory private constructor() : CrashCategory {
|
|||
throwable: Throwable?,
|
||||
fatal: Boolean,
|
||||
): LinkedHashMap<String, Any?> {
|
||||
if (Environment.isElevated() == null)
|
||||
if (Environment.getOperatingSystem() == null)
|
||||
return linkedMapOf(
|
||||
Pair("Not available.", null)
|
||||
)
|
||||
|
@ -78,10 +76,10 @@ class EnvironmentCrashCategory private constructor() : CrashCategory {
|
|||
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("Total", DataSize.ofBytes(Environment.getMemoryTotal()!!.toULong()).toPerfectRepresentationString()),
|
||||
Pair("Available", DataSize.ofBytes(Environment.getMemoryAvailable()!!.toULong()).toPerfectRepresentationString()),
|
||||
Pair("Used", DataSize.ofBytes(Environment.getMemoryUsed()!!.toULong()).toPerfectRepresentationString()),
|
||||
Pair("Page size", DataSize.ofBytes(Environment.getMemoryPageSize()!!.toULong()).toPerfectRepresentationString()),
|
||||
)),
|
||||
Pair("CPU", linkedMapOf<String, String>(
|
||||
Pair("Logical processors", Environment.getCPULogicalCount()!!.toString()),
|
||||
|
@ -97,7 +95,7 @@ class EnvironmentCrashCategory private constructor() : CrashCategory {
|
|||
Pair("Device identifier", graphicsCard.getDeviceIdentifier()),
|
||||
Pair("Manufacturer", graphicsCard.getManufacturer()),
|
||||
Pair("Version", graphicsCard.getVersion()),
|
||||
Pair("VRAM", "${graphicsCard.getVideoMemory()} bytes"),
|
||||
Pair("VRAM", DataSize.ofBytes(graphicsCard.getVideoMemory().toULong()).toPerfectRepresentationString()),
|
||||
))
|
||||
|
||||
return map
|
||||
|
|
|
@ -22,7 +22,7 @@ package de.staropensource.engine.base.utility
|
|||
import java.math.RoundingMode
|
||||
import java.text.DecimalFormat
|
||||
import java.text.DecimalFormatSymbols
|
||||
import java.util.Locale
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Converts between various data size units.
|
||||
|
@ -40,6 +40,15 @@ data class DataSize(
|
|||
* @since v1-alpha10
|
||||
*/
|
||||
companion object {
|
||||
/**
|
||||
* Creates a new [DataSize] instance.
|
||||
*
|
||||
* @param bytes bytes to pass
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun ofBytes(bytes: ULong): DataSize = DataSize(bytes)
|
||||
|
||||
/**
|
||||
* Converts the specified amount of
|
||||
* kilobytes into a [DataSize] instance.
|
||||
|
@ -310,6 +319,21 @@ data class DataSize(
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the perfect representation
|
||||
* of the specified data size.
|
||||
*
|
||||
* @param binary uses a factor of `1024` (giving [Unit.MEBIBYTE], [Unit.GIBIBYTE], ...) instead of `1000` (giving [Unit.MEGABYTE], [Unit.GIGABYTE], ...)
|
||||
* @param shortName whether to use the Unit's short name (see [Unit.getShortName]) or it's long name (see [Unit.getName])
|
||||
* @return pair of the converted amount and the [Unit]
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun toPerfectRepresentationString(binary: Boolean = true, shortName: Boolean = true): String {
|
||||
val representation: Pair<Double, Unit> = toPerfectRepresentation(binary = binary)
|
||||
|
||||
return "${representation.first} ${if (shortName) representation.second.getShortName() else representation.second.getName()}"
|
||||
}
|
||||
|
||||
|
||||
// -----> Inner classes
|
||||
/**
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.io.InputStreamReader
|
|||
import java.io.Reader
|
||||
import java.io.StringReader
|
||||
import java.util.*
|
||||
import kotlin.Throws
|
||||
|
||||
/**
|
||||
* Loads the specified `-git.properties` and
|
||||
|
@ -503,8 +504,8 @@ open class BuildInformation
|
|||
gitCommitAuthorMap.put("Email address", info!!.gitCommitAuthorEmail)
|
||||
|
||||
// Add to 'gitCommitMap'
|
||||
gitCommitMap.put("Identifier", "'${info!!.gitCommitIdentifierLong}'")
|
||||
gitCommitMap.put("Message (short)", "'${info!!.gitCommitMessageShort}'")
|
||||
gitCommitMap.put("Identifier", info!!.gitCommitIdentifierLong)
|
||||
gitCommitMap.put("Message (short)", info!!.gitCommitMessageShort)
|
||||
gitCommitMap.put("Time", "${gitCommitTime.dayOfMonth}.${gitCommitTime.monthNumber}.${gitCommitTime.year} ${gitCommitTime.hour}:${gitCommitTime.minute}:${gitCommitTime.second} UTC")
|
||||
gitCommitMap.put("Author", gitCommitAuthorMap)
|
||||
|
||||
|
|
Loading…
Reference in a new issue