Created
October 23, 2012 15:22
-
-
Save nikos/3939407 to your computer and use it in GitHub Desktop.
Measure time for the execution of each gradle task executed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TaskTimerListener implements TaskExecutionListener { | |
private Clock clock | |
@Override | |
void beforeExecute(Task task) { | |
clock = new org.gradle.util.Clock() | |
} | |
@Override | |
void afterExecute(Task task, TaskState taskState) { | |
task.project.logger.info "Execution of ${task.name} took ${clock.time}" | |
} | |
} | |
gradle.addListener new TaskTimerListener() |
You can add a command line flag and conditionally add the Listener. Example
./gradlew test -PtimeTest
Code example
I realize this is an old thread. I'm using a form of this, but I've noticed with multi-project builds, the Listener actually multiplies all tasks across all projects. Very strange.
@stewartbryson I'm seeing the same. Please share if you find a fix for this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now, how can do this optionally? I'd like to have timings show up when you add a task. example "./gradlew timing assembleDebug"