All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.tinkoff.plugins.buildmetrics.system.utils.GarbageCollectorUtils.kt Maven / Gradle / Ivy

The newest version!
package ru.tinkoff.plugins.buildmetrics.system.utils

import java.io.Serializable
import java.lang.management.ManagementFactory
import kotlin.math.max

interface GarbageCollectorUtils : Serializable {

    /**
     * Returns total collection time of all garbage collector beans in a process.
     *
     * @return collection time in milliseconds.
     * @see java.lang.management.ManagementFactory
     * @see java.lang.management.GarbageCollectorMXBean
     */
    fun collectionTimeMs(): Long
}

internal class GarbageCollectorUtilsImpl : GarbageCollectorUtils {

    override fun collectionTimeMs(): Long {
        return ManagementFactory.getGarbageCollectorMXBeans()
            .sumOf { gc -> max(MIN_GC_TIME_MS, gc.collectionTime) }
    }

    companion object {
        private const val MIN_GC_TIME_MS = 0L
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy