Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
package and name rearrangement
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalcolea committed Sep 24, 2018
1 parent 741d22f commit af839b3
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import nebula.plugin.metrics.model.GradleToolContainer;
import nebula.plugin.metrics.model.Info;
import nebula.plugin.metrics.model.Result;
import nebula.plugin.metrics.model.profile.BuildProfile;
import nebula.plugin.metrics.model.profile.CompositeOperation;
import nebula.plugin.metrics.model.profile.ContinuousOperation;
import nebula.plugin.metrics.model.profile.ProjectProfile;
import nebula.plugin.metrics.model.profile.TaskExecution;
import nebula.plugin.metrics.model.BuildMetrics;
import nebula.plugin.metrics.model.CompositeOperation;
import nebula.plugin.metrics.model.ContinuousOperation;
import nebula.plugin.metrics.model.ProjectMetrics;
import nebula.plugin.metrics.model.TaskExecution;
import nebula.plugin.metrics.time.BuildStartedTime;
import nebula.plugin.metrics.time.Clock;
import org.gradle.BuildListener;
Expand Down Expand Up @@ -59,7 +59,7 @@
import static com.google.common.base.Preconditions.checkState;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCauseMessage;

public final class GradleBuildMetricsCollector implements BuildListener, ProjectEvaluationListener, TaskExecutionListener, DependencyResolutionListener, BuildCompletionListener {
public final class GradleBuildMetricsCollector implements BuildListener, ProjectEvaluationListener, TaskExecutionListener, DependencyResolutionListener, BuildCompletionListener {

private static final long TIMEOUT_MS = 5000;

Expand All @@ -80,7 +80,7 @@ public GradleBuildMetricsCollector(Supplier<MetricsDispatcher> dispatcherSupplie

private final BuildStartedTime buildStartedTime;
private final Clock clock;
private BuildProfile buildProfile;
private BuildMetrics buildMetrics;

/**
* This method is called explicity from projectsEvaluated.
Expand All @@ -92,31 +92,31 @@ public GradleBuildMetricsCollector(Supplier<MetricsDispatcher> dispatcherSupplie
public void buildStarted(Gradle gradle) {
checkNotNull(gradle);
long now = clock.getCurrentTime();
buildProfile = new BuildProfile(gradle.getStartParameter());
buildProfile.setBuildStarted(now);
buildProfile.setProfilingStarted(buildStartedTime.getStartTime());
buildMetrics = new BuildMetrics(gradle.getStartParameter());
buildMetrics.setBuildStarted(now);
buildMetrics.setProfilingStarted(buildStartedTime.getStartTime());
}

@Override
public void settingsEvaluated(Settings settings) {
checkNotNull(settings);
buildProfile.setSettingsEvaluated(clock.getCurrentTime());
buildMetrics.setSettingsEvaluated(clock.getCurrentTime());
}

@Override
public void projectsLoaded(Gradle gradle) {
checkNotNull(gradle);
buildProfile.setProjectsLoaded(clock.getCurrentTime());
buildMetrics.setProjectsLoaded(clock.getCurrentTime());
}

@Override
public void completed() {
if (buildProfile != null) {
buildProfile.setBuildFinished(clock.getCurrentTime());
if (buildMetrics != null) {
buildMetrics.setBuildFinished(clock.getCurrentTime());
try {
buildFinished(buildProfile);
buildFinished(buildMetrics);
} finally {
buildProfile = null;
buildMetrics = null;
}
}
}
Expand All @@ -125,54 +125,58 @@ public void completed() {
@Override
public void beforeEvaluate(Project project) {
long now = clock.getCurrentTime();
buildProfile.getProjectProfile(project.getPath()).getConfigurationOperation().setStart(now);
buildMetrics.getProjectProfile(project.getPath()).getConfigurationOperation().setStart(now);
}

@Override
public void afterEvaluate(Project project, ProjectState state) {
long now = clock.getCurrentTime();
ProjectProfile projectProfile = buildProfile.getProjectProfile(project.getPath());
projectProfile.getConfigurationOperation().setFinish(now);
ProjectMetrics projectMetrics = buildMetrics.getProjectProfile(project.getPath());
projectMetrics.getConfigurationOperation().setFinish(now);
}

// TaskExecutionListener
@Override
public void beforeExecute(Task task) {
long now = clock.getCurrentTime();
Project project = task.getProject();
ProjectProfile projectProfile = buildProfile.getProjectProfile(project.getPath());
projectProfile.getTaskProfile(task.getPath()).setStart(now);
ProjectMetrics projectMetrics = buildMetrics.getProjectProfile(project.getPath());
projectMetrics.getTaskProfile(task.getPath()).setStart(now);
}

@Override
public void afterExecute(Task task, TaskState state) {
long now = clock.getCurrentTime();
Project project = task.getProject();
ProjectProfile projectProfile = buildProfile.getProjectProfile(project.getPath());
TaskExecution taskExecution = projectProfile.getTaskProfile(task.getPath());
ProjectMetrics projectMetrics = buildMetrics.getProjectProfile(project.getPath());
TaskExecution taskExecution = projectMetrics.getTaskProfile(task.getPath());
taskExecution.setFinish(now);
taskExecution.completed(state);
}

@Override
public void beforeResolve(ResolvableDependencies dependencies) {
long now = clock.getCurrentTime();
buildProfile.getDependencySetProfile(dependencies.getPath()).setStart(now);
buildMetrics.getDependencySetProfile(dependencies.getPath()).setStart(now);
}

@Override
public void afterResolve(ResolvableDependencies dependencies) {
long now = clock.getCurrentTime();
buildProfile.getDependencySetProfile(dependencies.getPath()).setFinish(now);
buildMetrics.getDependencySetProfile(dependencies.getPath()).setFinish(now);
}

@Override
public void projectsEvaluated(Gradle gradle) {
checkNotNull(gradle);

/*
* There is no way for users to hook in before the build starts, this method is mostly used by internal listeners in Gradle
* @see <a href="https://github.com/gradle/gradle/issues/4315">https://github.com/gradle/gradle/issues/4315</a>
*/
buildStarted(gradle);

buildProfile.setProjectsEvaluated(clock.getCurrentTime());
buildMetrics.setProjectsEvaluated(clock.getCurrentTime());
StartParameter startParameter = gradle.getStartParameter();
checkState(!startParameter.isOffline(), "Collectors should not be registered when Gradle is running offline");
try {
Expand Down Expand Up @@ -237,10 +241,10 @@ public void buildFinishedClosure(BuildResult buildResult) {

@Override
public void buildFinished(BuildResult result) {
buildProfile.setSuccessful(result.getFailure() == null);
buildMetrics.setSuccessful(result.getFailure() == null);
}

public void buildFinished(BuildProfile result) {
public void buildFinished(BuildMetrics result) {
checkNotNull(result);
long startupElapsed = result.getElapsedStartup();
long settingsElapsed = result.getElapsedSettings();
Expand All @@ -256,8 +260,8 @@ public void buildFinished(BuildProfile result) {
expectedTotal += settingsElapsed;
dispatcher.event("projectsLoading", "configure", loadingElapsed);
expectedTotal += loadingElapsed;
for (ProjectProfile projectProfile : result.getProjects()) {
ContinuousOperation configurationOperation = projectProfile.getConfigurationOperation();
for (ProjectMetrics projectMetrics : result.getProjects()) {
ContinuousOperation configurationOperation = projectMetrics.getConfigurationOperation();
long configurationElapsed = configurationOperation.getElapsedTime();
dispatcher.event(configurationOperation.getDescription(), "configure", configurationElapsed);
expectedTotal += configurationElapsed;
Expand All @@ -271,9 +275,9 @@ public void buildFinished(BuildProfile result) {
}

// Execution
for (ProjectProfile projectProfile : result.getProjects()) {
for (ProjectMetrics projectMetrics : result.getProjects()) {
long totalTaskElapsed = 0;
CompositeOperation<TaskExecution> tasks = projectProfile.getTasks();
CompositeOperation<TaskExecution> tasks = projectMetrics.getTasks();
for (TaskExecution execution : tasks.getOperations()) {
Result taskResult = getTaskExecutionResult(execution);
long taskElapsed = execution.getElapsedTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nebula.plugin.metrics.model.profile;
package nebula.plugin.metrics.model;

import com.google.common.collect.Maps;
import org.gradle.StartParameter;
Expand All @@ -28,11 +28,11 @@

import static com.google.common.base.Preconditions.checkNotNull;

public class BuildProfile {
public class BuildMetrics {

private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd - HH:mm:ss");

private final Map<String, ProjectProfile> projects = new LinkedHashMap<String, ProjectProfile>();
private final Map<String, ProjectMetrics> projects = new LinkedHashMap<String, ProjectMetrics>();
private final Map<String, ContinuousOperation> dependencySets = new LinkedHashMap<String, ContinuousOperation>();
private final Map<String, FragmentedOperation> transforms = Maps.newLinkedHashMap();
private long profilingStarted;
Expand All @@ -44,7 +44,7 @@ public class BuildProfile {
private final StartParameter startParameter;
private boolean successful;

public BuildProfile(StartParameter startParameter) {
public BuildMetrics(StartParameter startParameter) {
checkNotNull(startParameter);
this.startParameter = startParameter;
}
Expand Down Expand Up @@ -86,10 +86,10 @@ public void setSuccessful(boolean successful) {
* Get the profiling container for the specified project
* @param projectPath to look up
*/
public ProjectProfile getProjectProfile(String projectPath) {
ProjectProfile result = projects.get(projectPath);
public ProjectMetrics getProjectProfile(String projectPath) {
ProjectMetrics result = projects.get(projectPath);
if (result == null) {
result = new ProjectProfile(projectPath);
result = new ProjectMetrics(projectPath);
projects.put(projectPath, result);
}
return result;
Expand All @@ -99,14 +99,14 @@ public ProjectProfile getProjectProfile(String projectPath) {
* Get a list of the profiling containers for all projects
* @return list
*/
public List<ProjectProfile> getProjects() {
public List<ProjectMetrics> getProjects() {
return CollectionUtils.sort(projects.values(), Operation.slowestFirst());
}

public CompositeOperation<Operation> getProjectConfiguration() {
List<Operation> operations = new ArrayList<Operation>();
for (ProjectProfile projectProfile : projects.values()) {
operations.add(projectProfile.getConfigurationOperation());
for (ProjectMetrics projectMetrics : projects.values()) {
operations.add(projectMetrics.getConfigurationOperation());
}
operations = CollectionUtils.sort(operations, Operation.slowestFirst());
return new CompositeOperation<Operation>(operations);
Expand Down Expand Up @@ -239,8 +239,8 @@ public long getElapsedArtifactTransformTime() {
*/
public long getElapsedTotalExecutionTime() {
long result = 0;
for (ProjectProfile projectProfile : projects.values()) {
result += projectProfile.getElapsedTime();
for (ProjectMetrics projectMetrics : projects.values()) {
result += projectMetrics.getElapsedTime();
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nebula.plugin.metrics.model.profile;
package nebula.plugin.metrics.model;

import com.google.common.collect.Lists;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nebula.plugin.metrics.model.profile;
package nebula.plugin.metrics.model;

import static com.google.common.base.Preconditions.checkNotNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package nebula.plugin.metrics.model.profile;
package nebula.plugin.metrics.model;

import com.google.common.collect.Sets;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nebula.plugin.metrics.model.profile;
package nebula.plugin.metrics.model;

import java.util.Comparator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nebula.plugin.metrics.model.profile;
package nebula.plugin.metrics.model;

import org.gradle.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;

public class ProjectProfile extends Operation {
public class ProjectMetrics extends Operation {
private HashMap<String, TaskExecution> tasks = new HashMap<String, TaskExecution>();
private final ContinuousOperation configurationOperation;
private String projectPath;

public ProjectProfile(String projectPath) {
public ProjectMetrics(String projectPath) {
checkNotNull(projectPath);
this.projectPath = projectPath;
this.configurationOperation = new ContinuousOperation(projectPath);
Expand All @@ -48,7 +48,7 @@ public TaskExecution getTaskProfile(String taskPath) {
* Returns the task executions for this project.
*/
public CompositeOperation<TaskExecution> getTasks() {
List<TaskExecution> taskExecutions = CollectionUtils.sort(tasks.values(), Operation.slowestFirst());
List<TaskExecution> taskExecutions = CollectionUtils.sort(tasks.values(), slowestFirst());
return new CompositeOperation<TaskExecution>(taskExecutions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nebula.plugin.metrics.model.profile;
package nebula.plugin.metrics.model;

import org.gradle.api.tasks.TaskState;
import static com.google.common.base.Preconditions.checkNotNull;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nebula.plugin.metrics.model.profile
package nebula.plugin.metrics.model


import org.gradle.StartParameter
import org.gradle.api.tasks.TaskState
Expand All @@ -23,7 +24,7 @@ import spock.lang.Subject
@Subject(BuildProfileTest)
class BuildProfileTest extends Specification {

private profile = new BuildProfile(new StartParameter())
private profile = new BuildMetrics(new StartParameter())

def "creates dependency set profile on first get"() {
expect:
Expand Down Expand Up @@ -72,7 +73,7 @@ class BuildProfileTest extends Specification {
param.setExcludedTaskNames(["one", "two"])

when:
profile = new BuildProfile(param)
profile = new BuildMetrics(param)

then:
profile.buildDescription.contains(" -x one -x two foo bar")
Expand All @@ -83,7 +84,7 @@ class BuildProfileTest extends Specification {
def param = new StartParameter()

when:
profile = new BuildProfile(param)
profile = new BuildMetrics(param)

then:
profile.buildDescription.contains(" (no tasks specified)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nebula.plugin.metrics.model.profile
package nebula.plugin.metrics.model

import nebula.plugin.metrics.model.CompositeOperation
import nebula.plugin.metrics.model.Operation
import spock.lang.Specification
import spock.lang.Subject

Expand Down

0 comments on commit af839b3

Please sign in to comment.