forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Post AnalysisPhaseCompleteEvent for Skymeld.
Many classes, especially the ones collecting metrics around a build, rely on AnalysisPhaseCompleteEvent. For Skymeld, that is problematic since we don't have a clear boundary between analysis/execution. With this cl, we redefine the meaning of AnalysisPhaseCompleteEvent with --skymeld: it's the moment when all analysis-related work is concluded in the build, and blaze is expected to already be deep in execution work when this moment happens. This also means that BEP's analysis_phase_time_in_ms [1] keeps its original meaning with Skymeld: it's the wall time duration between the start and the end of analysis. The difference: it's no longer true that total wall time = analysis wall time + execution wall time, as analysis and execution overlap. To implement this, we introduce AnalysisOperationWatcher, which: - Has a pre-filled expected set of BuildDriverKeys, - Listens to TopLevelEntityAnalysisConcludedEvents which include information of the respective BuildDriverKey, - Removes the BuildDriverKey from the expected set upon receiving the events, and - Posts an AnalysisPhaseCompleteEvent when the expected set is empty. The analysis work of a top level target is considered "concluded" when its analysis either fails or succeeds (which also includes work outside of the main Skyframe evaluation, like action conflict checking and compatibility checking). In case of --nokeep_going and an analysis error occurs, there's no AnalysisPhaseCompleteEvent. This is consistent with the behavior of --noskymeld in the same scenario. [1] https://github.com/bazelbuild/bazel/blob/1941e2b1b5be8596e984b02fd5dd37e3ed25a81f/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto#L948 PiperOrigin-RevId: 461154740 Change-Id: I731c817280e66a6aad3781cc578c60a708a56ceb
- Loading branch information
1 parent
6b50773
commit 6a6d1b2
Showing
15 changed files
with
478 additions
and
111 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/main/java/com/google/devtools/build/lib/analysis/AnalysisOperationWatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2022 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.analysis; | ||
|
||
import com.google.common.eventbus.EventBus; | ||
import com.google.common.eventbus.Subscribe; | ||
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TopLevelEntityAnalysisConcludedEvent; | ||
import com.google.devtools.build.skyframe.SkyKey; | ||
import java.util.Set; | ||
|
||
/** | ||
* A watcher for analysis-related work that sends out a signal when all such work in the build is | ||
* done. There's one instance of this class per build. | ||
*/ | ||
public class AnalysisOperationWatcher implements AutoCloseable { | ||
// Since the events are fired from within a SkyFunction, it's possible that the same event is | ||
// fired multiple times. A simple counter would therefore not suffice. | ||
private final Set<SkyKey> threadSafeExpectedKeys; | ||
private final EventBus eventBus; | ||
private final AnalysisOperationWatcherFinisher finisher; | ||
|
||
private AnalysisOperationWatcher( | ||
Set<SkyKey> threadSafeExpectedKeys, | ||
EventBus eventBus, | ||
AnalysisOperationWatcherFinisher finisher) { | ||
this.threadSafeExpectedKeys = threadSafeExpectedKeys; | ||
this.eventBus = eventBus; | ||
this.finisher = finisher; | ||
} | ||
|
||
/** Creates an AnalysisOperationWatcher and registers it with the provided eventBus. */ | ||
public static AnalysisOperationWatcher createAndRegisterWithEventBus( | ||
Set<SkyKey> threadSafeExpectedKeys, | ||
EventBus eventBus, | ||
AnalysisOperationWatcherFinisher finisher) { | ||
AnalysisOperationWatcher watcher = | ||
new AnalysisOperationWatcher(threadSafeExpectedKeys, eventBus, finisher); | ||
eventBus.register(watcher); | ||
return watcher; | ||
} | ||
|
||
@Subscribe | ||
public void handleTopLevelEntityAnalysisConcluded(TopLevelEntityAnalysisConcludedEvent e) { | ||
if (threadSafeExpectedKeys.isEmpty()) { | ||
return; | ||
} | ||
threadSafeExpectedKeys.remove(e.getAnalyzedTopLevelKey()); | ||
if (threadSafeExpectedKeys.isEmpty()) { | ||
finisher.sendAnalysisPhaseCompleteEvent(); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
eventBus.unregister(this); | ||
} | ||
|
||
/** A callback to be called when all the expected keys have been analyzed. */ | ||
@FunctionalInterface | ||
public interface AnalysisOperationWatcherFinisher { | ||
void sendAnalysisPhaseCompleteEvent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.