Merge SimpleCriticalPathComputer into CriticalPathComputer
PiperOrigin-RevId: 213799069
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java
index 86d4e80..cd39b50 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java
@@ -45,7 +45,7 @@
private static final Logger logger = Logger.getLogger(BuildSummaryStatsModule.class.getName());
private ActionKeyContext actionKeyContext;
- private SimpleCriticalPathComputer criticalPathComputer;
+ private CriticalPathComputer criticalPathComputer;
private EventBus eventBus;
private Reporter reporter;
private boolean enabled;
@@ -80,7 +80,7 @@
public void executionPhaseStarting(ExecutionStartingEvent event) {
if (enabled) {
criticalPathComputer =
- new SimpleCriticalPathComputer(actionKeyContext, BlazeClock.instance(), discardActions);
+ new CriticalPathComputer(actionKeyContext, BlazeClock.instance(), discardActions);
eventBus.register(criticalPathComputer);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComponent.java b/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComponent.java
index 70c9133..59150a7 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComponent.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComponent.java
@@ -219,7 +219,6 @@
/** Returns a string representation of the action. Only for use in crash messages and the like. */
protected String getActionString() {
- Action action = maybeGetAction();
return (action == null ? "(null action)" : action.prettyPrint());
}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComputer.java b/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComputer.java
index 737337b..85692f3 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComputer.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CriticalPathComputer.java
@@ -27,12 +27,15 @@
import com.google.devtools.build.lib.actions.Actions;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.CachedActionEvent;
+import com.google.devtools.build.lib.actions.SpawnMetrics;
import com.google.devtools.build.lib.clock.Clock;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.concurrent.ThreadSafe;
/**
@@ -41,10 +44,11 @@
* <p>After instantiation, this object needs to be registered on the event bus to work.
*/
@ThreadSafe
-public abstract class CriticalPathComputer {
-
+public class CriticalPathComputer {
/** Number of top actions to record. */
static final int SLOWEST_COMPONENTS_SIZE = 30;
+
+ private final AtomicInteger idGenerator = new AtomicInteger();
// outputArtifactToComponent is accessed from multiple event handlers.
protected final ConcurrentMap<Artifact, CriticalPathComponent> outputArtifactToComponent =
Maps.newConcurrentMap();
@@ -82,7 +86,12 @@
* @param relativeStartNanos time when the action started to run in nanos. Only mean to be used
* for computing time differences.
*/
- protected abstract CriticalPathComponent createComponent(Action action, long relativeStartNanos);
+ public CriticalPathComponent createComponent(Action action, long relativeStartNanos) {
+ int id = idGenerator.getAndIncrement();
+ return discardActions
+ ? new ActionDiscardingCriticalPathComponent(id, action, relativeStartNanos)
+ : new CriticalPathComponent(id, action, relativeStartNanos);
+ }
/**
* Return the critical path stats for the current command execution.
@@ -90,7 +99,20 @@
* <p>This method allows us to calculate lazily the aggregate statistics of the critical path,
* avoiding the memory and cpu penalty for doing it for all the actions executed.
*/
- public abstract AggregatedCriticalPath aggregate();
+ public AggregatedCriticalPath aggregate() {
+ ImmutableList.Builder<CriticalPathComponent> components = ImmutableList.builder();
+ CriticalPathComponent maxCriticalPath = getMaxCriticalPath();
+ if (maxCriticalPath == null) {
+ return new AggregatedCriticalPath(Duration.ZERO, SpawnMetrics.EMPTY, components.build());
+ }
+ CriticalPathComponent child = maxCriticalPath;
+ while (child != null) {
+ components.add(child);
+ child = child.getChild();
+ }
+ return new AggregatedCriticalPath(
+ maxCriticalPath.getAggregatedElapsedTime(), SpawnMetrics.EMPTY, components.build());
+ }
/**
* Record an action that has started to run.
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/SimpleCriticalPathComputer.java b/src/main/java/com/google/devtools/build/lib/runtime/SimpleCriticalPathComputer.java
deleted file mode 100644
index 331431a..0000000
--- a/src/main/java/com/google/devtools/build/lib/runtime/SimpleCriticalPathComputer.java
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.runtime;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.actions.Action;
-import com.google.devtools.build.lib.actions.ActionKeyContext;
-import com.google.devtools.build.lib.actions.SpawnMetrics;
-import com.google.devtools.build.lib.clock.Clock;
-import java.time.Duration;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * Computes the critical path during a build.
- */
-public class SimpleCriticalPathComputer extends CriticalPathComputer {
- private final AtomicInteger idGenerator = new AtomicInteger();
-
- SimpleCriticalPathComputer(
- ActionKeyContext actionKeyContext, Clock clock, boolean discardActions) {
- super(actionKeyContext, clock, discardActions);
- }
-
- @Override
- public CriticalPathComponent createComponent(Action action, long relativeStartNanos) {
- int id = idGenerator.getAndIncrement();
- return discardActions
- ? new ActionDiscardingCriticalPathComponent(id, action, relativeStartNanos)
- : new CriticalPathComponent(id, action, relativeStartNanos);
- }
-
- /**
- * Return the critical path stats for the current command execution.
- *
- * <p>This method allow us to calculate lazily the aggregate statistics of the critical path,
- * avoiding the memory and cpu penalty for doing it for all the actions executed.
- */
- @Override
- public AggregatedCriticalPath aggregate() {
- ImmutableList.Builder<CriticalPathComponent> components = ImmutableList.builder();
- CriticalPathComponent maxCriticalPath = getMaxCriticalPath();
- if (maxCriticalPath == null) {
- return new AggregatedCriticalPath(Duration.ZERO, SpawnMetrics.EMPTY, components.build());
- }
- CriticalPathComponent child = maxCriticalPath;
- while (child != null) {
- components.add(child);
- child = child.getChild();
- }
- return new AggregatedCriticalPath(
- maxCriticalPath.getAggregatedElapsedTime(), SpawnMetrics.EMPTY, components.build());
- }
-}
-