From 9819de1abd4539edb555b0c0e24f1a4090ef473f Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Fri, 17 Mar 2017 16:30:54 +0300 Subject: [PATCH] Improve daemon client debug reports Before this change a daemon client debug messages were printed only when the client could not connect and the 'kotlin.daemon.verbose' system property was set up. Now messages are printed if the debug logging is enabled and the 'kotlin.daemon.verbose' is set up. --- .../kotlin/compilerRunner/KotlinCompilerRunner.kt | 8 +++++++- .../kotlin/daemon/client/KotlinCompilerClient.kt | 4 +++- .../jetbrains/kotlin/compilerRunner/JpsKotlinLogger.kt | 3 +++ .../jetbrains/kotlin/compilerRunner/GradleKotlinLogger.kt | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/KotlinCompilerRunner.kt b/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/KotlinCompilerRunner.kt index 89934bd1639..8bd12479ed5 100644 --- a/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/KotlinCompilerRunner.kt +++ b/compiler/compiler-runner/src/org/jetbrains/kotlin/compilerRunner/KotlinCompilerRunner.kt @@ -42,6 +42,8 @@ interface KotlinLogger { fun warn(msg: String) fun info(msg: String) fun debug(msg: String) + + val isDebugEnabled: Boolean } abstract class KotlinCompilerRunner { @@ -61,11 +63,15 @@ abstract class KotlinCompilerRunner { val daemonJVMOptions = configureDaemonJVMOptions(inheritMemoryLimits = true, inheritAdditionalProperties = true) val daemonReportMessages = ArrayList() + val daemonReportingTargets = when { + log.isDebugEnabled -> DaemonReportingTargets(messages = daemonReportMessages) + else -> DaemonReportingTargets(messageCollector = environment.messageCollector) + } val profiler = if (daemonOptions.reportPerf) WallAndThreadAndMemoryTotalProfiler(withGC = false) else DummyProfiler() val connection = profiler.withMeasure(null) { - val daemon = KotlinCompilerClient.connectToCompileService(compilerId, daemonJVMOptions, daemonOptions, DaemonReportingTargets(null, daemonReportMessages), true, true) + val daemon = KotlinCompilerClient.connectToCompileService(compilerId, daemonJVMOptions, daemonOptions, daemonReportingTargets, true, true) DaemonConnection(daemon, daemon?.leaseCompileSession(flagFile.absolutePath)?.get() ?: CompileService.NO_SESSION) } diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt index 1b8529bb996..837e761c838 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt @@ -395,11 +395,13 @@ object KotlinCompilerClient { daemon.inputStream .reader() .forEachLine { + reportingTargets.report(DaemonReportCategory.DEBUG, it, "daemon") + if (it == COMPILE_DAEMON_IS_READY_MESSAGE) { + reportingTargets.report(DaemonReportCategory.DEBUG, "Received the message signalling that the daemon is ready") isEchoRead.release() return@forEachLine } - reportingTargets.report(DaemonReportCategory.DEBUG, it, "daemon") } } finally { diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinLogger.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinLogger.kt index eadd0f387cc..47aacea901f 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinLogger.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinLogger.kt @@ -34,4 +34,7 @@ internal class JpsKotlinLogger(private val log: Logger) : KotlinLogger { override fun debug(msg: String) { log.debug(msg) } + + override val isDebugEnabled: Boolean + get() = log.isDebugEnabled } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinLogger.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinLogger.kt index f25bd5f82cd..3810881d21f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinLogger.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinLogger.kt @@ -34,4 +34,7 @@ internal class GradleKotlinLogger(private val log: Logger) : KotlinLogger { override fun warn(msg: String) { log.warn(msg) } + + override val isDebugEnabled: Boolean + get() = log.isDebugEnabled } \ No newline at end of file