mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Display task timings in --log 2.
This commit is contained in:
parent
82d6faa54f
commit
0e90561c8f
2 changed files with 27 additions and 16 deletions
|
@ -7,6 +7,7 @@ import com.beust.kobalt.api.PluginTask
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.annotation.IncrementalTask
|
import com.beust.kobalt.api.annotation.IncrementalTask
|
||||||
import com.beust.kobalt.api.annotation.Task
|
import com.beust.kobalt.api.annotation.Task
|
||||||
|
import com.beust.kobalt.misc.benchmarkMillis
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.google.common.collect.ArrayListMultimap
|
import com.google.common.collect.ArrayListMultimap
|
||||||
import com.google.common.collect.Multimap
|
import com.google.common.collect.Multimap
|
||||||
|
@ -46,8 +47,11 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana
|
||||||
fun matches(projectName: String) = project == null || project == projectName
|
fun matches(projectName: String) = project == null || project == projectName
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun runTargets(taskNames: List<String>, projects: List<Project>) : Int {
|
class RunTargetResult(val exitCode: Int, val messages: List<String>)
|
||||||
|
|
||||||
|
public fun runTargets(taskNames: List<String>, projects: List<Project>) : RunTargetResult {
|
||||||
var result = 0
|
var result = 0
|
||||||
|
val messages = Collections.synchronizedList(arrayListOf<String>())
|
||||||
projects.forEach { project ->
|
projects.forEach { project ->
|
||||||
val projectName = project.name
|
val projectName = project.name
|
||||||
// There can be multiple tasks by the same name (e.g. PackagingPlugin and AndroidPlugin both
|
// There can be multiple tasks by the same name (e.g. PackagingPlugin and AndroidPlugin both
|
||||||
|
@ -139,9 +143,13 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana
|
||||||
|
|
||||||
val factory = object : IThreadWorkerFactory<PluginTask> {
|
val factory = object : IThreadWorkerFactory<PluginTask> {
|
||||||
override public fun createWorkers(nodes: List<PluginTask>): List<IWorker<PluginTask>> {
|
override public fun createWorkers(nodes: List<PluginTask>): List<IWorker<PluginTask>> {
|
||||||
|
// val tr = nodes.reduce { workers: List<TaskWorker>, node: PluginTask ->
|
||||||
|
// val result: List<TaskWorker> = workers + TaskWorker(listOf(node), args.dryRun, messages)
|
||||||
|
// result
|
||||||
|
// }
|
||||||
val thisResult = arrayListOf<IWorker<PluginTask>>()
|
val thisResult = arrayListOf<IWorker<PluginTask>>()
|
||||||
nodes.forEach {
|
nodes.forEach {
|
||||||
thisResult.add(TaskWorker(arrayListOf(it), args.dryRun))
|
thisResult.add(TaskWorker(listOf(it), args.dryRun, messages))
|
||||||
}
|
}
|
||||||
return thisResult
|
return thisResult
|
||||||
}
|
}
|
||||||
|
@ -154,7 +162,7 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return result
|
return RunTargetResult(result, messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -205,7 +213,7 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana
|
||||||
dependencyNames.forEach {
|
dependencyNames.forEach {
|
||||||
newToProcess.add(TaskInfo(project.name, it))
|
newToProcess.add(TaskInfo(project.name, it))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log(1, "Couldn't find task ${currentTask.taskName}: not applicable to project ${project.name}")
|
log(1, "Couldn't find task ${currentTask.taskName}: not applicable to project ${project.name}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,15 +327,12 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
// Manage the tasks
|
||||||
/////
|
/////
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TaskWorker(val tasks: List<PluginTask>, val dryRun: Boolean) : IWorker<PluginTask> {
|
class TaskWorker(val tasks: List<PluginTask>, val dryRun: Boolean, val messages: MutableList<String>)
|
||||||
// override fun compareTo(other: IWorker2<PluginTask>): Int {
|
: IWorker<PluginTask> {
|
||||||
// return priority.compareTo(other.priority)
|
|
||||||
// }
|
|
||||||
|
|
||||||
override fun call() : TaskResult2<PluginTask> {
|
override fun call() : TaskResult2<PluginTask> {
|
||||||
if (tasks.size > 0) {
|
if (tasks.size > 0) {
|
||||||
|
@ -338,9 +343,13 @@ class TaskWorker(val tasks: List<PluginTask>, val dryRun: Boolean) : IWorker<Plu
|
||||||
var success = true
|
var success = true
|
||||||
val errorMessages = arrayListOf<String>()
|
val errorMessages = arrayListOf<String>()
|
||||||
tasks.forEach {
|
tasks.forEach {
|
||||||
val tr = if (dryRun) TaskResult() else it.call()
|
val name = it.project.name + ":" + it.name
|
||||||
success = success and tr.success
|
val time = benchmarkMillis {
|
||||||
if (tr.errorMessage != null) errorMessages.add(tr.errorMessage)
|
val tr = if (dryRun) TaskResult() else it.call()
|
||||||
|
success = success and tr.success
|
||||||
|
if (tr.errorMessage != null) errorMessages.add(tr.errorMessage)
|
||||||
|
}
|
||||||
|
messages.add("$name: $time ms")
|
||||||
}
|
}
|
||||||
return TaskResult2(success, errorMessages.joinToString("\n"), tasks[0])
|
return TaskResult2(success, errorMessages.joinToString("\n"), tasks[0])
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ private class Main @Inject constructor(
|
||||||
|
|
||||||
var result = 0
|
var result = 0
|
||||||
val latestVersionFuture = github.latestKobaltVersion
|
val latestVersionFuture = github.latestKobaltVersion
|
||||||
val seconds = benchmark {
|
val seconds = benchmarkSeconds {
|
||||||
try {
|
try {
|
||||||
result = runWithArgs(jc, args, argv)
|
result = runWithArgs(jc, args, argv)
|
||||||
} catch(ex: KobaltException) {
|
} catch(ex: KobaltException) {
|
||||||
|
@ -195,10 +195,12 @@ private class Main @Inject constructor(
|
||||||
//
|
//
|
||||||
// Launch the build
|
// Launch the build
|
||||||
//
|
//
|
||||||
val thisResult = taskManager.runTargets(args.targets, allProjects)
|
val runTargetResult = taskManager.runTargets(args.targets, allProjects)
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
result = thisResult
|
result = runTargetResult.exitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log(2, "Timings:\n " + runTargetResult.messages.joinToString("\n "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue