
ru.tinkoff.plugins.buildmetrics.system.utils.GarbageCollectorUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of build-metrics-system Show documentation
Show all versions of build-metrics-system Show documentation
Extension for tinkoff build metrics gradle plugin.
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