Fix measuring compile time in benchmarks plugin. Plugin creates tasks with same names for each subproject (#4064)
This commit is contained in:
@@ -194,20 +194,23 @@ fun createRunTask(
|
||||
return subproject.tasks.create(name, RunKotlinNativeTask::class.java, linkTask, executable, outputFileName)
|
||||
}
|
||||
|
||||
fun getJvmCompileTime(programName: String): BenchmarkResult =
|
||||
TaskTimerListener.getBenchmarkResult(programName, listOf("compileKotlinMetadata", "jvmJar"))
|
||||
fun getJvmCompileTime(subproject: Project,programName: String): BenchmarkResult =
|
||||
TaskTimerListener.getTimerListenerOfSubproject(subproject)
|
||||
.getBenchmarkResult(programName, listOf("compileKotlinMetadata", "jvmJar"))
|
||||
|
||||
@JvmOverloads
|
||||
fun getNativeCompileTime(programName: String,
|
||||
fun getNativeCompileTime(subproject: Project, programName: String,
|
||||
tasks: List<String> = listOf("linkBenchmarkReleaseExecutableNative")): BenchmarkResult =
|
||||
TaskTimerListener.getBenchmarkResult(programName, tasks)
|
||||
TaskTimerListener.getTimerListenerOfSubproject(subproject).getBenchmarkResult(programName, tasks)
|
||||
|
||||
fun getCompileBenchmarkTime(programName: String, tasksNames: Iterable<String>, repeats: Int, exitCodes: Map<String, Int>) =
|
||||
fun getCompileBenchmarkTime(subproject: Project,
|
||||
programName: String, tasksNames: Iterable<String>,
|
||||
repeats: Int, exitCodes: Map<String, Int>) =
|
||||
(1..repeats).map { number ->
|
||||
var time = 0.0
|
||||
var status = BenchmarkResult.Status.PASSED
|
||||
tasksNames.forEach {
|
||||
time += TaskTimerListener.getTime("$it$number")
|
||||
time += TaskTimerListener.getTimerListenerOfSubproject(subproject).getTime("$it$number")
|
||||
status = if (exitCodes["$it$number"] != 0) BenchmarkResult.Status.FAILED else status
|
||||
}
|
||||
|
||||
@@ -227,20 +230,25 @@ fun toCompileBenchmark(metricDescription: String, status: String, programName: S
|
||||
// Class time tracker for all tasks.
|
||||
class TaskTimerListener: TaskExecutionListener {
|
||||
companion object {
|
||||
val tasksTimes = mutableMapOf<String, Double>()
|
||||
internal val timerListeners = mutableMapOf<String, TaskTimerListener>()
|
||||
|
||||
fun getBenchmarkResult(programName: String, tasksNames: List<String>): BenchmarkResult {
|
||||
val time = tasksNames.map { tasksTimes[it] ?: 0.0 }.sum()
|
||||
// TODO get this info from gradle plugin with exit code end stacktrace.
|
||||
val status = tasksNames.map { tasksTimes.containsKey(it) }.reduce { a, b -> a && b }
|
||||
return BenchmarkResult(programName,
|
||||
if (status) BenchmarkResult.Status.PASSED else BenchmarkResult.Status.FAILED,
|
||||
time, BenchmarkResult.Metric.COMPILE_TIME, time, 1, 0)
|
||||
}
|
||||
|
||||
fun getTime(taskName: String) = tasksTimes[taskName] ?: 0.0
|
||||
internal fun getTimerListenerOfSubproject(subproject: Project) =
|
||||
timerListeners[subproject.name] ?: error("TimeListener for project ${subproject.name} wasn't set")
|
||||
}
|
||||
|
||||
val tasksTimes = mutableMapOf<String, Double>()
|
||||
|
||||
fun getBenchmarkResult(programName: String, tasksNames: List<String>): BenchmarkResult {
|
||||
val time = tasksNames.map { tasksTimes[it] ?: 0.0 }.sum()
|
||||
// TODO get this info from gradle plugin with exit code end stacktrace.
|
||||
val status = tasksNames.map { tasksTimes.containsKey(it) }.reduce { a, b -> a && b }
|
||||
return BenchmarkResult(programName,
|
||||
if (status) BenchmarkResult.Status.PASSED else BenchmarkResult.Status.FAILED,
|
||||
time, BenchmarkResult.Metric.COMPILE_TIME, time, 1, 0)
|
||||
}
|
||||
|
||||
fun getTime(taskName: String) = tasksTimes[taskName] ?: 0.0
|
||||
|
||||
private var startTime = System.nanoTime()
|
||||
|
||||
override fun beforeExecute(task: Task) {
|
||||
@@ -253,5 +261,7 @@ class TaskTimerListener: TaskExecutionListener {
|
||||
}
|
||||
|
||||
fun addTimeListener(subproject: Project) {
|
||||
subproject.gradle.addListener(TaskTimerListener())
|
||||
val listener = TaskTimerListener()
|
||||
TaskTimerListener.timerListeners.put(subproject.name, listener)
|
||||
subproject.gradle.addListener(listener)
|
||||
}
|
||||
|
||||
@@ -220,8 +220,8 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
|
||||
it.doLast {
|
||||
val applicationName = benchmark.applicationName
|
||||
val benchContents = buildDir.resolve(nativeBenchResults).readText()
|
||||
val nativeCompileTime = if (benchmark.compileTasks.isEmpty()) getNativeCompileTime(applicationName)
|
||||
else getNativeCompileTime(applicationName, benchmark.compileTasks)
|
||||
val nativeCompileTime = if (benchmark.compileTasks.isEmpty()) getNativeCompileTime(project, applicationName)
|
||||
else getNativeCompileTime(project, applicationName, benchmark.compileTasks)
|
||||
|
||||
val properties = commonBenchmarkProperties + mapOf(
|
||||
"type" to "native",
|
||||
|
||||
+1
@@ -85,6 +85,7 @@ open class CompileBenchmarkingPlugin : Plugin<Project> {
|
||||
|
||||
doLast {
|
||||
val nativeCompileTime = getCompileBenchmarkTime(
|
||||
project,
|
||||
applicationName,
|
||||
buildSteps.names,
|
||||
repeatNumber,
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ open class KotlinNativeBenchmarkingPlugin: BenchmarkingPlugin() {
|
||||
it.doLast {
|
||||
val applicationName = benchmark.applicationName
|
||||
val jarPath = (tasks.getByName("jvmJar") as Jar).archiveFile.get().asFile
|
||||
val jvmCompileTime = getJvmCompileTime(applicationName)
|
||||
val jvmCompileTime = getJvmCompileTime(project, applicationName)
|
||||
val benchContents = buildDir.resolve(jvmBenchResults).readText()
|
||||
|
||||
val properties: Map<String, Any> = commonBenchmarkProperties + mapOf(
|
||||
|
||||
@@ -91,7 +91,7 @@ task konanJsonReport {
|
||||
def frameworkPath = kotlin.macosX64("macos").binaries.
|
||||
getFramework(frameworkName, kotlin.macosX64("macos").binaries.DEBUG).outputFile.absolutePath
|
||||
def nativeExecutable = new File("$frameworkPath/$frameworkName").canonicalPath
|
||||
def nativeCompileTime = MPPTools.getNativeCompileTime(applicationName, ['compileKotlinMacos',
|
||||
def nativeCompileTime = MPPTools.getNativeCompileTime(project, applicationName, ['compileKotlinMacos',
|
||||
'linkBenchmarksAnalyzerDebugFrameworkMacos',
|
||||
'cinteropLibcurlMacos'])
|
||||
def properties = getCommonProperties() + ['type' : 'native',
|
||||
|
||||
Reference in New Issue
Block a user