Search in sources :

Example 1 with ResourceSet

use of com.google.devtools.build.lib.actions.ResourceSet in project bazel by bazelbuild.

the class DeployArchiveBuilder method build.

/** Builds the action as configured. */
public void build() throws InterruptedException {
    ImmutableList<Artifact> classpathResources = attributes.getClassPathResources();
    Set<String> classPathResourceNames = new HashSet<>();
    for (Artifact artifact : classpathResources) {
        String name = artifact.getExecPath().getBaseName();
        if (!classPathResourceNames.add(name)) {
            ruleContext.attributeError("classpath_resources", "entries must have different file names (duplicate: " + name + ")");
            return;
        }
    }
    IterablesChain<Artifact> runtimeJars = runtimeJarsBuilder.build();
    // TODO(kmb): Consider not using getArchiveInputs, specifically because we don't want/need to
    // transform anything but the runtimeClasspath and b/c we currently do it twice here and below
    IterablesChain.Builder<Artifact> inputs = IterablesChain.builder();
    inputs.add(getArchiveInputs(attributes, derivedJars));
    inputs.add(ImmutableList.copyOf(Iterables.transform(runtimeJars, derivedJars)));
    if (runfilesMiddleman != null) {
        inputs.addElement(runfilesMiddleman);
    }
    ImmutableList<Artifact> buildInfoArtifacts = ruleContext.getBuildInfo(JavaBuildInfoFactory.KEY);
    inputs.add(buildInfoArtifacts);
    Iterable<Artifact> runtimeClasspath = Iterables.transform(Iterables.concat(runtimeJars, attributes.getRuntimeClassPathForArchive()), derivedJars);
    if (launcher != null) {
        inputs.addElement(launcher);
    }
    CommandLine commandLine = semantics.buildSingleJarCommandLine(ruleContext.getConfiguration(), outputJar, javaStartClass, deployManifestLines, buildInfoArtifacts, classpathResources, runtimeClasspath, includeBuildData, compression, launcher);
    List<String> jvmArgs = ImmutableList.of(SINGLEJAR_MAX_MEMORY);
    ResourceSet resourceSet = ResourceSet.createWithRamCpuIo(/*memoryMb = */
    200.0, /*cpuUsage = */
    .2, /*ioUsage=*/
    .2);
    // If singlejar's name ends with .jar, it is Java application, otherwise it is native.
    // TODO(asmundak): once https://github.com/bazelbuild/bazel/issues/2241 is fixed (that is,
    // the native singlejar is used on windows) remove support for the Java implementation
    Artifact singlejar = getSingleJar(ruleContext);
    if (singlejar.getFilename().endsWith(".jar")) {
        ruleContext.registerAction(new SpawnAction.Builder().addInputs(inputs.build()).addTransitiveInputs(JavaHelper.getHostJavabaseInputs(ruleContext)).addOutput(outputJar).setResources(resourceSet).setJarExecutable(ruleContext.getHostConfiguration().getFragment(Jvm.class).getJavaExecutable(), singlejar, jvmArgs).setCommandLine(commandLine).alwaysUseParameterFile(ParameterFileType.SHELL_QUOTED).setProgressMessage("Building deploy jar " + outputJar.prettyPrint()).setMnemonic("JavaDeployJar").setExecutionInfo(ImmutableMap.of("supports-workers", "1")).build(ruleContext));
    } else {
        ruleContext.registerAction(new SpawnAction.Builder().addInputs(inputs.build()).addOutput(outputJar).setResources(resourceSet).setExecutable(singlejar).setCommandLine(commandLine).alwaysUseParameterFile(ParameterFileType.SHELL_QUOTED).setProgressMessage("Building deploy jar " + outputJar.prettyPrint()).setMnemonic("JavaDeployJar").build(ruleContext));
    }
}
Also used : IterablesChain(com.google.devtools.build.lib.collect.IterablesChain) ResourceSet(com.google.devtools.build.lib.actions.ResourceSet) Artifact(com.google.devtools.build.lib.actions.Artifact) CommandLine(com.google.devtools.build.lib.analysis.actions.CommandLine) CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) HashSet(java.util.HashSet)

Example 2 with ResourceSet

use of com.google.devtools.build.lib.actions.ResourceSet in project bazel by bazelbuild.

the class CppLinkActionTest method assertLinkSizeAccuracy.

private void assertLinkSizeAccuracy(int inputs) throws Exception {
    ImmutableList.Builder<Artifact> objects = ImmutableList.builder();
    for (int i = 0; i < inputs; i++) {
        objects.add(getOutputArtifact("object" + i + ".o"));
    }
    CppLinkAction linkAction = createLinkBuilder(Link.LinkTargetType.EXECUTABLE, "dummyRuleContext/binary2", objects.build(), ImmutableList.<LibraryToLink>of(), new FeatureConfiguration()).setFake(true).build();
    // Ensure that minima are enforced.
    ResourceSet resources = linkAction.estimateResourceConsumptionLocal();
    assertTrue(resources.getMemoryMb() >= CppLinkAction.MIN_STATIC_LINK_RESOURCES.getMemoryMb());
    assertTrue(resources.getCpuUsage() >= CppLinkAction.MIN_STATIC_LINK_RESOURCES.getCpuUsage());
    assertTrue(resources.getIoUsage() >= CppLinkAction.MIN_STATIC_LINK_RESOURCES.getIoUsage());
    final int linkSize = Iterables.size(linkAction.getLinkCommandLine().getLinkerInputs());
    ResourceSet scaledSet = ResourceSet.createWithRamCpuIo(CppLinkAction.LINK_RESOURCES_PER_INPUT.getMemoryMb() * linkSize, CppLinkAction.LINK_RESOURCES_PER_INPUT.getCpuUsage() * linkSize, CppLinkAction.LINK_RESOURCES_PER_INPUT.getIoUsage() * linkSize);
    // Ensure that anything above the minimum is properly scaled.
    assertTrue(resources.getMemoryMb() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getMemoryMb() || resources.getMemoryMb() == scaledSet.getMemoryMb());
    assertTrue(resources.getCpuUsage() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getCpuUsage() || resources.getCpuUsage() == scaledSet.getCpuUsage());
    assertTrue(resources.getIoUsage() == CppLinkAction.MIN_STATIC_LINK_RESOURCES.getIoUsage() || resources.getIoUsage() == scaledSet.getIoUsage());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) ResourceSet(com.google.devtools.build.lib.actions.ResourceSet) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 3 with ResourceSet

use of com.google.devtools.build.lib.actions.ResourceSet in project bazel by bazelbuild.

the class ExecutionTool method configureResourceManager.

private void configureResourceManager(BuildRequest request) {
    ResourceManager resourceMgr = ResourceManager.instance();
    ExecutionOptions options = request.getOptions(ExecutionOptions.class);
    ResourceSet resources;
    if (options.availableResources != null) {
        resources = options.availableResources;
        resourceMgr.setRamUtilizationPercentage(100);
    } else {
        resources = LocalHostCapacity.getLocalHostCapacity();
        resourceMgr.setRamUtilizationPercentage(options.ramUtilizationPercentage);
    }
    resourceMgr.setAvailableResources(ResourceSet.create(resources.getMemoryMb(), resources.getCpuUsage(), resources.getIoUsage(), request.getExecutionOptions().usingLocalTestJobs() ? request.getExecutionOptions().localTestJobs : Integer.MAX_VALUE));
}
Also used : ExecutionOptions(com.google.devtools.build.lib.exec.ExecutionOptions) ResourceManager(com.google.devtools.build.lib.actions.ResourceManager) ResourceSet(com.google.devtools.build.lib.actions.ResourceSet)

Example 4 with ResourceSet

use of com.google.devtools.build.lib.actions.ResourceSet in project bazel by bazelbuild.

the class CppLinkAction method estimateResourceConsumptionLocal.

/**
   * Estimate the resources consumed when this action is run locally.
   */
public ResourceSet estimateResourceConsumptionLocal() {
    // It's ok if this behaves differently even if the key is identical.
    ResourceSet minLinkResources = getLinkCommandLine().getLinkStaticness() == Link.LinkStaticness.DYNAMIC ? MIN_DYNAMIC_LINK_RESOURCES : MIN_STATIC_LINK_RESOURCES;
    final int inputSize = Iterables.size(getLinkCommandLine().getLinkerInputs()) + Iterables.size(getLinkCommandLine().getRuntimeInputs());
    return ResourceSet.createWithRamCpuIo(Math.max(inputSize * LINK_RESOURCES_PER_INPUT.getMemoryMb(), minLinkResources.getMemoryMb()), Math.max(inputSize * LINK_RESOURCES_PER_INPUT.getCpuUsage(), minLinkResources.getCpuUsage()), Math.max(inputSize * LINK_RESOURCES_PER_INPUT.getIoUsage(), minLinkResources.getIoUsage()));
}
Also used : ResourceSet(com.google.devtools.build.lib.actions.ResourceSet) Fingerprint(com.google.devtools.build.lib.util.Fingerprint)

Aggregations

ResourceSet (com.google.devtools.build.lib.actions.ResourceSet)4 Artifact (com.google.devtools.build.lib.actions.Artifact)2 ImmutableList (com.google.common.collect.ImmutableList)1 ResourceManager (com.google.devtools.build.lib.actions.ResourceManager)1 CommandLine (com.google.devtools.build.lib.analysis.actions.CommandLine)1 CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)1 IterablesChain (com.google.devtools.build.lib.collect.IterablesChain)1 ExecutionOptions (com.google.devtools.build.lib.exec.ExecutionOptions)1 FeatureConfiguration (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration)1 Fingerprint (com.google.devtools.build.lib.util.Fingerprint)1 HashSet (java.util.HashSet)1