Skip to content

Commit

Permalink
Add profile spans for the network handshake inside RemoteModule#befor…
Browse files Browse the repository at this point in the history
…eCommand.

PiperOrigin-RevId: 538498468
Change-Id: I88cb9114bb370f42ecdeaac5b592b3a4e9ab4f08
  • Loading branch information
coeuvre authored and Copybara-Service committed Jun 7, 2023
1 parent a1dcaea commit bf9b177
Showing 1 changed file with 40 additions and 35 deletions.
Expand Up @@ -59,6 +59,7 @@
import com.google.devtools.build.lib.exec.ExecutorBuilder;
import com.google.devtools.build.lib.exec.ModuleActionContextRegistry;
import com.google.devtools.build.lib.exec.SpawnStrategyRegistry;
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.remote.RemoteServerCapabilities.ServerCapabilitiesRequirement;
import com.google.devtools.build.lib.remote.circuitbreaker.CircuitBreakerFactory;
import com.google.devtools.build.lib.remote.common.RemoteCacheClient;
Expand Down Expand Up @@ -443,45 +444,49 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
}

if (enableRemoteExecution) {
ImmutableList.Builder<ClientInterceptor> interceptors = ImmutableList.builder();
interceptors.add(TracingMetadataUtils.newExecHeadersInterceptor(remoteOptions));
if (loggingInterceptor != null) {
interceptors.add(loggingInterceptor);
}
execChannel =
new ReferenceCountedChannel(
new GoogleChannelConnectionFactory(
channelFactory,
remoteOptions.remoteExecutor,
remoteOptions.remoteProxy,
authAndTlsOptions,
interceptors.build(),
maxConcurrencyPerConnection),
maxConnections);

// Create a separate channel if --remote_executor and --remote_cache point to different
// endpoints.
if (remoteOptions.remoteCache.equals(remoteOptions.remoteExecutor)) {
cacheChannel = execChannel.retain();
try (var s = Profiler.instance().profile("init exec channel")) {
ImmutableList.Builder<ClientInterceptor> interceptors = ImmutableList.builder();
interceptors.add(TracingMetadataUtils.newExecHeadersInterceptor(remoteOptions));
if (loggingInterceptor != null) {
interceptors.add(loggingInterceptor);
}
execChannel =
new ReferenceCountedChannel(
new GoogleChannelConnectionFactory(
channelFactory,
remoteOptions.remoteExecutor,
remoteOptions.remoteProxy,
authAndTlsOptions,
interceptors.build(),
maxConcurrencyPerConnection),
maxConnections);

// Create a separate channel if --remote_executor and --remote_cache point to different
// endpoints.
if (remoteOptions.remoteCache.equals(remoteOptions.remoteExecutor)) {
cacheChannel = execChannel.retain();
}
}
}

if (cacheChannel == null) {
ImmutableList.Builder<ClientInterceptor> interceptors = ImmutableList.builder();
interceptors.add(TracingMetadataUtils.newCacheHeadersInterceptor(remoteOptions));
if (loggingInterceptor != null) {
interceptors.add(loggingInterceptor);
try (var s = Profiler.instance().profile("init cache channel")) {
ImmutableList.Builder<ClientInterceptor> interceptors = ImmutableList.builder();
interceptors.add(TracingMetadataUtils.newCacheHeadersInterceptor(remoteOptions));
if (loggingInterceptor != null) {
interceptors.add(loggingInterceptor);
}
cacheChannel =
new ReferenceCountedChannel(
new GoogleChannelConnectionFactory(
channelFactory,
remoteOptions.remoteCache,
remoteOptions.remoteProxy,
authAndTlsOptions,
interceptors.build(),
maxConcurrencyPerConnection),
maxConnections);
}
cacheChannel =
new ReferenceCountedChannel(
new GoogleChannelConnectionFactory(
channelFactory,
remoteOptions.remoteCache,
remoteOptions.remoteProxy,
authAndTlsOptions,
interceptors.build(),
maxConcurrencyPerConnection),
maxConnections);
}

if (enableRemoteDownloader) {
Expand Down Expand Up @@ -526,7 +531,7 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
// capabilities respectively.
ServerCapabilities executionCapabilities = null;
ServerCapabilities cacheCapabilities = null;
try {
try (var s = Profiler.instance().profile("check server capabilities")) {
if (execChannel != null) {
if (cacheChannel != execChannel) {
executionCapabilities =
Expand Down

0 comments on commit bf9b177

Please sign in to comment.