Add some gradle benchmarks
Adds tools/test_gradle_benchmarks.py which
outputs information about Gradle tasks duration
for Golem.
Adds an init-script which is used to override
Gradle-based benchmark project configuration
so that the desired versions of r8 and android
Gradle plugin is used.
Change-Id: I050671bd8f62820d8108eb53ef38407a3ac6462a
Bug: 77613196
diff --git a/third_party/benchmarks/init-script.gradle b/third_party/benchmarks/init-script.gradle
new file mode 100644
index 0000000..3434a4a
--- /dev/null
+++ b/third_party/benchmarks/init-script.gradle
@@ -0,0 +1,74 @@
+def r8RootDir = System.properties['r8.root.dir']
+
+allprojects {
+ buildscript {
+ repositories {
+ maven { url r8RootDir+ '/third_party/gradle-plugin' }
+ // We don't use 'google()' in order to support projects using gradle
+ // lower to 4.1 version.
+ maven { url 'https://maven.google.com' }
+ jcenter()
+ }
+ dependencies {
+ classpath files(r8RootDir + '/build/libs/r8.jar')
+ classpath 'com.android.tools.build:gradle:3.2.0-dev'
+ }
+ }
+ repositories {
+ maven { url r8RootDir+ '/third_party/gradle-plugin' }
+ maven { url 'https://maven.google.com' }
+ jcenter()
+ mavenCentral()
+ }
+}
+
+//
+// Dump detailed timings per subtask
+//
+import java.util.concurrent.TimeUnit;
+class TimingsListener implements TaskExecutionListener, BuildListener {
+ private long startTimeInNs;
+ private timings = []
+
+ @Override
+ void beforeExecute(Task task) {
+ startTimeInNs = System.nanoTime();
+ }
+
+ @Override
+ void afterExecute(Task task, TaskState taskState) {
+ def ms = TimeUnit.MILLISECONDS.convert(
+ System.nanoTime() - startTimeInNs, TimeUnit.NANOSECONDS);
+ timings.add([task.path,ms])
+ }
+
+ @Override
+ void buildStarted(Gradle gradle) {
+ }
+
+ @Override
+ void buildFinished(BuildResult result) {
+ def total=0
+ for (timing in timings) {
+ total += timing[1]
+ }
+
+ for (timing in timings) {
+ printf "BENCH,%s,%s\n", timing
+ }
+
+ printf "BENCH,totalGradleTasks,%s\n", total
+
+ }
+
+ @Override
+ void projectsEvaluated(Gradle gradle) {}
+
+ @Override
+ void projectsLoaded(Gradle gradle) {}
+
+ @Override
+ void settingsEvaluated(Settings settings) {}
+}
+
+gradle.addListener new TimingsListener()
\ No newline at end of file