java gradle execution_java-在gradle脚本中跟踪每个任务的执行时间?

简单的排序将使@jlevy的解决方案更好。

另外,对于典型的生产应用程序,我认为50ms的阈值太低。

我们通常关心耗时超过1秒的任务。

项目/ build.gradle

import java.util.concurrent.TimeUnit

// Log timings per task.

class TimingsListener implements TaskExecutionListener, BuildListener {

private long startTime

private timings = []

@Override

void beforeExecute(Task task) {

startTime = System.nanoTime()

}

@Override

void afterExecute(Task task, TaskState taskState) {

def ms = TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS)

timings.add(new Tuple2(ms, task.path))

task.project.logger.warn "${task.path} took ${ms}ms"

}

@Override

void buildFinished(BuildResult result) {

println "Task timings:"

def tmp = timings.toSorted(new Comparator>() {

@Override

int compare(Tuple2 o, Tuple2 t1) {

return o.first - t1.first

}

})

for (timing in tmp) {

if (timing.first >= 1000) {

printf "%ss %s\n", timing.first / 1000, timing.second

}

}

}

@Override

void buildStarted(Gradle gradle) {}

@Override

void projectsEvaluated(Gradle gradle) {}

@Override

void projectsLoaded(Gradle gradle) {}

@Override

void settingsEvaluated(Settings settings) {}

}

gradle.addListener new TimingsListener()

终端输出:

BUILD SUCCESSFUL in 14m 33s

948 actionable tasks: 419 executed, 476 from cache, 53 up-to-date

Task timings:

1.036s :cbl-config:mergeMyAppDebugResources

1.187s :express:bundleMyAppDebug

1.199s :country:testMyAppDebugUnitTest

1.214s :core-for-test:extractMyAppDebugAnnotations

1.242s :analytics:testMyAppDebugUnitTest

1.308s :express:extractMyAppDebugAnnotations

1.33s :availability:dataBindingExportBuildInfoMyAppDebug

1.357s :app:transformNativeLibsWithStripDebugSymbolForMyAppDebug

1.405s :hermes:generateMyAppDebugBuildConfig

1.56s :availability:testMyAppDebugUnitTest

1.65s :app:javaPreCompileMyAppDebugUnitTest

1.749s :chat:compileMyAppDebugJavaWithJavac

1.858s :cbl-config-for-test:compileMyAppDebugJavaWithJavac

2.027s :cbl-config:compileMyAppDebugJavaWithJavac

2.056s :analytics-for-test:compileMyAppDebugJavaWithJavac

2.447s :crypto:compileMyAppDebugJavaWithJavac

2.45s :crypto:testMyAppDebugUnitTest

2.47s :chat:javaPreCompileMyAppDebugUnitTest

2.639s :crypto-for-test:dataBindingExportBuildInfoMyAppDebug

2.683s :test-utils:compileMyAppDebugJavaWithJavac

3.056s :crypto:lintMyAppDebug

3.227s :app:transformNativeLibsWithMergeJniLibsForMyAppDebug

3.272s :express:testMyAppDebugUnitTest

3.394s :crypto:mergeMyAppDebugResources

3.426s :core:testMyAppDebugUnitTest

4.299s :multicity:testMyAppDebugUnitTest

4.333s :app:packageMyAppDebug

4.584s :availability-for-test:compileMyAppDebugJavaWithJavac

4.672s :app:transformResourcesWithMergeJavaResForMyAppDebug

4.786s :map:lintMyAppDebug

5.309s :country:lintMyAppDebug

5.332s :job:lintMyAppDebug

5.389s :map:testMyAppDebugUnitTest

6.04s :express:lintMyAppDebug

6.584s :hermes:lintMyAppDebug

6.707s :app:transformClassesWithMultidexlistForMyAppDebug

7.052s :multicity:lintMyAppDebug

8.044s :multicity:compileMyAppDebugJavaWithJavac

8.87s :app:transformDexArchiveWithDexMergerForMyAppDebug

9.371s :uikit:testMyAppDebugUnitTest

9.429s :availability:lintMyAppDebug

13.12s :app:compileMyAppDebugUnitTestKotlin

16.276s :hermes:testMyAppDebugUnitTest

16.898s :chat:testMyAppDebugUnitTest

17.174s :job:testMyAppDebugUnitTest

36.008s :grab-junior:testMyAppDebugUnitTest

96.88s :app:compileMyAppDebugJavaWithJavac

125.693s :app:lintMyAppDebug

145.538s :app:transformClassesWithDexBuilderForMyAppDebug

182.752s :app:testMyAppDebugUnitTest

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值