当前位置:主页 > 资料 >

Tracing Gradle task execution
栏目分类:资料   发布日期:2018-08-02   浏览次数:

导读:本文为去找网小编(www.7zhao.net)为您推荐的Tracing Gradle task execution,希望对您有所帮助,谢谢! Gradle provides two built-in mechanisms for tracing your build: --profile and --scan . The former produces a simple H

本文为去找网小编(www.7zhao.net)为您推荐的Tracing Gradle task execution,希望对您有所帮助,谢谢!

欢迎访问www.7zhao.net



Gradle provides two built-in mechanisms for tracing your build: --profile and --scan . The former produces a simple HTML report of task execution times. You can get a rough idea of where time was spent but are unlikely to glean any real insights. The latter sends a detailed report to Gradle’s servers (or to a Gradle Enterprise installation) with much more granular information. Task details are rendered on a concurrent timeline corresponding to their execution. For CI builds, I tend to want something more granular than --profile but I don’t like the idea of sending details of every build to Gradle with --scan . It seems entirely needless considering their plugin has all of that information locally but chooses to render it remotely. www.7zhao.net

The project started a few years ago as a way to deterministically measure build speeds. By creating scenarios such as an ABI-breaking change, ABI-compatible change, Android resource change, etc., the tool can run these scenarios multiple times to first warm up the JVM and then to produce an accurate picture of what gets executed. It offers integrations and outputs for use with popular JVM-based performance analysis tools such as YourKit and Java Flight Recorder. 本文来自去找www.7zhao.net

For CI builds, executing through the Gradle profiler would be an annoying abstraction to use. We can instead use it for inspiration and run its integrations on individual builds.

欢迎访问www.7zhao.net

Java Flight Recorder can be used on individual Gradle builds with the jcmd binary in the JDK and with flags to java specified on the org.gradle.jvmargs in your gradle.properties . There are even which offer to start and stop the recording automatically. We can then open the resulting .jfr file in Java Mission Control or use to convert it into a . copyright www.7zhao.net

本文来自去找www.7zhao.net

The flamegraph can show where time is being spent inside of tasks over the course of the build. The stacks aren’t correlated to a task, though, so it’s important to remember that you’re looking at the larger picture. This also doesn’t handle tasks which communicate with their own daemons such as the Kotlin compiler. 本文来自去找www.7zhao.net

While this produces a pretty output, its utility is small and the Gradle plugin integration is not the most stable. I would refrain from using this on CI as result unless you’re going to build out a strong integration with jcmd directly. These visualizations work well when you have a small subset of tasks to run rather than when your entire project is being built. 内容来自www.7zhao.net

The Gradle profiler also includes support for . This output will be familiar to Android users who have used the . Again we can integrate this into our builds without jumping through the Gradle profiler. 欢迎访问www.7zhao.net

The code for producing a Chrome trace lives inside . Clone and build the project which will produce a jar at subprojects/chrome-trace/build/libs/chrome-trace.jar . Copy this jar into the gradle/ directory of your project. This jar contains a plugin which can be applied inside a Gradle initialization script. 本文来自去找www.7zhao.net

// init.gradle

initscript {
  dependencies {
    classpath files('gradle/chrome-trace.jar')
  }
}

rootProject {
  def date = new java.text.SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
  ext.chromeTraceFile = new File(rootProject.buildDir, "reports/trace/trace-${date}.html")
}

apply plugin: org.gradle.trace.GradleTracingPlugin copyright www.7zhao.net 

When invoking Gradle we need to reference this script and also pass a flag to enable the tracing.

copyright www.7zhao.net

$ ./gradlew --init-script init.gradle -Dtrace build 

欢迎访问www.7zhao.net

This will produce a trace file at build/reports/trace/trace-(date).html which you can open in Chrome and navigate using the arrow keys and A-S-D-W keys. 去找(www.7zhao.net欢迎您

欢迎访问www.7zhao.net

The trace gives a picture of concurrent task execution and timings therein. There is very little here that isn’t in the --profile report, but it’s presented in a manner that gives you more context. The most notable and welcome addition is that of CPU load, heap size, and GC events.

本文来自去找www.7zhao.net

Unfortunately, the granularity per-task is near zero. There are no insights into that operate as part of a task. We cannot get flame graphs of the call stacks inside of a task. 欢迎访问www.7zhao.net

I have added this to SDK Search’s CI builds in addition to the other reports it already generates if you’d like to see a full integration: .

本文来自去找www.7zhao.net

Neither is perfect but both can be useful in different situations. Hopefully in the future visibility into workers will be added to the Chrome trace. Figuring out how to merge the Java Flight Recorder data into the Chrome trace would also be an amazing addition. For now, having the Chrome trace run on CI gives a good picture of how the build is performing and then Java Flight Recorder can be used either manually or with the Gradle profiler to dig into individual task performance.

本文来自去找www.7zhao.net

Here are the four tracing outputs of a single build: 内容来自www.7zhao.net

www.7zhao.net


本文原文地址:http://jakewharton.com/tracing-gradle-task-execution/

以上为Tracing Gradle task execution文章的全部内容,若您也有好的文章,欢迎与我们分享!

内容来自www.7zhao.net

Copyright ©2008-2017去找网版权所有   皖ICP备12002049号-2 皖公网安备 34088102000435号   关于我们|联系我们| 免责声明|友情链接|网站地图|手机版