From 8bf940eb7b59b5e5e326cfc06d51bdb54393f33b Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Fri, 28 Oct 2022 14:41:50 +0200 Subject: perf(compute/sim): Use static logger field This change updates the `Guest` class implementation to use a static logger field instead of allocation a new logger for every guest. --- .../kotlin/org/opendc/compute/simulator/internal/Guest.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt index c12e6fad..ca947625 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt +++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt @@ -48,11 +48,6 @@ internal class Guest( val server: Server, val machine: SimVirtualMachine ) { - /** - * The logger instance of this guest. - */ - private val logger = KotlinLogging.logger {} - /** * The state of the [Guest]. * @@ -68,12 +63,12 @@ internal class Guest( fun start() { when (state) { ServerState.TERMINATED, ServerState.ERROR -> { - logger.info { "User requested to start server ${server.uid}" } + LOGGER.info { "User requested to start server ${server.uid}" } doStart() } ServerState.RUNNING -> return ServerState.DELETED -> { - logger.warn { "User tried to start deleted server" } + LOGGER.warn { "User tried to start deleted server" } throw IllegalArgumentException("Server is deleted") } else -> assert(false) { "Invalid state transition" } @@ -239,4 +234,9 @@ internal class Guest( _downtime += duration } } + + private companion object { + @JvmStatic + private val LOGGER = KotlinLogging.logger {} + } } -- cgit v1.2.3