diff --git a/src/main/java/org/gradle/profiler/ScenarioLoader.java b/src/main/java/org/gradle/profiler/ScenarioLoader.java index b6f474a2..8cacf4af 100644 --- a/src/main/java/org/gradle/profiler/ScenarioLoader.java +++ b/src/main/java/org/gradle/profiler/ScenarioLoader.java @@ -17,8 +17,8 @@ import org.gradle.profiler.mutations.BuildMutatorConfigurator; import org.gradle.profiler.mutations.ClearArtifactTransformCacheMutator; import org.gradle.profiler.mutations.ClearBuildCacheMutator; +import org.gradle.profiler.mutations.ClearConfigurationCacheStateMutator; import org.gradle.profiler.mutations.ClearGradleUserHomeMutator; -import org.gradle.profiler.mutations.ClearInstantExecutionStateMutator; import org.gradle.profiler.mutations.ClearProjectCacheMutator; import org.gradle.profiler.mutations.FileChangeMutatorConfigurator; import org.gradle.profiler.mutations.GitCheckoutMutator; @@ -63,6 +63,7 @@ class ScenarioLoader { private static final String CLEAR_BUILD_CACHE_BEFORE = "clear-build-cache-before"; private static final String CLEAR_GRADLE_USER_HOME_BEFORE = "clear-gradle-user-home-before"; private static final String CLEAR_INSTANT_EXECUTION_STATE_BEFORE = "clear-instant-execution-state-before"; + private static final String CLEAR_CONFIGURATION_CACHE_STATE_BEFORE = "clear-configuration-cache-state-before"; private static final String CLEAR_PROJECT_CACHE_BEFORE = "clear-project-cache-before"; private static final String CLEAR_TRANSFORM_CACHE_BEFORE = "clear-transform-cache-before"; private static final String SHOW_BUILD_CACHE_SIZE = "show-build-cache-size"; @@ -98,6 +99,7 @@ class ScenarioLoader { CLEAR_BUILD_CACHE_BEFORE, CLEAR_GRADLE_USER_HOME_BEFORE, CLEAR_INSTANT_EXECUTION_STATE_BEFORE, + CLEAR_CONFIGURATION_CACHE_STATE_BEFORE, CLEAR_PROJECT_CACHE_BEFORE, CLEAR_TRANSFORM_CACHE_BEFORE, SHOW_BUILD_CACHE_SIZE, @@ -212,7 +214,8 @@ static List loadScenarios(File scenarioFile, InvocationSetti maybeAddMutator(scenario, scenarioName, settings.getProjectDir(), APPLY_H_SOURCE_CHANGE_TO, ApplyChangeToNativeSourceFileMutator.class, mutators); maybeAddMutator(scenario, scenarioName, settings.getProjectDir(), CLEAR_BUILD_CACHE_BEFORE, new ClearBuildCacheMutator.Configurator(settings.getGradleUserHome()), mutators); maybeAddMutator(scenario, scenarioName, settings.getProjectDir(), CLEAR_GRADLE_USER_HOME_BEFORE, new ClearGradleUserHomeMutator.Configurator(settings.getGradleUserHome()), mutators); - maybeAddMutator(scenario, scenarioName, settings.getProjectDir(), CLEAR_INSTANT_EXECUTION_STATE_BEFORE, new ClearInstantExecutionStateMutator.Configurator(), mutators); + maybeAddMutator(scenario, scenarioName, settings.getProjectDir(), CLEAR_INSTANT_EXECUTION_STATE_BEFORE, new ClearConfigurationCacheStateMutator.Configurator(), mutators); + maybeAddMutator(scenario, scenarioName, settings.getProjectDir(), CLEAR_CONFIGURATION_CACHE_STATE_BEFORE, new ClearConfigurationCacheStateMutator.Configurator(), mutators); maybeAddMutator(scenario, scenarioName, settings.getProjectDir(), CLEAR_PROJECT_CACHE_BEFORE, new ClearProjectCacheMutator.Configurator(), mutators); maybeAddMutator(scenario, scenarioName, settings.getProjectDir(), CLEAR_TRANSFORM_CACHE_BEFORE, new ClearArtifactTransformCacheMutator.Configurator(settings.getGradleUserHome()), mutators); maybeAddMutator(scenario, scenarioName, settings.getProjectDir(), SHOW_BUILD_CACHE_SIZE, new ShowBuildCacheSizeMutator.Configurator(settings.getGradleUserHome()), mutators); diff --git a/src/main/java/org/gradle/profiler/mutations/ClearInstantExecutionStateMutator.java b/src/main/java/org/gradle/profiler/mutations/ClearConfigurationCacheStateMutator.java similarity index 58% rename from src/main/java/org/gradle/profiler/mutations/ClearInstantExecutionStateMutator.java rename to src/main/java/org/gradle/profiler/mutations/ClearConfigurationCacheStateMutator.java index cc164066..d00f3645 100644 --- a/src/main/java/org/gradle/profiler/mutations/ClearInstantExecutionStateMutator.java +++ b/src/main/java/org/gradle/profiler/mutations/ClearConfigurationCacheStateMutator.java @@ -8,20 +8,24 @@ import java.io.IOException; import java.io.UncheckedIOException; -public class ClearInstantExecutionStateMutator extends AbstractCleanupMutator { +public class ClearConfigurationCacheStateMutator extends AbstractCleanupMutator { private final File projectDir; - public ClearInstantExecutionStateMutator(File projectDir, CleanupSchedule schedule) { + public ClearConfigurationCacheStateMutator(File projectDir, CleanupSchedule schedule) { super(schedule); this.projectDir = projectDir; } @Override protected void cleanup() { - File gradleCache = new File(projectDir, ".instant-execution-state"); - System.out.println(String.format("> Cleaning instant execution state: %s", gradleCache)); + System.out.println("> Cleaning configuration cache state"); + cleanup(new File(projectDir, ".gradle/configuration-cache")); + cleanup(new File(projectDir, ".instant-execution-state")); + } + + private void cleanup(File dir) { try { - FileUtils.deleteDirectory(gradleCache); + FileUtils.deleteDirectory(dir); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -30,7 +34,7 @@ protected void cleanup() { public static class Configurator extends AbstractCleanupMutator.Configurator { @Override protected BuildMutator newInstance(Config scenario, String scenarioName, File projectDir, String key, CleanupSchedule schedule) { - return new ClearInstantExecutionStateMutator(projectDir, schedule); + return new ClearConfigurationCacheStateMutator(projectDir, schedule); } } } diff --git a/src/test/groovy/org/gradle/profiler/AbstractProfilerIntegrationTest.groovy b/src/test/groovy/org/gradle/profiler/AbstractProfilerIntegrationTest.groovy index cc1d6a62..325ba891 100644 --- a/src/test/groovy/org/gradle/profiler/AbstractProfilerIntegrationTest.groovy +++ b/src/test/groovy/org/gradle/profiler/AbstractProfilerIntegrationTest.groovy @@ -16,7 +16,7 @@ abstract class AbstractProfilerIntegrationTest extends Specification { "3.3", "3.4.1", "3.5", "4.0", "4.1", "4.2.1", "4.7", "5.2.1", "5.5.1", "5.6.3", - "6.0.1", "6.1" + "6.0.1", "6.1", "6.5-rc-1" ] @Shared String minimalSupportedGradleVersion = supportedGradleVersions.first() diff --git a/src/test/groovy/org/gradle/profiler/BuildOperationInstrumentationIntegrationTest.groovy b/src/test/groovy/org/gradle/profiler/BuildOperationInstrumentationIntegrationTest.groovy index a13f24fa..078ad4dd 100644 --- a/src/test/groovy/org/gradle/profiler/BuildOperationInstrumentationIntegrationTest.groovy +++ b/src/test/groovy/org/gradle/profiler/BuildOperationInstrumentationIntegrationTest.groovy @@ -9,7 +9,7 @@ import static org.junit.Assert.assertTrue class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerIntegrationTest { @Unroll - def "can benchmark configuration time for build using #gradleVersion (instant-execution: #instantExecution)"() { + def "can benchmark configuration time for build using #gradleVersion (configuration-cache: #configurationCache)"() { given: instrumentedBuildScript() @@ -22,8 +22,10 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg "--measure-config-time", "assemble" ] - if (instantExecution) { - args += "-Dorg.gradle.unsafe.instant-execution=true" + if (configurationCache) { + file("gradle.properties") << """ + org.gradle.unsafe.configuration-cache=on + """ } when: @@ -50,14 +52,14 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg Long.valueOf(taskStart[0][1]) > 0 where: - [gradleVersion, instantExecution] << [ - ["6.1-milestone-3", latestSupportedGradleVersion] as Set, // simplify this once the latest version is > 6.1-milestone-3 - [true, false] - ].combinations() + gradleVersion | configurationCache + "6.1" | false + latestSupportedGradleVersion | false + latestSupportedGradleVersion | true } @Unroll - def "can benchmark snapshotting build operation time via #via for build using #gradleVersion (instant-execution: #instantExecution)"() { + def "can benchmark snapshotting build operation time via #via for build using #gradleVersion (configuration-cache: #configurationCache)"() { given: instrumentedBuildForSnapshottingBenchmark() @@ -79,8 +81,10 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg args += ["--scenario-file", scenarioFile.absolutePath] } args += commandLine - if (instantExecution) { - args += "-Dorg.gradle.unsafe.instant-execution=true" + if (configurationCache) { + file("gradle.properties") << """ + org.gradle.unsafe.configuration-cache=on + """ } args += scenarioConfiguration ? "default" : "assemble" @@ -107,7 +111,7 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg lines.get(26).matches("stddev,\\d+\\.\\d+,\\d+\\.\\d+") where: - [via, commandLine, scenarioConfiguration, gradleVersion, instantExecution] << [ + [via, commandLine, scenarioConfiguration, gradleVersion, configurationCache] << [ [ [ 'command line', @@ -125,7 +129,7 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg 'measured-build-ops = ["org.gradle.api.internal.tasks.SnapshotTaskInputsBuildOperationType"]' ] ], - ["6.1-milestone-3", latestSupportedGradleVersion] as Set + ["6.1", latestSupportedGradleVersion] as Set ].combinations().collectMany { def scenario = it[0] def gradleVersion = it[1] @@ -138,7 +142,7 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg } @Unroll - def "can combine measuring configuration time and build operation using #gradleVersion (instant-execution: #instantExecution)"() { + def "can combine measuring configuration time and build operation using #gradleVersion (configuration-cache: #configurationCache)"() { given: instrumentedBuildForSnapshottingBenchmark() @@ -152,8 +156,10 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg "--measure-build-op", "org.gradle.api.internal.tasks.SnapshotTaskInputsBuildOperationType", "assemble" ] - if (instantExecution) { - args += "-Dorg.gradle.unsafe.instant-execution=true" + if (configurationCache) { + file("gradle.properties") << """ + org.gradle.unsafe.configuration-cache=on + """ } when: @@ -187,9 +193,10 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg assertTrue("different build-op times", buildOps.size() > 1) where: - gradleVersion | instantExecution - "6.1-milestone-3" | false - "6.1-milestone-3" | true + gradleVersion | configurationCache + "6.1" | false + latestSupportedGradleVersion | false + latestSupportedGradleVersion | true } private void instrumentedBuildForSnapshottingBenchmark() { @@ -229,7 +236,7 @@ class BuildOperationInstrumentationIntegrationTest extends AbstractProfilerInteg instrumentedBuildScript() def scenarioFile = file("performance.scenarios") scenarioFile.text = """ - assemble { + assemble { versions = ["${minimalSupportedGradleVersion}", "4.0", "4.10", "6.0", "${latestSupportedGradleVersion}"] } """ diff --git a/subprojects/build-operations/src/main/java/org/gradle/trace/pid/PidCollector.java b/subprojects/build-operations/src/main/java/org/gradle/trace/pid/PidCollector.java index 2b91d37d..4e5e70a6 100644 --- a/subprojects/build-operations/src/main/java/org/gradle/trace/pid/PidCollector.java +++ b/subprojects/build-operations/src/main/java/org/gradle/trace/pid/PidCollector.java @@ -1,10 +1,8 @@ package org.gradle.trace.pid; -import org.gradle.BuildAdapter; -import org.gradle.BuildResult; import org.gradle.api.internal.GradleInternal; import org.gradle.internal.nativeintegration.ProcessEnvironment; -import org.gradle.trace.stream.AsyncWriter; +import org.gradle.util.GFileUtils; import java.io.File; @@ -12,14 +10,6 @@ public class PidCollector { public static void collect(GradleInternal gradle, File outFile) { ProcessEnvironment processEnvironment = gradle.getServices().get(ProcessEnvironment.class); - AsyncWriter writer = new AsyncWriter<>(outFile, (l, w) -> w.print(l)); - writer.append(processEnvironment.getPid()); - writer.finished(); - gradle.addBuildListener(new BuildAdapter(){ - @Override - public void buildFinished(BuildResult result) { - writer.stop(); - } - }); + GFileUtils.writeFile(processEnvironment.getPid().toString(), outFile); } }