Skip to content

Commit

Permalink
Report action cache hit count as part of spawn stats summary.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 672526599
Change-Id: I7a22d28e9228f8ff64a169bd55c442828bc0b02c
  • Loading branch information
meisterT authored and copybara-github committed Sep 9, 2024
1 parent 9187a7e commit 84228ea
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.devtools.build.lib.actions.ActionCompletionEvent;
import com.google.devtools.build.lib.actions.ActionKeyContext;
import com.google.devtools.build.lib.actions.ActionResultReceivedEvent;
import com.google.devtools.build.lib.actions.cache.PostableActionCacheStats;
import com.google.devtools.build.lib.buildtool.BuildRequest;
import com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent;
import com.google.devtools.build.lib.buildtool.buildevent.ExecutionStartingEvent;
Expand Down Expand Up @@ -141,6 +142,11 @@ public void actionCompletion(ActionCompletionEvent event) {
spawnStats.incrementActionCount();
}

@Subscribe
public void actionCacheStats(PostableActionCacheStats event) {
spawnStats.recordActionCacheStats(event.asProto());
}

@Subscribe
public void buildComplete(BuildCompleteEvent event) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.Multiset;
import com.google.devtools.build.lib.actions.ActionResult;
import com.google.devtools.build.lib.actions.SpawnResult;
import com.google.devtools.build.lib.actions.cache.Protos.ActionCacheStatistics;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -39,6 +40,7 @@ public class SpawnStats {
private final ConcurrentHashMap<String, String> runnerExecKinds = new ConcurrentHashMap<>();
private final AtomicLong totalWallTimeMillis = new AtomicLong();
private final AtomicInteger totalNumberOfActions = new AtomicInteger();
private int actionCacheHitCount = 0;

public void countActionResult(ActionResult actionResult) {
for (SpawnResult r : actionResult.spawnResults()) {
Expand Down Expand Up @@ -66,6 +68,10 @@ public long getTotalWallTimeMillis() {
return totalWallTimeMillis.get();
}

public void recordActionCacheStats(ActionCacheStatistics actionCacheStatistics) {
actionCacheHitCount = actionCacheStatistics.getHits();
}

/*
* Returns a human-readable summary of spawns counted.
*/
Expand All @@ -83,6 +89,9 @@ public ImmutableMap<String, Integer> getSummary(ImmutableList<String> reportFirs
result.put("total", numActionsTotal);

// First report cache results.
if (actionCacheHitCount > 0) {
result.put("action cache hit", actionCacheHitCount);
}
for (String s : reportFirst) {
int count = runners.setCount(s, 0);
if (count > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/cc_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ function test_external_cc_test_local_sibling_repository_layout() {
--strategy=local \
--experimental_sibling_repository_layout \
@other_repo//test >& $TEST_log || fail "Test should pass"
expect_log "1 process: 1 internal"
expect_log "1 process: .*1 internal"
}

function test_bazel_current_repository_define() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/shell/bazel/remote/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ EOF

# The same value of --remote_default_platform_properties should NOT invalidate SkyFrames on-disk cache
# and the action should not be re-run.
expect_log "1 process: 1 internal"
expect_log "1 process: .*1 internal"

bazel build \
--remote_executor=grpc://localhost:${worker_port} \
Expand Down Expand Up @@ -1337,7 +1337,7 @@ EOF

# Changing --remote_default_platform_properties value does not invalidate SkyFrames
# given its is superseded by the platform exec_properties.
expect_log "1 process: 1 internal."
expect_log "1 process: .*1 internal."
}

function test_platform_default_properties_invalidation_with_platform_remote_execution_properties() {
Expand Down

0 comments on commit 84228ea

Please sign in to comment.