Add option to disable critical path computation in Bazel. While this information is useful, the critical path computer retains references to objects that could otherwise be cleared to save memory.
This change is probably not worth submitting on its own -- the benefit it provides is too slight. But my follow-up change unknown commit needs this option to be effective -- the critical path currently hangs on to references to every action in the graph, so we can't drop references to actions if it's enabled.
The critical path could probably be reworked in the future to not hang onto those references.
PiperOrigin-RevId: 151747605
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 c470d2c..705a00a 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
@@ -16,10 +16,13 @@
import com.google.common.base.Joiner;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
+import com.google.devtools.build.lib.buildtool.BuildRequest;
import com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent;
import com.google.devtools.build.lib.buildtool.buildevent.ExecutionStartingEvent;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.Reporter;
+import com.google.devtools.build.lib.exec.ExecutionOptions;
+import com.google.devtools.build.lib.exec.ExecutorBuilder;
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.profiler.ProfilerTask;
import com.google.devtools.build.lib.util.BlazeClock;
@@ -37,6 +40,7 @@
private SimpleCriticalPathComputer criticalPathComputer;
private EventBus eventBus;
private Reporter reporter;
+ private boolean enabled;
@Override
public void beforeCommand(Command command, CommandEnvironment env) {
@@ -52,10 +56,17 @@
this.reporter = null;
}
+ @Override
+ public void executorInit(CommandEnvironment env, BuildRequest request, ExecutorBuilder builder) {
+ enabled = env.getOptions().getOptions(ExecutionOptions.class).enableCriticalPathProfiling;
+ }
+
@Subscribe
public void executionPhaseStarting(ExecutionStartingEvent event) {
- criticalPathComputer = new SimpleCriticalPathComputer(BlazeClock.instance());
- eventBus.register(criticalPathComputer);
+ if (enabled) {
+ criticalPathComputer = new SimpleCriticalPathComputer(BlazeClock.instance());
+ eventBus.register(criticalPathComputer);
+ }
}
@Subscribe