Skip to content

Commit

Permalink
Add exec_kind to RunnerCount in BEP
Browse files Browse the repository at this point in the history
Solves bazelbuild#17296 .

The execution kind of runners is now stored in the RunnerCount message of the Build Event Protocol. For runners where execution kind is not applicable, e.g. "total", no value is set. The exec_kind field has been set as a string field rather than using an enum to avoid implicit dependencies between the Java code and the protobuf.

Closes bazelbuild#17585.

PiperOrigin-RevId: 524281812
Change-Id: I55518886f976397db58e71b0b34b32cf287e3d51
  • Loading branch information
crydell-ericsson authored and fweikert committed May 25, 2023
1 parent 8db7cc3 commit a83e3a8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ message BuildMetrics {
message RunnerCount {
string name = 1;
int32 count = 2;
string exec_kind = 3;
}
repeated RunnerCount runner_count = 6;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,15 @@ private ActionSummary finishActionSummary() {
spawnSummary
.entrySet()
.forEach(
e ->
actionSummary.addRunnerCount(
RunnerCount.newBuilder().setName(e.getKey()).setCount(e.getValue()).build()));
e -> {
RunnerCount.Builder builder = RunnerCount.newBuilder();
builder.setName(e.getKey()).setCount(e.getValue());
String execKind = spawnStats.getExecKindFor(e.getKey());
if (execKind != null) {
builder.setExecKind(execKind);
}
actionSummary.addRunnerCount(builder.build());
});
return actionSummary.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import javax.annotation.concurrent.ThreadSafe;
Expand All @@ -35,11 +36,13 @@ public class SpawnStats {
ImmutableList.of("disk cache hit", "remote cache hit");

private final ConcurrentHashMultiset<String> runners = ConcurrentHashMultiset.create();
private final ConcurrentHashMap<String, String> runnerExecKinds = new ConcurrentHashMap<>();
private final AtomicLong totalWallTimeMillis = new AtomicLong();
private final AtomicInteger totalNumberOfActions = new AtomicInteger();

public void countActionResult(ActionResult actionResult) {
for (SpawnResult r : actionResult.spawnResults()) {
storeRunnerExecKind(r);
countRunnerName(r.getRunnerName());
totalWallTimeMillis.addAndGet(r.getMetrics().executionWallTimeInMs());
}
Expand All @@ -49,6 +52,12 @@ public void countRunnerName(String runner) {
runners.add(runner);
}

private void storeRunnerExecKind(SpawnResult r) {
String name = r.getRunnerName();
String execKind = r.getMetrics().execKind().toString();
runnerExecKinds.put(name, execKind);
}

public void incrementActionCount() {
totalNumberOfActions.incrementAndGet();
}
Expand Down Expand Up @@ -97,6 +106,10 @@ public ImmutableMap<String, Integer> getSummary(ImmutableList<String> reportFirs
return result.buildOrThrow();
}

public String getExecKindFor(String runnerName) {
return runnerExecKinds.getOrDefault(runnerName, null);
}

public static String convertSummaryToString(ImmutableMap<String, Integer> spawnSummary) {
Integer total = spawnSummary.get("total");
if (total == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.common.truth.Truth.assertThat;

import com.google.devtools.build.lib.actions.ActionResult;
import com.google.devtools.build.lib.actions.SpawnMetrics;
import com.google.devtools.build.lib.actions.SpawnResult;
import java.util.ArrayList;
import org.junit.Before;
Expand Down Expand Up @@ -215,4 +216,26 @@ public void orderCacheInternalRest() {
assertThat(SpawnStats.convertSummaryToString(stats.getSummary()))
.isEqualTo("11 processes: 1 remote cache hit, 2 internal, 3 a, 2 b, 1 c, 2 z.");
}

private final SpawnResult rC =
new SpawnResult.Builder()
.setStatus(SpawnResult.Status.SUCCESS)
.setSpawnMetrics(SpawnMetrics.Builder.forExec(SpawnMetrics.ExecKind.OTHER).build())
.setRunnerName("fgh")
.build();

@Test
public void getExecKindDefined() {
ArrayList<SpawnResult> spawns = new ArrayList<>();
spawns.add(rC);
stats.countActionResult(ActionResult.create(spawns));
assertThat(stats.getExecKindFor("fgh")).isEqualTo(SpawnMetrics.ExecKind.OTHER.toString());
}

@Test
public void getExecKindNotDefined() {
var unused = stats.getSummary();
assertThat(stats.getExecKindFor("total")).isNull();
assertThat(stats.getExecKindFor("internal")).isNull();
}
}

0 comments on commit a83e3a8

Please sign in to comment.