aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
diff options
context:
space:
mode:
authorGravatar Janak Ramakrishnan <janakr@google.com>2016-11-17 18:34:08 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-11-18 10:54:26 +0000
commitbede7b47d88c3892c47382ed39911117e48adc70 (patch)
tree330ad21b0d317e8a20a856bbabecc10954e27746 /src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
parent6c3ac8acf02a6fa5758dc8e67b7f6c9a428e4e67 (diff)
Run the analysis phase with as many threads as the user wants. In order to avoid memory blow-up intra-configured-target analysis, use a semaphore to ensure that CPU-bound work only occurs on #CPU-many threads.
RELNOTES: Use --loading_phase_threads to control the number of threads used during the loading/analysis phase. -- MOS_MIGRATED_REVID=139477645
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis/BuildView.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/BuildView.java48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
index 20b89b0f82..b29d2a2a79 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
@@ -82,8 +82,10 @@ import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.WalkableGraph;
+import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionsBase;
+import com.google.devtools.common.options.OptionsParsingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -149,6 +151,14 @@ public class BuildView {
* of a BuildConfiguration.
*/
public static class Options extends OptionsBase {
+ @Option(
+ name = "loading_phase_threads",
+ defaultValue = "-1",
+ category = "what",
+ converter = LoadingPhaseThreadCountConverter.class,
+ help = "Number of parallel threads to use for the loading/analysis phase."
+ )
+ public int loadingPhaseThreads;
@Option(name = "keep_going",
abbrev = 'k',
@@ -502,7 +512,12 @@ public class BuildView {
try {
skyframeAnalysisResult =
skyframeBuildView.configureTargets(
- eventHandler, topLevelCtKeys, aspectKeys, eventBus, viewOptions.keepGoing);
+ eventHandler,
+ topLevelCtKeys,
+ aspectKeys,
+ eventBus,
+ viewOptions.keepGoing,
+ viewOptions.loadingPhaseThreads);
setArtifactRoots(skyframeAnalysisResult.getPackageRoots());
} finally {
skyframeBuildView.clearInvalidatedConfiguredTargets();
@@ -1107,4 +1122,35 @@ public class BuildView {
}
return null;
}
+
+ /**
+ * A converter for loading phase thread count. Since the default is not a true constant, we create
+ * a converter here to implement the default logic.
+ */
+ public static final class LoadingPhaseThreadCountConverter implements Converter<Integer> {
+ @Override
+ public Integer convert(String input) throws OptionsParsingException {
+ if ("-1".equals(input)) {
+ // Reduce thread count while running tests. Test cases are typically small, and large thread
+ // pools vying for a relatively small number of CPU cores may induce non-optimal
+ // performance.
+ return System.getenv("TEST_TMPDIR") == null ? 200 : 5;
+ }
+
+ try {
+ int result = Integer.decode(input);
+ if (result < 0) {
+ throw new OptionsParsingException("'" + input + "' must be at least -1");
+ }
+ return result;
+ } catch (NumberFormatException e) {
+ throw new OptionsParsingException("'" + input + "' is not an int");
+ }
+ }
+
+ @Override
+ public String getTypeDescription() {
+ return "an integer";
+ }
+ }
}