Last active
March 21, 2017 07:56
-
-
Save gitzxon/bd181ada71f7bb2f7b304a2387a85145 to your computer and use it in GitHub Desktop.
printing executed time of a task
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
// (1) put this snippet to the tail of app.gradle | |
// (2) ./gradlew assembleDebug | |
public class BuildTimeListener implements TaskExecutionListener, BuildListener { | |
private org.gradle.internal.time.Clock clock | |
private times = [] | |
@Override | |
void beforeExecute(Task task) { | |
clock = new org.gradle.internal.time.Clock() | |
} | |
@Override | |
void afterExecute(Task task, TaskState taskState) { | |
def ms = clock.getElapsedMillis() | |
times.add([ms, task.path]) | |
//task.project.logger.warn "${task.path} spend ${ms}ms" | |
} | |
@Override | |
void buildFinished(BuildResult result) { | |
println "Task spend time:" | |
for (time in times) { | |
if (time[0] >= 50) { | |
printf "%7sms %s\n", time | |
} | |
} | |
} | |
@Override | |
void buildStarted(Gradle gradle) {} | |
@Override | |
void projectsEvaluated(Gradle gradle) {} | |
@Override | |
void projectsLoaded(Gradle gradle) {} | |
@Override | |
void settingsEvaluated(Settings settings) {} | |
} | |
project.gradle.addListener(new BuildTimeListener()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment