From e638b9fd12b8aa01050738644fb7bd334961c080 Mon Sep 17 00:00:00 2001 From: LepilkinaElena Date: Fri, 1 Nov 2019 18:16:43 +0300 Subject: [PATCH] =?UTF-8?q?K/N=20performance=20gradle=20plugin.=20Added=20?= =?UTF-8?q?options=20and=20right=20code=20size=20for=20=E2=80=A6=20(#2752)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tasks/KotlinNativePerformanceTask.kt | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativePerformanceTask.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativePerformanceTask.kt index 075425eed98..866e9941151 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativePerformanceTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativePerformanceTask.kt @@ -49,6 +49,30 @@ open class NativePerformanceReport : DefaultTask() { return tasks } + private fun folderSize(directory: File): Long { + var length: Long = 0 + directory.listFiles()?.forEach { + length += if (it.isFile) it.length() else folderSize(it) + } + return length + } + + private fun compilerFlagsFromBinary(): List { + val result = mutableListOf() + if (binary.buildType.optimized) { + result.add("-opt") + } + if (binary.buildType.debuggable) { + result.add("-g") + } + result.addAll(binary.freeCompilerArgs) + return result + } + + private fun getPerformanceCompilerOptions() = + (compilerFlagsFromBinary() + binary.linkTask.compilation.kotlinOptions.freeCompilerArgs) + .filter { it in listOf("-g", "-opt", "-Xg0") }.map { "\"$it\"" } + @TaskAction fun generate() { val compileTasks = if (settings.includeAssociatedTasks) @@ -61,8 +85,10 @@ open class NativePerformanceReport : DefaultTask() { if (outputFile.exists()) { project.delete(outputFile.absolutePath) } - project.logger.warn("Next compile tasks which are needed for time measurement are upToDate" + - " and weren't executed:\n${upToDateTasks.joinToString("\n", "- ")}") + project.logger.warn( + "Next compile tasks which are needed for time measurement are upToDate" + + " and weren't executed:\n${upToDateTasks.joinToString("\n", "- ")}" + ) return } val successStatus = allExecutedTasks.all { it.state.failure == null } @@ -70,7 +96,10 @@ open class NativePerformanceReport : DefaultTask() { var codeSize: String? = null if (TrackableMetric.CODE_SIZE in settings.metrics) { codeSize = binary.outputFile.let { - if (it.exists()) "CODE_SIZE ${it.length()}" else null + if (it.exists()) { + val size = if (it.isDirectory) folderSize(it) else it.length() + "CODE_SIZE $size" + } else null } } // Get compile time. @@ -88,6 +117,7 @@ open class NativePerformanceReport : DefaultTask() { } val name = settings.binaryNamesForReport[binary]!! outputFile.writeText(name) + outputFile.appendText("\nOPTIONS ${getPerformanceCompilerOptions()}") if (compileTime != null) { outputFile.appendText("\n$compileTime") }