Skip to content

Commit

Permalink
Remote: Add remoteCacheHits to BEP BuildMetrics.
Browse files Browse the repository at this point in the history
Fixes #7714.

Closes #13563.

PiperOrigin-RevId: 378316476
  • Loading branch information
coeuvre authored and copybara-github committed Jun 9, 2021
1 parent 43ba582 commit 95c7931
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,9 @@ message BuildMetrics {
// remote cache hits, but excludes local action cache hits.
int64 actions_executed = 2;

// The total number of remote cache hits.
int64 remote_cache_hits = 5;

message ActionData {
string mnemonic = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
// limitations under the License.
package com.google.devtools.build.lib.metrics;

import com.google.common.collect.ImmutableMap;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import com.google.devtools.build.lib.actions.ActionCompletionEvent;
import com.google.devtools.build.lib.actions.ActionResultReceivedEvent;
import com.google.devtools.build.lib.actions.AnalysisGraphStatsEvent;
import com.google.devtools.build.lib.actions.TotalAndConfiguredTargetOnlyMetric;
import com.google.devtools.build.lib.analysis.AnalysisPhaseCompleteEvent;
Expand All @@ -39,6 +41,7 @@
import com.google.devtools.build.lib.metrics.PostGCMemoryUseRecorder.PeakHeap;
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
import com.google.devtools.build.lib.runtime.SpawnStats;
import com.google.devtools.build.lib.skyframe.ExecutionFinishedEvent;
import com.google.devtools.build.skyframe.SkyframeGraphStatsEvent;
import java.lang.management.ManagementFactory;
Expand Down Expand Up @@ -70,7 +73,6 @@ class MetricsCollector {
private final boolean bepPublishUsedHeapSizePostBuild;
private final boolean recordMetricsForAllMnemonics;
// For ActionSummary.
private final AtomicLong executedActionCount = new AtomicLong();
private final ConcurrentHashMap<String, ActionStats> actionStatsMap = new ConcurrentHashMap<>();

// For CumulativeMetrics.
Expand All @@ -83,6 +85,7 @@ class MetricsCollector {
private final TimingMetrics.Builder timingMetrics = TimingMetrics.newBuilder();
private final ArtifactMetrics.Builder artifactMetrics = ArtifactMetrics.newBuilder();
private final BuildGraphMetrics.Builder buildGraphMetrics = BuildGraphMetrics.newBuilder();
private final SpawnStats spawnStats = new SpawnStats();

private MetricsCollector(
CommandEnvironment env, AtomicInteger numAnalyses, AtomicInteger numBuilds) {
Expand Down Expand Up @@ -147,12 +150,18 @@ public synchronized void logExecutionStartingEvent(ExecutionStartingEvent event)
@Subscribe
@AllowConcurrentEvents
public void onActionComplete(ActionCompletionEvent event) {
executedActionCount.incrementAndGet();
ActionStats actionStats =
actionStatsMap.computeIfAbsent(event.getAction().getMnemonic(), ActionStats::new);
actionStats.numActions.incrementAndGet();
actionStats.firstStarted.accumulate(event.getRelativeActionStartTime());
actionStats.lastEnded.accumulate(BlazeClock.nanoTime());
spawnStats.incrementActionCount();
}

@Subscribe
@AllowConcurrentEvents
public void actionResultReceived(ActionResultReceivedEvent event) {
spawnStats.countActionResult(event.getActionResult());
}

@SuppressWarnings("unused")
Expand Down Expand Up @@ -215,7 +224,10 @@ private ActionSummary finishActionSummary() {
action.lastEnded.longValue()))
.setActionsExecuted(action.numActions.get())
.build()));
return actionSummary.setActionsExecuted(executedActionCount.get()).build();
ImmutableMap<String, Integer> spawnSummary = spawnStats.getSummary();
Integer total = spawnSummary.getOrDefault("total", 0);
Integer remoteCacheHits = spawnSummary.getOrDefault("remote cache hit", 0);
return actionSummary.setActionsExecuted(total).setRemoteCacheHits(remoteCacheHits).build();
}

private MemoryMetrics createMemoryMetrics() {
Expand Down

0 comments on commit 95c7931

Please sign in to comment.