Skip to content

Commit

Permalink
Merge pull request #274 from gradle/lptr/disallow-cleanup-actions-wit…
Browse files Browse the repository at this point in the history
…h-warm-daemon
  • Loading branch information
lptr authored Sep 29, 2020
2 parents c9dc1c2 + edc695c commit e0cfe31
Show file tree
Hide file tree
Showing 37 changed files with 288 additions and 233 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ insert_final_newline = true
# Markdown files sometimes need trailing whitespaces.
[*.md]
trim_trailing_whitespace = false

[*.json]
indent_size = 2
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

public class AdhocGradleScenarioDefinition extends GradleScenarioDefinition {
public AdhocGradleScenarioDefinition(
GradleBuildConfiguration version,
GradleBuildInvoker invoker,
BuildAction buildAction,
Map<String, String> systemProperties,
Supplier<BuildMutator> buildMutator,
int warmUpCount,
int buildCount,
File outputDir,
Expand All @@ -27,7 +25,7 @@ public AdhocGradleScenarioDefinition(
BuildAction.NO_OP,
Collections.emptyList(),
systemProperties,
buildMutator,
Collections.emptyList(),
warmUpCount,
buildCount,
outputDir,
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/gradle/profiler/BazelScenarioDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
import javax.annotation.Nullable;
import java.io.File;
import java.util.List;
import java.util.function.Supplier;

public class BazelScenarioDefinition extends BuildToolCommandLineScenarioDefinition {
public BazelScenarioDefinition(
String scenarioName,
@Nullable String title,
List<String> targets,
Supplier<BuildMutator> buildMutator,
List<BuildMutator> buildMutators,
int warmUpCount,
int buildCount,
File outputDir,
@Nullable File bazelHome
) {
super(scenarioName, title, targets, buildMutator, warmUpCount, buildCount, outputDir, bazelHome);
super(scenarioName, title, targets, buildMutators, warmUpCount, buildCount, outputDir, bazelHome);
}

@Override
Expand All @@ -34,6 +33,11 @@ public String getBuildToolDisplayName() {
return "bazel";
}

@Override
public BuildInvoker getInvoker() {
return BuildInvoker.Bazel;
}

@Override
protected String getExecutableName() {
if (OperatingSystem.isWindows()) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/gradle/profiler/BuckScenarioDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.File;
import java.io.PrintStream;
import java.util.List;
import java.util.function.Supplier;

public class BuckScenarioDefinition extends BuildToolCommandLineScenarioDefinition {
private final String type;
Expand All @@ -14,13 +13,13 @@ public BuckScenarioDefinition(
@Nullable String title,
List<String> targets,
String type,
Supplier<BuildMutator> buildMutator,
List<BuildMutator> buildMutators,
int warmUpCount,
int buildCount,
File outputDir,
@Nullable File buckHome
) {
super(scenarioName, title, targets, buildMutator, warmUpCount, buildCount, outputDir, buckHome);
super(scenarioName, title, targets, buildMutators, warmUpCount, buildCount, outputDir, buckHome);
this.type = type;
}

Expand All @@ -43,6 +42,11 @@ public String getType() {
return type;
}

@Override
public BuildInvoker getInvoker() {
return BuildInvoker.Buck;
}

@Override
protected void printDetail(PrintStream out) {
out.println(" Targets: " + getTargets());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/gradle/profiler/BuildInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public int benchmarkWarmUps() {
public int profileWarmUps() {
return 2;
}

public boolean allowsCleanupBetweenBuilds() {
return true;
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/gradle/profiler/BuildMutator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package org.gradle.profiler;

public interface BuildMutator {
/**
* Validates if the mutator works with the given invoker.
*/
default void validate(BuildInvoker invoker) {}

/**
* Runs before the first iteration of the scenario.
*/
Expand Down
35 changes: 0 additions & 35 deletions src/main/java/org/gradle/profiler/BuildMutatorFactory.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class BuildToolCommandLineInvoker<T extends BuildToolCommandLine
void doRun(T scenario, InvocationSettings settings, Consumer<BuildInvocationResult> resultConsumer, List<String> commandLine) {
ScenarioContext scenarioContext = ScenarioContext.from(settings, scenario);

BuildMutator mutator = scenario.getBuildMutator().get();
BuildMutator mutator = new CompositeBuildMutator(scenario.getBuildMutators());
mutator.beforeScenario(scenarioContext);
try {
for (int iteration = 1; iteration <= scenario.getWarmUpCount(); iteration++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.File;
import java.io.PrintStream;
import java.util.List;
import java.util.function.Supplier;

public abstract class BuildToolCommandLineScenarioDefinition extends ScenarioDefinition {
private final List<String> targets;
Expand All @@ -14,13 +13,13 @@ public BuildToolCommandLineScenarioDefinition(
String name,
@Nullable String title,
List<String> targets,
Supplier<BuildMutator> buildMutator,
List<BuildMutator> buildMutators,
int warmUpCount,
int buildCount,
File outputDir,
@Nullable File toolHome
) {
super(name, title, buildMutator, warmUpCount, buildCount, outputDir);
super(name, title, buildMutators, warmUpCount, buildCount, outputDir);
this.targets = targets;
this.toolHome = toolHome;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/gradle/profiler/GradleBuildInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ private GradleBuildInvoker(GradleClientSpec client, GradleDaemonReuse daemonReus
this.daemonReuse = daemonReuse;
}

@Override
public boolean allowsCleanupBetweenBuilds() {
// Warm daemons keep caches open and thus they cannot be removed
return !isReuseDaemon();
}

@Override
public String toString() {
if (daemonReuse == GradleDaemonReuse.ColdDaemonOnly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class GradleScenarioDefinition extends ScenarioDefinition {
Expand All @@ -31,14 +30,14 @@ public GradleScenarioDefinition(
BuildAction cleanupAction,
List<String> gradleArgs,
Map<String, String> systemProperties,
Supplier<BuildMutator> buildMutator,
List<BuildMutator> buildMutators,
int warmUpCount,
int buildCount,
File outputDir,
List<String> jvmArgs,
List<String> measuredBuildOperations
) {
super(name, title, buildMutator, warmUpCount, buildCount, outputDir);
super(name, title, buildMutators, warmUpCount, buildCount, outputDir);
this.invoker = invoker;
this.buildAction = buildAction;
this.buildConfiguration = buildConfiguration;
Expand Down Expand Up @@ -77,6 +76,7 @@ public List<String> getGradleArgs() {
return gradleArgs;
}

@Override
public GradleBuildInvoker getInvoker() {
return invoker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void doRun(GradleScenarioDefinition scenario, InvocationSettings settings

daemonControl.stop(buildConfiguration);

BuildMutator mutator = scenario.getBuildMutator().get();
BuildMutator mutator = new CompositeBuildMutator(scenario.getBuildMutators());
ScenarioContext scenarioContext = ScenarioContext.from(settings, scenario);
GradleClient gradleClient = scenario.getInvoker().getClient().create(buildConfiguration, settings);
try {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/gradle/profiler/MavenScenarioDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
import javax.annotation.Nullable;
import java.io.File;
import java.util.List;
import java.util.function.Supplier;

public class MavenScenarioDefinition extends BuildToolCommandLineScenarioDefinition {
public MavenScenarioDefinition(
String scenarioName,
@Nullable String title,
List<String> targets,
Supplier<BuildMutator> buildMutator,
List<BuildMutator> buildMutators,
int warmUpCount,
int buildCount,
File outputDir,
@Nullable File mavenHome
) {
super(scenarioName, title, targets, buildMutator, warmUpCount, buildCount, outputDir, mavenHome);
super(scenarioName, title, targets, buildMutators, warmUpCount, buildCount, outputDir, mavenHome);
}

@Override
Expand All @@ -34,6 +33,11 @@ public String getBuildToolDisplayName() {
return "maven";
}

@Override
public BuildInvoker getInvoker() {
return BuildInvoker.Maven;
}

@Override
protected String getExecutableName() {
if (OperatingSystem.isWindows()) {
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/org/gradle/profiler/ScenarioDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,43 @@
import javax.annotation.Nullable;
import java.io.File;
import java.io.PrintStream;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;

public abstract class ScenarioDefinition {
private final String name;
private final String title;
private final Supplier<BuildMutator> buildMutator;
private final List<BuildMutator> buildMutators;
private final int warmUpCount;
private final int buildCount;
private final File outputDir;


public ScenarioDefinition(
String name,
@Nullable String title,
Supplier<BuildMutator> buildMutator,
List<BuildMutator> buildMutators,
int warmUpCount,
int buildCount,
File outputDir
) {
this.name = name;
this.title = title;
this.buildMutator = buildMutator;
this.buildMutators = buildMutators;
this.warmUpCount = warmUpCount;
this.buildCount = buildCount;
this.outputDir = outputDir;
}

public void validate() {
for (BuildMutator buildMutator : buildMutators) {
try {
buildMutator.validate(getInvoker());
} catch (Exception ex) {
throw new IllegalStateException("Scenario '" + getTitle() + "' is invalid: " + ex.getMessage(), ex);
}
}
}

/**
* A specific title defined for the scenario to be used in reports (defaults to {@link #getName()}.
*/
Expand Down Expand Up @@ -58,6 +67,8 @@ public String getTitle() {
*/
public abstract String getTasksDisplayName();

public abstract BuildInvoker getInvoker();

public String getName() {
return name;
}
Expand All @@ -66,8 +77,8 @@ public File getOutputDir() {
return outputDir;
}

public Supplier<BuildMutator> getBuildMutator() {
return buildMutator;
public List<BuildMutator> getBuildMutators() {
return buildMutators;
}

public int getWarmUpCount() {
Expand All @@ -81,7 +92,7 @@ public int getBuildCount() {
public void printTo(PrintStream out) {
out.println("Scenario: " + getDisplayName());
printDetail(out);
out.println(" Build changes: " + getBuildMutator());
out.println(" Build changes: " + getBuildMutators());
out.println(" Warm-ups: " + getWarmUpCount());
out.println(" Builds: " + getBuildCount());
}
Expand Down
Loading

0 comments on commit e0cfe31

Please sign in to comment.