Skip to content

Instantly share code, notes, and snippets.

@nikos
Created October 23, 2012 15:22
Show Gist options
  • Save nikos/3939407 to your computer and use it in GitHub Desktop.
Save nikos/3939407 to your computer and use it in GitHub Desktop.
Measure time for the execution of each gradle task executed
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()
@milkrun
Copy link

milkrun commented Apr 20, 2015

Now, how can do this optionally? I'd like to have timings show up when you add a task. example "./gradlew timing assembleDebug"

@Scuilion
Copy link

You can add a command line flag and conditionally add the Listener. Example
./gradlew test -PtimeTest
Code example

@stewartbryson
Copy link

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.

@julioz
Copy link

julioz commented Apr 17, 2017

@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