Add support for "HOST_CPUS" and "HOST_RAM" to --experimental_include_scanning_parallelism.
Allow users to set the value of this flag relative to host resources for greater control over performance.
Remove support for negative values. Previously, values <=0 would disable parallelism, but only 0 was documented as doing so.
RELNOTES: None.
package com.google.devtools.build.lib.includescanning;
import com.google.devtools.build.lib.actions.LocalHostCapacity;
-import com.google.devtools.common.options.Converters.IntegerConverter;
+import com.google.devtools.build.lib.util.ResourceConverter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
@@ -27,22 +27,16 @@ import com.google.devtools.common.options.OptionsParsingException;
public class IncludeScanningOptions extends OptionsBase {
/**
- * Converter for a number of threads or {@code auto}, which automatically selects a value that
- * makes sense according to the local machine resources.
+ * Converter for scanning parallelism threads: Takes {@value #FLAG_SYNTAX} 0 disables scanning
+ * parallelism.
*/
- public static class ParallelismConverter extends IntegerConverter {
- @Override
- public Integer convert(String input) throws OptionsParsingException {
- if (input.equals("auto")) {
- return (int) Math.ceil(LocalHostCapacity.getLocalHostCapacity().getCpuUsage());
- } else {
- return super.convert(input);
- }
- }
-
- @Override
- public String getTypeDescription() {
- return "\"auto\" or " + super.getTypeDescription();
+ public static class ParallelismConverter extends ResourceConverter {
+ public ParallelismConverter() throws OptionsParsingException {
+ super(
+ /* autoSupplier= */ () ->
+ (int) Math.ceil(LocalHostCapacity.getLocalHostCapacity().getCpuUsage()),
+ /* minValue= */ 0,
+ /* maxValue= */ Integer.MAX_VALUE);
}
}
@@ -99,11 +93,11 @@ public class IncludeScanningOptions extends OptionsBase {
defaultValue = "80",
converter = ParallelismConverter.class,
help =
- "Configures the size of the thread pool used for include scanning. "
- + "0 means to disable parallelism and to just rely on the build graph parallelism "
+ "Configures the size of the thread pool used for include scanning. Takes "
+ + ResourceConverter.FLAG_SYNTAX
+ + ". 0 means to disable parallelism and to just rely on the build graph parallelism "
+ "for concurrency. "
+ " \"auto\" means to use a reasonable value derived from the machine's hardware"
- + " profile (e.g. the number of processors)."
- )
+ + " profile (e.g. the number of processors).")
public int includeScanningParallelism;
}
