aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Philipp Wollermann <philwo@google.com>2017-02-01 13:45:55 +0000
committerGravatar Yun Peng <pcloudy@google.com>2017-02-01 14:31:25 +0000
commit4ca5dfa0a66e9baf6c3953830fc53e6da27b9f42 (patch)
treeadc4f37dfa5141eb21c699d3edf5b1330f6d0353 /src/main/java
parent46d31b5f1e3201651bf621da2674ff2f070ce824 (diff)
Add a flag to print the effective (Spawn)ActionContexts for debugging.
By specifying the flag "--debug_print_action_contexts", Bazel will print the contents of the internal SpawnActionContext and ContextMap maps, which allows developers to see which kind of actions are run using which strategy. Example output of Bazel at HEAD: $ ./output/bazel build --debug_print_action_contexts INFO: SpawnActionContextMap: "" = LinuxSandboxedStrategy INFO: SpawnActionContextMap: "Closure" = WorkerSpawnStrategy INFO: SpawnActionContextMap: "Javac" = WorkerSpawnStrategy INFO: ContextMap: Context = BazelWorkspaceStatusActionContext INFO: ContextMap: CppCompileActionContext = SpawnGccStrategy INFO: ContextMap: CppLinkActionContext = SpawnLinkStrategy INFO: ContextMap: FileWriteActionContext = FileWriteStrategy INFO: ContextMap: FilesetActionContext = FilesetActionContextImpl INFO: ContextMap: IncludeScanningContext = DummyIncludeScanningContext INFO: ContextMap: SpawnActionContext = LinuxSandboxedStrategy INFO: ContextMap: SymlinkTreeActionContext = SymlinkTreeStrategy INFO: ContextMap: TestActionContext = ExclusiveTestStrategy (Can you spot the bug found by this feature here? The default TestActionContext is ExclusiveTestStrategy, which is probably not what we want.) -- PiperOrigin-RevId: 146233390 MOS_MIGRATED_REVID=146233390
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java58
-rw-r--r--src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java8
3 files changed, 49 insertions, 19 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
index c332127b8a..48bc11c8d9 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
@@ -299,8 +299,6 @@ public class ExecutionTool {
env.getEventBus(),
runtime.getClock(),
request,
- request.getOptions(ExecutionOptions.class).verboseFailures,
- request.getOptions(ExecutionOptions.class).showSubcommands,
strategies,
spawnStrategyMap,
actionContextProviders);
diff --git a/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java b/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java
index 3f7e07075b..a9cb8b094d 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/BlazeExecutor.java
@@ -38,6 +38,8 @@ import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -67,31 +69,29 @@ public final class BlazeExecutor implements Executor {
new HashMap<>();
/**
- * Constructs an Executor, bound to a specified output base path, and which
- * will use the specified reporter to announce SUBCOMMAND events,
- * the given event bus to delegate events and the given output streams
- * for streaming output. The list of
- * strategy implementation classes is used to construct instances of the
- * strategies mapped by their declared abstract type. This list is uniquified
- * before using. Each strategy instance is created with a reference to this
- * Executor as well as the given options object.
- * <p>
- * Don't forget to call startBuildRequest() and stopBuildRequest() for each
- * request, and shutdown() when you're done with this executor.
+ * Constructs an Executor, bound to a specified output base path, and which will use the specified
+ * reporter to announce SUBCOMMAND events, the given event bus to delegate events and the given
+ * output streams for streaming output. The list of strategy implementation classes is used to
+ * construct instances of the strategies mapped by their declared abstract type. This list is
+ * uniquified before using. Each strategy instance is created with a reference to this Executor as
+ * well as the given options object.
+ *
+ * <p>Don't forget to call startBuildRequest() and stopBuildRequest() for each request, and
+ * shutdown() when you're done with this executor.
*/
- public BlazeExecutor(Path execRoot,
+ public BlazeExecutor(
+ Path execRoot,
Reporter reporter,
EventBus eventBus,
Clock clock,
OptionsClassProvider options,
- boolean verboseFailures,
- boolean showSubcommands,
List<ActionContext> contextImplementations,
Map<String, SpawnActionContext> spawnActionContextMap,
Iterable<ActionContextProvider> contextProviders)
throws ExecutorInitException {
- this.verboseFailures = verboseFailures;
- this.showSubcommands = showSubcommands;
+ ExecutionOptions executionOptions = options.getOptions(ExecutionOptions.class);
+ this.verboseFailures = executionOptions.verboseFailures;
+ this.showSubcommands = executionOptions.showSubcommands;
this.execRoot = execRoot;
this.reporter = reporter;
this.eventBus = eventBus;
@@ -105,7 +105,6 @@ public final class BlazeExecutor implements Executor {
allContexts.addAll(contextImplementations);
allContexts.addAll(spawnActionContextMap.values());
this.spawnActionContextMap = ImmutableMap.copyOf(spawnActionContextMap);
-
for (ActionContext context : contextImplementations) {
ExecutionStrategy annotation = context.getClass().getAnnotation(ExecutionStrategy.class);
if (annotation != null) {
@@ -114,6 +113,31 @@ public final class BlazeExecutor implements Executor {
contextMap.put(context.getClass(), context);
}
+ // Print a sorted list of our (Spawn)ActionContext maps.
+ if (executionOptions.debugPrintActionContexts) {
+ for (Entry<String, SpawnActionContext> entry :
+ new TreeMap<>(spawnActionContextMap).entrySet()) {
+ reporter.handle(
+ Event.info(
+ String.format(
+ "SpawnActionContextMap: \"%s\" = %s",
+ entry.getKey(), entry.getValue().getClass().getSimpleName())));
+ }
+
+ TreeMap<String, String> sortedContextMapWithSimpleNames = new TreeMap<>();
+ for (Entry<Class<? extends ActionContext>, ActionContext> entry : contextMap.entrySet()) {
+ sortedContextMapWithSimpleNames.put(
+ entry.getKey().getSimpleName(), entry.getValue().getClass().getSimpleName());
+ }
+ for (Entry<String, String> entry : sortedContextMapWithSimpleNames.entrySet()) {
+ // Skip uninteresting identity mappings of contexts.
+ if (!entry.getKey().equals(entry.getValue())) {
+ reporter.handle(
+ Event.info(String.format("ContextMap: %s = %s", entry.getKey(), entry.getValue())));
+ }
+ }
+ }
+
for (ActionContextProvider factory : contextProviders) {
factory.executorCreated(allContexts);
}
diff --git a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
index dc823f2be7..b8b2ac2509 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
@@ -197,4 +197,12 @@ public class ExecutionOptions extends OptionsBase {
public boolean usingLocalTestJobs() {
return localTestJobs != 0;
}
+
+ @Option(
+ name = "debug_print_action_contexts",
+ defaultValue = "false",
+ category = "undocumented",
+ help = "Print the contents of the SpawnActionContext and ContextProviders maps."
+ )
+ public boolean debugPrintActionContexts;
}