From 9974423e2bdc474bb53cd9e3eb546ce7348634e5 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Thu, 18 Jun 2015 20:28:40 +0300 Subject: [PATCH] Disable performance time counters by default --- .../cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt | 1 + .../src/org/jetbrains/kotlin/util/PerformanceCounter.kt | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index 5c6fde64d83..e3562a67f17 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -61,6 +61,7 @@ public open class K2JVMCompiler : CLICompiler() { 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) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/util/PerformanceCounter.kt b/compiler/frontend/src/org/jetbrains/kotlin/util/PerformanceCounter.kt index a48fd1b7627..32c1d8fba35 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/util/PerformanceCounter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/util/PerformanceCounter.kt @@ -26,6 +26,8 @@ public class PerformanceCounter jvmOverloads constructor (val name: String, val private val enteredCounters = ThreadLocal>() + 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(block: () -> T): T { count++ + if (!enabled) return block() + val needTime = !reenterable || enterCounter(this) val startTime = currentThreadCpuTime() try {