Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2a5bfd0

Browse files
jincopybara-github
authored andcommittedMay 5, 2025·
Remove get{Analysis/Execution}Cache{Hits/Misses} methods in favor of grouping by SkyFunctions.
Filter at the callsite by class/SkyFunction instead for more precision. PiperOrigin-RevId: 754861275 Change-Id: I7a5235745b15f8a2ee698dfb9aae22bd9d64e857
1 parent 5162b5f commit 2a5bfd0

File tree

3 files changed

+19
-73
lines changed

3 files changed

+19
-73
lines changed
 

‎src/main/java/com/google/devtools/build/lib/skyframe/serialization/analysis/FrontierViolationChecker.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ public static RemoteAnalysisCachingDependenciesProvider check(
196196

197197
public static void accumulateCacheHitsAcrossInvocations(
198198
RemoteAnalysisCachingEventListener listener) {
199-
accumulatedCacheHits.getAndAdd(listener.getAnalysisNodeCacheHits());
200-
accumulatedCacheHits.getAndAdd(listener.getExecutionNodeCacheHits());
199+
accumulatedCacheHits.getAndAdd(listener.getCacheHits().size());
201200
}
202201

203202
/**

‎src/main/java/com/google/devtools/build/lib/skyframe/serialization/analysis/RemoteAnalysisCachingEventListener.java

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.google.devtools.build.lib.skyframe.serialization.SkyValueRetriever.Restart;
3030
import com.google.devtools.build.lib.skyframe.serialization.SkyValueRetriever.RetrievalResult;
3131
import com.google.devtools.build.lib.skyframe.serialization.SkyValueRetriever.RetrievedValue;
32-
import com.google.devtools.build.skyframe.ExecutionPhaseSkyKey;
3332
import com.google.devtools.build.skyframe.SkyFunctionName;
3433
import com.google.devtools.build.skyframe.SkyKey;
3534
import java.util.Set;
@@ -54,10 +53,6 @@ public record SerializedNodeEvent(SkyKey key) {
5453
private final Set<SkyKey> serializedKeys = ConcurrentHashMap.newKeySet();
5554
private final Set<SkyKey> cacheHits = ConcurrentHashMap.newKeySet();
5655
private final Set<SkyKey> cacheMisses = ConcurrentHashMap.newKeySet();
57-
private final AtomicInteger analysisCacheHits = new AtomicInteger();
58-
private final AtomicInteger analysisCacheMisses = new AtomicInteger();
59-
private final AtomicInteger executionCacheHits = new AtomicInteger();
60-
private final AtomicInteger executionCacheMisses = new AtomicInteger();
6156
private final Set<SerializationException> serializationExceptions = ConcurrentHashMap.newKeySet();
6257
private final ConcurrentHashMap<SkyFunctionName, AtomicInteger> hitsBySkyFunctionName =
6358
new ConcurrentHashMap<>();
@@ -103,77 +98,29 @@ public void recordRetrievalResult(RetrievalResult result, SkyKey key) {
10398
return;
10499
}
105100

106-
SkyFunctionName functionName = key.functionName(); // Get the function name
107-
108101
switch (result) {
109102
case RetrievedValue unusedValue -> {
110103
if (!cacheHits.add(key)) {
111104
return;
112105
}
113106
hitsBySkyFunctionName
114-
.computeIfAbsent(functionName, k -> new AtomicInteger())
107+
.computeIfAbsent(key.functionName(), k -> new AtomicInteger())
115108
.incrementAndGet();
116-
if (isExecutionNode(key)) {
117-
executionCacheHits.incrementAndGet();
118-
} else {
119-
analysisCacheHits.incrementAndGet();
120-
}
121109
}
122110
case NoCachedData unusedNoCachedData -> {
123111
if (!cacheMisses.add(key)) {
124112
return;
125113
}
126114
missesBySkyFunctionName
127-
.computeIfAbsent(functionName, k -> new AtomicInteger())
115+
.computeIfAbsent(key.functionName(), k -> new AtomicInteger())
128116
.incrementAndGet();
129-
if (isExecutionNode(key)) {
130-
executionCacheMisses.incrementAndGet();
131-
} else {
132-
analysisCacheMisses.incrementAndGet();
133-
}
134117
}
135118
case Restart unusedRestart ->
136119
throw new IllegalStateException(
137120
"should have returned earlier"); // restart counts are not useful (yet).
138121
}
139122
}
140123

141-
private static boolean isExecutionNode(SkyKey key) {
142-
return key instanceof ExecutionPhaseSkyKey;
143-
}
144-
145-
/**
146-
* Returns the number of successful analysis SkyValue retrievals from the {@link
147-
* com.google.devtools.build.lib.skyframe.serialization.FingerprintValueService} .
148-
*/
149-
public int getAnalysisNodeCacheHits() {
150-
return analysisCacheHits.get();
151-
}
152-
153-
/**
154-
* Returns the number of successful analysis SkyValue retrievals from the {@link
155-
* com.google.devtools.build.lib.skyframe.serialization.FingerprintValueService} .
156-
*/
157-
public int getAnalysisNodeCacheMisses() {
158-
return analysisCacheMisses.get();
159-
}
160-
161-
/**
162-
* Returns the number of unsuccessful execution SkyValue retrievals from the {@link
163-
* com.google.devtools.build.lib.skyframe.serialization.FingerprintValueService} .
164-
*/
165-
public int getExecutionNodeCacheHits() {
166-
return executionCacheHits.get();
167-
}
168-
169-
/**
170-
* Returns the number of unsuccessful execution SkyValue retrievals from the {@link
171-
* com.google.devtools.build.lib.skyframe.serialization.FingerprintValueService} .
172-
*/
173-
public int getExecutionNodeCacheMisses() {
174-
return executionCacheMisses.get();
175-
}
176-
177124
/** Returns the number of cache hits grouped by SkyFunction name. */
178125
public ImmutableMap<SkyFunctionName, AtomicInteger> getHitsBySkyFunctionName() {
179126
return ImmutableMap.copyOf(hitsBySkyFunctionName);

‎src/test/java/com/google/devtools/build/lib/skyframe/serialization/analysis/FrontierSerializerTestBase.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ public void buildCommand_downloadsFrontierBytesWithDownloadMode() throws Excepti
441441

442442
var listener = getCommandEnvironment().getRemoteAnalysisCachingEventListener();
443443
// //bar:C, //bar:H, //bar:E
444-
assertThat(listener.getAnalysisNodeCacheHits()).isEqualTo(3);
444+
assertThat(listener.getCacheHits()).hasSize(3);
445445
// //bar:F is not in the project boundary, but it's in the active set, so it wasn't cached.
446-
assertThat(listener.getAnalysisNodeCacheMisses()).isAtLeast(1);
446+
assertThat(listener.getCacheMisses()).isNotEmpty();
447447
}
448448

449449
@Test
@@ -691,20 +691,6 @@ protected void setupScenarioWithConfiguredTargets() throws Exception {
691691
""");
692692
}
693693

694-
protected static <T> ImmutableSet<T> filterKeys(Set<SkyKey> from, Class<? extends T> klass) {
695-
return from.stream().filter(klass::isInstance).map(klass::cast).collect(toImmutableSet());
696-
}
697-
698-
protected static ImmutableSet<Label> getLabels(Set<ActionLookupKey> from) {
699-
return from.stream().map(ActionLookupKey::getLabel).collect(toImmutableSet());
700-
}
701-
702-
protected static ImmutableSet<Label> getOwningLabels(Set<ActionLookupData> from) {
703-
return from.stream()
704-
.map(data -> data.getActionLookupKey().getLabel())
705-
.collect(toImmutableSet());
706-
}
707-
708694
@Test
709695
public void actionLookupKey_underTheFrontier_areNotUploaded() throws Exception {
710696
setupGenruleGraph();
@@ -1254,4 +1240,18 @@ public void workspaceInit(
12541240
builder.setSyscallCache(syscallCache);
12551241
}
12561242
}
1243+
1244+
protected static <T> ImmutableSet<T> filterKeys(Set<SkyKey> from, Class<? extends T> klass) {
1245+
return from.stream().filter(klass::isInstance).map(klass::cast).collect(toImmutableSet());
1246+
}
1247+
1248+
protected static ImmutableSet<Label> getLabels(Set<ActionLookupKey> from) {
1249+
return from.stream().map(ActionLookupKey::getLabel).collect(toImmutableSet());
1250+
}
1251+
1252+
protected static ImmutableSet<Label> getOwningLabels(Set<ActionLookupData> from) {
1253+
return from.stream()
1254+
.map(data -> data.getActionLookupKey().getLabel())
1255+
.collect(toImmutableSet());
1256+
}
12571257
}

0 commit comments

Comments
 (0)
Please sign in to comment.