@@ -362,7 +362,9 @@ public void clearAnalysisCache(
362
362
ImmutableSet <ConfiguredTarget > topLevelTargets , ImmutableSet <AspectKey > topLevelAspects ) {
363
363
// TODO(bazel-team): Consider clearing packages too to save more memory.
364
364
skyframeAnalysisWasDiscarded = true ;
365
- skyframeExecutor .clearAnalysisCache (topLevelTargets , topLevelAspects );
365
+ try (SilentCloseable c = Profiler .instance ().profile ("skyframeExecutor.clearAnalysisCache" )) {
366
+ skyframeExecutor .clearAnalysisCache (topLevelTargets , topLevelAspects );
367
+ }
366
368
}
367
369
368
370
/**
@@ -633,7 +635,8 @@ public SkyframeAnalysisResult analyzeAndExecuteTargets(
633
635
boolean checkForActionConflicts ,
634
636
int numThreads ,
635
637
int cpuHeavySkyKeysThreadPoolSize ,
636
- int mergedPhasesExecutionJobsCount )
638
+ int mergedPhasesExecutionJobsCount ,
639
+ boolean shouldDiscardAnalysisCache )
637
640
throws InterruptedException , ViewCreationFailedException , BuildFailedException ,
638
641
TestExecException {
639
642
enableAnalysis (true );
@@ -683,14 +686,11 @@ public SkyframeAnalysisResult analyzeAndExecuteTargets(
683
686
Sets .newConcurrentHashSet (Sets .union (buildDriverCTKeys , buildDriverAspectKeys )),
684
687
eventBus ,
685
688
/*finisher=*/ () ->
686
- eventBus .post (
687
- AnalysisPhaseCompleteEvent .fromSkymeld (
688
- buildResultListener .getAnalyzedTargets (),
689
- getEvaluatedCounts (),
690
- getEvaluatedActionCounts (),
691
- analysisWorkTimer .stop ().elapsed ().toMillis (),
692
- skyframeExecutor .getPackageManager ().getAndClearStatistics (),
693
- skyframeExecutor .wasAnalysisCacheInvalidatedAndResetBit ())))) {
689
+ analysisFinishedCallback (
690
+ eventBus ,
691
+ buildResultListener ,
692
+ shouldDiscardAnalysisCache ,
693
+ /*measuredAnalysisTime=*/ analysisWorkTimer .stop ().elapsed ().toMillis ()))) {
694
694
695
695
try {
696
696
resourceManager .resetResourceUsage ();
@@ -814,6 +814,27 @@ public SkyframeAnalysisResult analyzeAndExecuteTargets(
814
814
}
815
815
}
816
816
817
+ /** Handles the required steps after all analysis work in this build is done. */
818
+ private void analysisFinishedCallback (
819
+ EventBus eventBus ,
820
+ BuildResultListener buildResultListener ,
821
+ boolean shouldDiscardAnalysisCache ,
822
+ long measuredAnalysisTime ) {
823
+ if (shouldDiscardAnalysisCache ) {
824
+ clearAnalysisCache (
825
+ buildResultListener .getAnalyzedTargets (),
826
+ buildResultListener .getAnalyzedAspects ().keySet ());
827
+ }
828
+ eventBus .post (
829
+ AnalysisPhaseCompleteEvent .fromSkymeld (
830
+ buildResultListener .getAnalyzedTargets (),
831
+ getEvaluatedCounts (),
832
+ getEvaluatedActionCounts (),
833
+ measuredAnalysisTime ,
834
+ skyframeExecutor .getPackageManager ().getAndClearStatistics (),
835
+ skyframeExecutor .wasAnalysisCacheInvalidatedAndResetBit ()));
836
+ }
837
+
817
838
/**
818
839
* Report the appropriate conflicts and return a TopLevelActionConflictReport.
819
840
*
0 commit comments