Skip to content

Commit

Permalink
Temporary extra debugging info for super-slow occasional builds.
Browse files Browse the repository at this point in the history
RELNOTES: None.
PiperOrigin-RevId: 388908994
  • Loading branch information
larsrc-google authored and copybara-github committed Aug 5, 2021
1 parent a8fe064 commit 5b1c12f
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
Expand Down Expand Up @@ -541,6 +542,14 @@ public ImmutableList<SpawnResult> exec(
spawn.getResourceOwner().prettyPrint());
throw new UserExecException(failure);
} else if (!localCanExec && remoteCanExec) {
// Extra logging to debug b/194373457
logger.atInfo().atMostEvery(1, TimeUnit.SECONDS).log(
"Dynamic execution of %s can only be done remotely: Local execution policy %s it, "
+ "local strategies are %s.%n",
spawn.getResourceOwner().prettyPrint(),
executionPolicy.canRunLocally() ? "allows" : "forbids",
dynamicStrategyRegistry.getDynamicSpawnActionContexts(
spawn, DynamicStrategyRegistry.DynamicMode.LOCAL));
debugLog(
"Dynamic execution of %s can only be done remotely: Local execution policy %s it, "
+ "local strategies are %s.%n",
Expand All @@ -550,6 +559,14 @@ public ImmutableList<SpawnResult> exec(
spawn, DynamicStrategyRegistry.DynamicMode.LOCAL));
return runRemotely(spawn, actionExecutionContext, null);
} else if (localCanExec && !remoteCanExec) {
// Extra logging to debug b/194373457
logger.atInfo().atMostEvery(1, TimeUnit.SECONDS).log(
"Dynamic execution of %s can only be done locally: Remote execution policy %s it, "
+ "remote strategies are %s.%n",
spawn.getResourceOwner().prettyPrint(),
executionPolicy.canRunRemotely() ? "allows" : "forbids",
dynamicStrategyRegistry.getDynamicSpawnActionContexts(
spawn, DynamicStrategyRegistry.DynamicMode.REMOTE));
debugLog(
"Dynamic execution of %s can only be done locally: Remote execution policy %s it, "
+ "remote strategies are %s.%n",
Expand All @@ -559,6 +576,9 @@ public ImmutableList<SpawnResult> exec(
spawn, DynamicStrategyRegistry.DynamicMode.REMOTE));
return runLocally(spawn, actionExecutionContext, null);
}
// Extra logging to debug b/194373457
logger.atInfo().atMostEvery(1, TimeUnit.SECONDS).log(
"Spawn %s dynamically executed both ways", spawn.getResourceOwner().describe());
debugLog("Dynamic execution of %s beginning%n", spawn.getResourceOwner().prettyPrint());
// else both can exec. Fallthrough to below.

Expand Down Expand Up @@ -707,6 +727,11 @@ public ImmutableList<SpawnResult> callImpl(ActionExecutionContext context)
} finally {
checkState(localBranch.isDone());
checkState(remoteBranch.isDone());
logger.atInfo().atMostEvery(1, TimeUnit.SECONDS).log(
"Dynamic execution of %s ended with local %s, remote %s%n",
spawn.getResourceOwner().prettyPrint(),
localBranch.isCancelled() ? "cancelled" : "done",
remoteBranch.isCancelled() ? "cancelled" : "done");
debugLog(
"Dynamic execution of %s ended with local %s, remote %s%n",
spawn.getResourceOwner().prettyPrint(),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/exec/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ java_library(
":spawn_strategy_registry",
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/protobuf:failure_details_java_proto",
"//third_party:flogger",
"//third_party:guava",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.flogger.GoogleLogger;
import com.google.devtools.build.lib.actions.ActionContext;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
import com.google.devtools.build.lib.actions.ExecException;
Expand All @@ -27,13 +28,15 @@
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
import com.google.devtools.build.lib.server.FailureDetails.Spawn.Code;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
* Resolver that looks up the right strategy for a spawn during {@link #exec} (via a {@link
* SpawnStrategyRegistry}) and uses it to execute the spawn.
*/
public final class SpawnStrategyResolver implements ActionContext {
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();

/**
* Executes the given spawn with the {@linkplain SpawnStrategyRegistry highest priority strategy}
Expand Down Expand Up @@ -116,8 +119,18 @@ public List<? extends SpawnStrategy> resolve(
.setMessage(message)
.setSpawn(FailureDetails.Spawn.newBuilder().setCode(Code.NO_USABLE_STRATEGY_FOUND))
.build());
} else {
// Extra logging to debug b/194373457
logger.atInfo().atMostEvery(1, TimeUnit.SECONDS).log(
"Spawn %s resolved with fallback to strategies %s",
spawn.getResourceOwner().describe(), fallbackStrategies);
}
return fallbackStrategies;
} else {
// Extra logging to debug b/194373457
logger.atInfo().atMostEvery(1, TimeUnit.SECONDS).log(
"Spawn %s resolved to strategies %s",
spawn.getResourceOwner().describe(), execableStrategies);
}

return execableStrategies;
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/google/devtools/build/lib/testutil/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,23 @@ java_library(
],
)

java_library(
name = "FakeResourceOwner_lib",
srcs = [
"FakeResourceOwner.java",
],
deps = [
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
"//src/main/java/com/google/devtools/build/lib/actions:middleman_type",
"//src/main/java/com/google/devtools/build/lib/analysis/platform",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/net/starlark/java/syntax",
"//third_party:guava",
"//third_party:jsr305",
],
)

java_test(
name = "TestUtilTests",
size = "small",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Copyright 2021 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.testutil;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
import com.google.devtools.build.lib.actions.ActionExecutionException;
import com.google.devtools.build.lib.actions.ActionExecutionMetadata;
import com.google.devtools.build.lib.actions.ActionKeyContext;
import com.google.devtools.build.lib.actions.ActionOwner;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
import com.google.devtools.build.lib.actions.EmptyRunfilesSupplier;
import com.google.devtools.build.lib.actions.MiddlemanType;
import com.google.devtools.build.lib.actions.RunfilesSupplier;
import com.google.devtools.build.lib.analysis.platform.ConstraintCollection.DuplicateConstraintException;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo.ExecPropertiesException;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import java.util.Collection;
import javax.annotation.Nullable;
import net.starlark.java.syntax.Location;

/** A fake implementation of ResourceOwner that does nothing except give output strings. */
public class FakeResourceOwner implements ActionExecutionMetadata {

private final String mnemonic;

public FakeResourceOwner(String mnemonic) {
this.mnemonic = mnemonic;
}

@Nullable
@Override
public String getProgressMessage() {
return "Progress on " + mnemonic;
}

@Nullable
@Override
public String describeKey() {
return "fake key";
}

@Override
public RunfilesSupplier getRunfilesSupplier() {
return EmptyRunfilesSupplier.INSTANCE;
}

@Override
public boolean inputsDiscovered() {
return false;
}

@Override
public boolean discoversInputs() {
return false;
}

@Override
public ActionOwner getOwner() {
return ActionOwner.create(
null,
ImmutableList.of(),
Location.BUILTIN,
"fake",
"fake target kind",
"fake",
null,
null,
ImmutableMap.of(),
null);
}

@Override
public boolean isShareable() {
return false;
}

@Override
public String getMnemonic() {
return mnemonic;
}

@Override
public String getKey(
ActionKeyContext actionKeyContext, @Nullable ArtifactExpander artifactExpander)
throws InterruptedException {
return "fake key";
}

@Override
public String prettyPrint() {
return mnemonic;
}

@Override
public String describe() {
return "Executing " + mnemonic;
}

@Override
public NestedSet<Artifact> getTools() {
return NestedSetBuilder.emptySet(Order.STABLE_ORDER);
}

@Override
public NestedSet<Artifact> getInputs() {
return NestedSetBuilder.emptySet(Order.STABLE_ORDER);
}

@Override
public Collection<String> getClientEnvironmentVariables() {
return ImmutableList.of();
}

@Override
public ImmutableSet<Artifact> getOutputs() {
return ImmutableSet.of();
}

@Override
public NestedSet<Artifact> getInputFilesForExtraAction(
ActionExecutionContext actionExecutionContext)
throws ActionExecutionException, InterruptedException {
return NestedSetBuilder.emptySet(Order.STABLE_ORDER);
}

@Override
public ImmutableSet<Artifact> getMandatoryOutputs() {
return ImmutableSet.of();
}

@Override
public Artifact getPrimaryInput() {
return null;
}

@Override
public Artifact getPrimaryOutput() {
return null;
}

@Override
public NestedSet<Artifact> getMandatoryInputs() {
return NestedSetBuilder.emptySet(Order.STABLE_ORDER);
}

@Override
public boolean shouldReportPathPrefixConflict(ActionAnalysisMetadata action) {
return false;
}

@Override
public MiddlemanType getActionType() {
return MiddlemanType.NORMAL;
}

@Override
public ImmutableMap<String, String> getExecProperties() {
return ImmutableMap.of();
}

@Nullable
@Override
public PlatformInfo getExecutionPlatform() {
try {
return PlatformInfo.builder().build();
} catch (DuplicateConstraintException | ExecPropertiesException e) {
return null;
}
}
}

0 comments on commit 5b1c12f

Please sign in to comment.