From 2d34c3251d71ffe743f4c3c601db7a0398e801ee Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 4 Mar 2024 07:17:32 -0800 Subject: [PATCH] [7.1.0] Add a profiler span for the findMissingDigests call associated with an upload. PiperOrigin-RevId: 612440278 Change-Id: I9ba6bbb212013596df330d1d3da45e80b4280647 --- .../build/lib/remote/UploadManifest.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/UploadManifest.java b/src/main/java/com/google/devtools/build/lib/remote/UploadManifest.java index 1652ec0deba1bd..8eeb55fa43122a 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/UploadManifest.java +++ b/src/main/java/com/google/devtools/build/lib/remote/UploadManifest.java @@ -40,10 +40,12 @@ import com.google.common.base.Preconditions; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Multimaps; import com.google.common.collect.SortedSetMultimap; import com.google.common.collect.TreeMultimap; +import com.google.common.util.concurrent.ListenableFuture; import com.google.devtools.build.lib.actions.ActionExecutionMetadata; import com.google.devtools.build.lib.actions.ActionUploadFinishedEvent; import com.google.devtools.build.lib.actions.ActionUploadStartedEvent; @@ -53,6 +55,8 @@ import com.google.devtools.build.lib.concurrent.ErrorClassifier; import com.google.devtools.build.lib.concurrent.NamedForkJoinPool; import com.google.devtools.build.lib.events.ExtendedEventHandler; +import com.google.devtools.build.lib.profiler.Profiler; +import com.google.devtools.build.lib.profiler.ProfilerTask; import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext; import com.google.devtools.build.lib.remote.common.RemoteCacheClient; import com.google.devtools.build.lib.remote.common.RemoteCacheClient.ActionKey; @@ -94,6 +98,8 @@ /** UploadManifest adds output metadata to a {@link ActionResult}. */ public class UploadManifest { + private static final Profiler profiler = Profiler.instance(); + private final DigestUtil digestUtil; private final RemotePathResolver remotePathResolver; private final ActionResult.Builder result; @@ -679,7 +685,7 @@ public Single uploadAsync( ActionExecutionMetadata action = context.getSpawnOwner(); Flowable bulkTransfers = - toSingle(() -> remoteCache.findMissingDigests(context, digests), directExecutor()) + toSingle(() -> findMissingDigests(context, remoteCache, digests), directExecutor()) .doOnSubscribe(d -> reportUploadStarted(reporter, action, Store.CAS, digests)) .doOnError(error -> reportUploadFinished(reporter, action, Store.CAS, digests)) .doOnDispose(() -> reportUploadFinished(reporter, action, Store.CAS, digests)) @@ -720,4 +726,19 @@ public Single uploadAsync( return Completable.concatArray(uploadOutputs, uploadActionResult).toSingleDefault(actionResult); } + + private ListenableFuture> findMissingDigests( + RemoteActionExecutionContext context, RemoteCache remoteCache, Collection digests) { + long startTime = Profiler.nanoTimeMaybe(); + + var future = remoteCache.findMissingDigests(context, digests); + + if (profiler.isActive()) { + future.addListener( + () -> profiler.logSimpleTask(startTime, ProfilerTask.INFO, "findMissingDigests"), + directExecutor()); + } + + return future; + } }