Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 20d29c8

Browse files
record cas findMissing requests to the buck_builds scuba table
Summary: Currently we report only uploads and downloads, however findMissing request can also be costly, and it would be good to report it as well. Reviewed By: stepancheg fbshipit-source-id: 01b32280713dc9d4b5d1e2c1587996ddcecd5a90
1 parent 3f69298 commit 20d29c8

File tree

4 files changed

+105
-4
lines changed

4 files changed

+105
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.facebook.buck.remoteexecution.event;
18+
19+
import com.facebook.buck.event.AbstractBuckEvent;
20+
import com.facebook.buck.event.BuckEventBus;
21+
import com.facebook.buck.event.EventKey;
22+
import com.facebook.buck.event.WorkAdvanceEvent;
23+
import com.facebook.buck.util.Scope;
24+
25+
/** Started/Finished event pairs for CAS findMissing requests. */
26+
public abstract class CasFindMissingEvent extends AbstractBuckEvent implements WorkAdvanceEvent {
27+
28+
protected CasFindMissingEvent(EventKey eventKey) {
29+
super(eventKey);
30+
}
31+
32+
/** Send the Started and returns a Scoped object that sends the Finished event. */
33+
public static Scope sendEvent(final BuckEventBus eventBus, int blobCount) {
34+
final CasFindMissingEvent.Started startedEvent = new CasFindMissingEvent.Started(blobCount);
35+
eventBus.post(startedEvent);
36+
return () -> eventBus.post(new CasFindMissingEvent.Finished(startedEvent));
37+
}
38+
39+
/** FindMissing call has started. */
40+
public static final class Started extends CasFindMissingEvent {
41+
private final int blobCount;
42+
43+
public Started(int blobCount) {
44+
super(EventKey.unique());
45+
this.blobCount = blobCount;
46+
}
47+
48+
public int getBlobCount() {
49+
return blobCount;
50+
}
51+
52+
@Override
53+
protected String getValueString() {
54+
return String.format("blobCount=[%d]", getBlobCount());
55+
}
56+
}
57+
58+
/** FindMissing call has finished. */
59+
public static class Finished extends CasFindMissingEvent {
60+
private final Started startedEvent;
61+
62+
public Finished(Started startedEvent) {
63+
super(startedEvent.getEventKey());
64+
this.startedEvent = startedEvent;
65+
}
66+
67+
public Started getStartedEvent() {
68+
return startedEvent;
69+
}
70+
71+
@Override
72+
protected String getValueString() {
73+
return getStartedEvent().getValueString();
74+
}
75+
}
76+
77+
@Override
78+
public String getEventName() {
79+
return getClass().getSimpleName();
80+
}
81+
}

src/com/facebook/buck/remoteexecution/event/RemoteExecutionStatsProvider.java

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public interface RemoteExecutionStatsProvider {
3737
/** Total of uploaded bytes to CAS. */
3838
long getCasUploadSizeBytes();
3939

40+
/** Total number of digests that were sent in findMissing calls. */
41+
long getCasFindMissingCount();
42+
4043
/** Get the total number of BuildRules that are finished. (both local and remote) */
4144
int getTotalRulesBuilt();
4245

src/com/facebook/buck/remoteexecution/event/listener/RemoteExecutionEventListener.java

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.facebook.buck.event.BuckEventListener;
2121
import com.facebook.buck.remoteexecution.event.CasBlobDownloadEvent;
2222
import com.facebook.buck.remoteexecution.event.CasBlobUploadEvent.Finished;
23+
import com.facebook.buck.remoteexecution.event.CasFindMissingEvent;
2324
import com.facebook.buck.remoteexecution.event.LocalFallbackEvent;
2425
import com.facebook.buck.remoteexecution.event.LocalFallbackEvent.Result;
2526
import com.facebook.buck.remoteexecution.event.LocalFallbackStats;
@@ -56,6 +57,7 @@ public class RemoteExecutionEventListener
5657
private final LongAdder downloadBytes;
5758
private final LongAdder uploads;
5859
private final LongAdder uploadBytes;
60+
private final LongAdder findMissingCount;
5961

6062
private final LongAdder remoteCpuTimeMs;
6163
private final LongAdder remoteQueueTimeMs;
@@ -155,6 +157,7 @@ public RemoteExecutionEventListener(Optional<String> reStatsDumpPath) {
155157
this.downloadBytes = new LongAdder();
156158
this.uploads = new LongAdder();
157159
this.uploadBytes = new LongAdder();
160+
this.findMissingCount = new LongAdder();
158161
this.remoteCpuTimeMs = new LongAdder();
159162
this.remoteQueueTimeMs = new LongAdder();
160163
this.totalRemoteTimeMs = new LongAdder();
@@ -211,6 +214,12 @@ public void onCasDownloadEvent(CasBlobDownloadEvent.Finished event) {
211214
downloadBytes.add(event.getStartedEvent().getSizeBytes());
212215
}
213216

217+
@Subscribe
218+
public void onFindMissingBlobsEvent(CasFindMissingEvent.Finished event) {
219+
hasFirstRemoteActionStarted.set(true);
220+
findMissingCount.add(event.getStartedEvent().getBlobCount());
221+
}
222+
214223
/** Event specific subscriber method. */
215224
@Subscribe
216225
public void onActionScheduled(
@@ -330,6 +339,11 @@ public long getCasUploadSizeBytes() {
330339
return uploadBytes.intValue();
331340
}
332341

342+
@Override
343+
public long getCasFindMissingCount() {
344+
return findMissingCount.intValue();
345+
}
346+
333347
@Override
334348
public int getTotalRulesBuilt() {
335349
return totalBuildRules.intValue();

src/com/facebook/buck/remoteexecution/grpc/GrpcCasBlobUploader.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.facebook.buck.remoteexecution.CasBlobUploader;
2828
import com.facebook.buck.remoteexecution.UploadDataSupplier;
2929
import com.facebook.buck.remoteexecution.event.CasBlobUploadEvent;
30+
import com.facebook.buck.remoteexecution.event.CasFindMissingEvent;
3031
import com.facebook.buck.remoteexecution.grpc.GrpcProtocol.GrpcDigest;
3132
import com.facebook.buck.remoteexecution.interfaces.Protocol.Digest;
3233
import com.facebook.buck.remoteexecution.proto.RemoteExecutionMetadata;
@@ -76,10 +77,12 @@ public ImmutableSet<String> getMissingHashes(Set<Digest> requiredDigests) throws
7677
FindMissingBlobsRequest.Builder requestBuilder = FindMissingBlobsRequest.newBuilder();
7778
requestBuilder.setInstanceName(instanceName);
7879
requiredDigests.forEach(digest -> requestBuilder.addBlobDigests((GrpcProtocol.get(digest))));
79-
return storageStub.findMissingBlobs(requestBuilder.build()).get().getMissingBlobDigestsList()
80-
.stream()
81-
.map(build.bazel.remote.execution.v2.Digest::getHash)
82-
.collect(ImmutableSet.toImmutableSet());
80+
try (Scope ignored = CasFindMissingEvent.sendEvent(buckEventBus, requiredDigests.size())) {
81+
return storageStub.findMissingBlobs(requestBuilder.build()).get()
82+
.getMissingBlobDigestsList().stream()
83+
.map(build.bazel.remote.execution.v2.Digest::getHash)
84+
.collect(ImmutableSet.toImmutableSet());
85+
}
8386
} catch (InterruptedException | ExecutionException e) {
8487
Throwables.throwIfInstanceOf(e.getCause(), IOException.class);
8588
throw new BuckUncheckedExecutionException(e);

0 commit comments

Comments
 (0)