Disable performance time counters by default

This commit is contained in:
Stanislav Erokhin
2015-06-18 20:28:40 +03:00
parent 94e3b058b2
commit 9974423e2b
2 changed files with 9 additions and 0 deletions
@@ -61,6 +61,7 @@ public open class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
PathUtil.getKotlinPathsForCompiler()
messageSeverityCollector.report(CompilerMessageSeverity.LOGGING, "Using Kotlin home directory " + paths.getHomePath(), CompilerMessageLocation.NO_LOCATION)
PerformanceCounter.setTimeCounterEnabled(arguments.reportPerf);
val configuration = CompilerConfiguration()
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageSeverityCollector)
@@ -26,6 +26,8 @@ public class PerformanceCounter jvmOverloads constructor (val name: String, val
private val enteredCounters = ThreadLocal<MutableSet<PerformanceCounter>>()
private var enabled = false
init {
threadMxBean.setThreadCpuTimeEnabled(true)
}
@@ -52,6 +54,10 @@ public class PerformanceCounter jvmOverloads constructor (val name: String, val
}
countersCopy.forEach { it.report(consumer) }
}
public fun setTimeCounterEnabled(enable: Boolean) {
enabled = enable
}
}
private var count: Int = 0
@@ -69,6 +75,8 @@ public class PerformanceCounter jvmOverloads constructor (val name: String, val
public fun time<T>(block: () -> T): T {
count++
if (!enabled) return block()
val needTime = !reenterable || enterCounter(this)
val startTime = currentThreadCpuTime()
try {