Skip to content

Commit

Permalink
Merge pull request #206 from gradle/eskatos/cc/update
Browse files Browse the repository at this point in the history
Update the gradle-profiler for Gradle 6.5-rc-1 and the configuration cache
  • Loading branch information
eskatos authored May 28, 2020
2 parents 96093df + 7382390 commit 1ca367c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 40 deletions.
7 changes: 5 additions & 2 deletions src/main/java/org/gradle/profiler/ScenarioLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -212,7 +214,8 @@ static List<ScenarioDefinition> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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:
Expand All @@ -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()

Expand All @@ -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"

Expand All @@ -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',
Expand All @@ -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]
Expand All @@ -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()

Expand All @@ -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:
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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}"]
}
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
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;

@SuppressWarnings("unused")
public class PidCollector {
public static void collect(GradleInternal gradle, File outFile) {
ProcessEnvironment processEnvironment = gradle.getServices().get(ProcessEnvironment.class);
AsyncWriter<Long> 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);
}
}

0 comments on commit 1ca367c

Please sign in to comment.