1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Added --profiling.

This commit is contained in:
Cedric Beust 2016-07-24 22:39:43 -08:00
parent f8d2d0ed23
commit 888e5cde73
3 changed files with 17 additions and 5 deletions

View file

@ -65,6 +65,9 @@ class Args {
@Parameter(names = arrayOf("--profiles"), description = "Comma-separated list of profiles to run") @Parameter(names = arrayOf("--profiles"), description = "Comma-separated list of profiles to run")
var profiles: String? = null var profiles: String? = null
@Parameter(names = arrayOf("--profiling"), description = "Display task timings at the end of the build")
var profiling: Boolean = false
@Parameter(names = arrayOf("--resolve"), @Parameter(names = arrayOf("--resolve"),
description = "Resolve the given comma-separated dependencies and display their dependency tree") description = "Resolve the given comma-separated dependencies and display their dependency tree")
var dependencies: String? = null var dependencies: String? = null

View file

@ -62,7 +62,7 @@ class TaskManager @Inject constructor(val args: Args,
override fun toString() = id override fun toString() = id
} }
class RunTargetResult(val taskResult: TaskResult, val messages: List<String>) class RunTargetResult(val taskResult: TaskResult, val timings: List<ProfilerInfo>)
/** /**
* @return the list of tasks available for the given project. * @return the list of tasks available for the given project.
@ -124,10 +124,12 @@ class TaskManager @Inject constructor(val args: Args,
return if (result.any()) result.toList() else projects return if (result.any()) result.toList() else projects
} }
class ProfilerInfo(val taskName: String, val durationMillis: Long)
private fun runProjects(taskInfos: List<TaskInfo>, projects: List<Project>) : RunTargetResult { private fun runProjects(taskInfos: List<TaskInfo>, projects: List<Project>) : RunTargetResult {
var result = TaskResult() var result = TaskResult()
val failedProjects = hashSetOf<String>() val failedProjects = hashSetOf<String>()
val messages = Collections.synchronizedList(arrayListOf<String>()) val messages = Collections.synchronizedList(arrayListOf<ProfilerInfo>())
projects.forEach { project -> projects.forEach { project ->
AsciiArt.logBox("Building ${project.name}") AsciiArt.logBox("Building ${project.name}")
@ -532,7 +534,7 @@ class TaskManager @Inject constructor(val args: Args,
///// /////
} }
class TaskWorker(val tasks: List<ITask>, val dryRun: Boolean, val messages: MutableList<String>) class TaskWorker(val tasks: List<ITask>, val dryRun: Boolean, val timings: MutableList<TaskManager.ProfilerInfo>)
: IWorker<ITask> { : IWorker<ITask> {
override fun call() : TaskResult2<ITask> { override fun call() : TaskResult2<ITask> {
@ -550,7 +552,7 @@ class TaskWorker(val tasks: List<ITask>, val dryRun: Boolean, val messages: Muta
success = success and tr.success success = success and tr.success
if (tr.errorMessage != null) errorMessages.add(tr.errorMessage) if (tr.errorMessage != null) errorMessages.add(tr.errorMessage)
} }
messages.add("$name: $time ms") timings.add(TaskManager.ProfilerInfo(name, time.first))
} }
return TaskResult2(success, errorMessages.joinToString("\n"), tasks[0]) return TaskResult2(success, errorMessages.joinToString("\n"), tasks[0])
} }

View file

@ -213,7 +213,14 @@ private class Main @Inject constructor(
// Shutdown all plug-ins // Shutdown all plug-ins
plugins.shutdownPlugins() plugins.shutdownPlugins()
log(3, "Timings:\n " + runTargetResult.messages.joinToString("\n ")) if (args.profiling) {
log(1, "\nTIMINGS (SECONDS)")
log(1, "================\n")
runTargetResult.timings.sortedByDescending { it.durationMillis }.forEach {
log(1, String.format("%.2f", it.durationMillis.toDouble() / 1000) + " " + it.taskName)
}
log(1, "\n")
}
} }
} }
} }