Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmv committed Aug 9, 2023
1 parent e19b541 commit ab31c6b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
"//src/main/java/com/google/devtools/build/lib/actions:commandline_item",
"//src/main/java/com/google/devtools/build/lib/actions:execution_requirements",
"//src/main/java/com/google/devtools/build/lib/actions:file_metadata",
"//src/main/java/com/google/devtools/build/lib/actions:localhost_capacity",
"//src/main/java/com/google/devtools/build/lib/actions:middleman_type",
"//src/main/java/com/google/devtools/build/lib/actions:runfiles_supplier",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.devtools.build.lib.actions.CommandLines.CommandLineAndParamFileInfo;
import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.actions.ExecutionRequirements;
import com.google.devtools.build.lib.actions.FileArtifactValue;
import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.actions.SimpleSpawn;
import com.google.devtools.build.lib.actions.SimpleSpawn.LocalResourcesSupplier;
Expand Down Expand Up @@ -335,6 +336,7 @@ public ActionResult execute(ActionExecutionContext actionExecutionContext)
throws ActionExecutionException, InterruptedException {
LocalResourcesEstimator localResourcesEstimator =
new LocalResourcesEstimator(
actionExecutionContext,
OS.getCurrent(),
linkCommandLine.getLinkerInputArtifacts());

Expand Down Expand Up @@ -491,6 +493,7 @@ protected String getRawProgressMessage() {
*/
@VisibleForTesting
static class LocalResourcesEstimator implements LocalResourcesSupplier {
private final ActionExecutionContext actionExecutionContext;
private final OS os;
private final NestedSet<Artifact> inputs;

Expand All @@ -509,7 +512,9 @@ private static class LazyData {

private LazyData lazyData = null;

public LocalResourcesEstimator(OS os, NestedSet<Artifact> inputs) {
public LocalResourcesEstimator(
ActionExecutionContext actionExecutionContext, OS os, NestedSet<Artifact> inputs) {
this.actionExecutionContext = actionExecutionContext;
this.os = os;
this.inputs = inputs;
}
Expand All @@ -521,7 +526,14 @@ private LazyData doCostlyEstimation() {
for (Artifact input : inputs.toList()) {
inputsCount += 1;
try {
inputsBytes += input.getPath().getFileSize();
FileArtifactValue value =
actionExecutionContext.getInputMetadataProvider().getInputMetadata(input);
if (value != null) {
inputsBytes += value.getSize();
} else {
logger.atWarning().log(
"Linker metrics: failed to get size of %s: no metadata", input.getExecPath());
}
} catch (Exception e) {
logger.atWarning().log(
"Linker metrics: failed to get size of %s: %s (ignored)", input.getExecPath(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib/testutil:TestUtils",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:truth",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;

import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
Expand All @@ -25,6 +26,7 @@
import com.google.common.primitives.Ints;
import com.google.devtools.build.lib.actions.Action;
import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
Expand Down Expand Up @@ -785,9 +787,12 @@ private static NestedSet<Artifact> createInputs(RuleContext ruleContext, int cou

private ResourceSet estimateResourceConsumptionLocal(
RuleContext ruleContext, OS os, int inputsCount) throws Exception {
ActionExecutionContext actionExecutionContext = mock(ActionExecutionContext.class);

NestedSet<Artifact> inputs = createInputs(ruleContext, inputsCount);
try {
LocalResourcesEstimator estimator = new LocalResourcesEstimator(os, inputs);
LocalResourcesEstimator estimator =
new LocalResourcesEstimator(actionExecutionContext, os, inputs);
return estimator.get();
} finally {
for (Artifact input : inputs.toList()) {
Expand Down

0 comments on commit ab31c6b

Please sign in to comment.