Skip to content

Commit

Permalink
Only enable analysis caching during analysis when mode is DOWNLOAD.
Browse files Browse the repository at this point in the history
When in UPLOAD, analysis caching should only be active during the frontier
upload.

PiperOrigin-RevId: 676402923
Change-Id: I0fada7c07b1a0be5f8ec5e3355f0b9166cb1c110
  • Loading branch information
aoeui authored and copybara-github committed Sep 19, 2024
1 parent c442bb5 commit 0313b4a
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.evaluateProjectFile;
import static com.google.devtools.build.lib.skyframe.serialization.analysis.RemoteAnalysisCachingOptions.RemoteAnalysisCacheMode.DOWNLOAD;
import static com.google.devtools.build.lib.skyframe.serialization.analysis.RemoteAnalysisCachingOptions.RemoteAnalysisCacheMode.OFF;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
Expand Down Expand Up @@ -234,7 +235,7 @@ public void buildTargets(BuildRequest request, BuildResult result, TargetValidat
evaluateProjectFile(request, buildOptions, targetPatternPhaseValue, env);

var analysisCachingDeps =
RemoteAnalysisCachingDependenciesProviderImpl.create(
RemoteAnalysisCachingDependenciesProviderImpl.forAnalysis(
env, projectEvaluationResult.activeDirectoriesMatcher());

if (env.withMergedAnalysisAndExecutionSourceOfTruth()) {
Expand All @@ -254,7 +255,8 @@ public void buildTargets(BuildRequest request, BuildResult result, TargetValidat
analysisCachingDeps);
}

logAnalysisCachingStatsAndMaybeUploadFrontier(request, analysisCachingDeps);
logAnalysisCachingStatsAndMaybeUploadFrontier(
request, projectEvaluationResult.activeDirectoriesMatcher());

if (env.getSkyframeExecutor().getSkyfocusState().enabled()) {
// Skyfocus only works at the end of a successful build.
Expand Down Expand Up @@ -837,7 +839,7 @@ public BuildResult processRequest(
* </ol>
*/
private void logAnalysisCachingStatsAndMaybeUploadFrontier(
BuildRequest request, RemoteAnalysisCachingDependenciesProvider analysisCachingDeps)
BuildRequest request, Optional<PathFragmentPrefixTrie> activeDirectoriesMatcher)
throws InterruptedException, AbruptExitException {
if (!(env.getSkyframeExecutor() instanceof SequencedSkyframeExecutor)) {
return;
Expand All @@ -850,12 +852,15 @@ private void logAnalysisCachingStatsAndMaybeUploadFrontier(

switch (options.mode) {
case UPLOAD -> {
if (!activeDirectoriesMatcher.isPresent()) {
return;
}
try (SilentCloseable closeable =
Profiler.instance().profile("serializeAndUploadFrontier")) {
Preconditions.checkState(analysisCachingDeps.enabled());
Optional<FailureDetail> maybeFailureDetail =
FrontierSerializer.serializeAndUploadFrontier(
analysisCachingDeps,
new RemoteAnalysisCachingDependenciesProviderImpl(
env, activeDirectoriesMatcher.get()),
env.getSkyframeExecutor(),
env.getReporter(),
env.getEventBus(),
Expand Down Expand Up @@ -1109,13 +1114,12 @@ private static final class RemoteAnalysisCachingDependenciesProviderImpl
private final PathFragmentPrefixTrie activeDirectoriesMatcher;
private final RemoteAnalysisCachingEventListener listener;

public static RemoteAnalysisCachingDependenciesProvider create(
public static RemoteAnalysisCachingDependenciesProvider forAnalysis(
CommandEnvironment env, Optional<PathFragmentPrefixTrie> activeDirectoriesMatcher) {
var options = env.getOptions().getOptions(RemoteAnalysisCachingOptions.class);
if (options == null || options.mode == OFF || activeDirectoriesMatcher.isEmpty()) {
if (options == null || options.mode != DOWNLOAD || activeDirectoriesMatcher.isEmpty()) {
return DisabledDependenciesProvider.INSTANCE;
}

return new RemoteAnalysisCachingDependenciesProviderImpl(env, activeDirectoriesMatcher.get());
}

Expand Down

0 comments on commit 0313b4a

Please sign in to comment.