Skip to content

Commit

Permalink
Emit remote configured aspect cache hits in UIStateTracker.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 697622802
Change-Id: I855ec6117e5349215094aa3a444718628a84f046
  • Loading branch information
jin authored and copybara-github committed Nov 18, 2024
1 parent 59f0d12 commit 938a010
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,41 @@
public class AnalysisProgressReceiver {

private final AtomicInteger configuredTargetsCompleted = new AtomicInteger();

private final AtomicInteger configuredTargetsFetched = new AtomicInteger();

private final AtomicInteger configuredTargetsDownloaded = new AtomicInteger();
private final AtomicInteger configuredAspectsCompleted = new AtomicInteger();
private final AtomicInteger configuredAspectsDownloaded = new AtomicInteger();

/** Register that a target has been configured. */
void doneConfigureTarget() {
configuredTargetsCompleted.incrementAndGet();
}

/** Register that a configured target has been downloaded from a remote cache. */
void doneFetchedTarget() {
void doneDownloadedConfiguredTarget() {
configuredTargetsCompleted.incrementAndGet();
configuredTargetsFetched.incrementAndGet();
configuredTargetsDownloaded.incrementAndGet();
}

/** Register that a aspect has been configured. */
void doneConfigureAspect() {
configuredAspectsCompleted.incrementAndGet();
}

/** Register that a configured target has been downloaded from a remote cache. */
void doneDownloadedConfiguredAspect() {
configuredAspectsCompleted.incrementAndGet();
configuredAspectsDownloaded.incrementAndGet();
}

/**
* Reset all instance variables of this object to a state equal to that of a newly
* constructed object.
*/
public void reset() {
configuredTargetsCompleted.set(0);
configuredTargetsFetched.set(0);
configuredTargetsDownloaded.set(0);
configuredAspectsCompleted.set(0);
configuredAspectsDownloaded.set(0);
}

/**
Expand All @@ -62,12 +68,15 @@ public void reset() {
public String getProgressString() {
String progress = "" + configuredTargetsCompleted + " ";
progress += (configuredTargetsCompleted.get() != 1) ? "targets" : "target";
if (configuredTargetsFetched.get() > 1) {
progress += " (" + configuredTargetsFetched + " cache hits)";
if (configuredTargetsDownloaded.get() > 0) {
progress += " (" + configuredTargetsDownloaded + " remote cache hits)";
}
if (configuredAspectsCompleted.get() > 0) {
progress += " and " + configuredAspectsCompleted + " ";
progress += (configuredAspectsCompleted.get() != 1) ? "aspects" : "aspect";
if (configuredAspectsDownloaded.get() > 0) {
progress += " (" + configuredAspectsDownloaded + " remote cache hits)";
}
}
progress += " configured";
return progress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
case SkyValueRetriever.Restart unused:
return null;
case SkyValueRetriever.RetrievedValue v:
analysisProgressReceiver.doneDownloadedConfiguredAspect();
return v.value();
case SkyValueRetriever.NoCachedData unused:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public SkyValue compute(SkyKey key, Environment env)
case SkyValueRetriever.Restart unused:
return null;
case SkyValueRetriever.RetrievedValue v:
analysisProgress.doneFetchedTarget();
analysisProgress.doneDownloadedConfiguredTarget();
return v.value();
case SkyValueRetriever.NoCachedData unused:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ public void testTargetCounted() {
.isTrue();
}

@Test
public void testDownloadedTargetCounted() {
AnalysisProgressReceiver progress = new AnalysisProgressReceiver();
progress.doneDownloadedConfiguredTarget();
String progressString1 = progress.getProgressString();

assertThat(progressString1).contains("1 target (1 remote cache hits) configured");

progress.doneConfigureTarget();
String progressString2 = progress.getProgressString();

assertThat(progressString2).contains("2 targets (1 remote cache hits) configured");
}

@Test
public void testAspectCounted() {
AnalysisProgressReceiver progress = new AnalysisProgressReceiver();
Expand All @@ -61,6 +75,21 @@ public void testAspectCounted() {
.isTrue();
}

@Test
public void testDownloadedAspectCounted() {
AnalysisProgressReceiver progress = new AnalysisProgressReceiver();
progress.doneDownloadedConfiguredAspect();
String progressString1 = progress.getProgressString();

assertThat(progressString1).contains("0 targets and 1 aspect (1 remote cache hits) configured");

progress.doneConfigureAspect();
String progressString2 = progress.getProgressString();

assertThat(progressString2)
.contains("0 targets and 2 aspects (1 remote cache hits) configured");
}

@Test
public void testTargetAndAspectCounted() {
AnalysisProgressReceiver progress = new AnalysisProgressReceiver();
Expand Down

0 comments on commit 938a010

Please sign in to comment.