aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2018-06-15 06:15:57 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-15 06:17:10 -0700
commitcca111fd1f9b4c52f9219f8e59bdcedf3836472f (patch)
tree80f39e9998a31abba2f43f3eb26ff1db40452534 /src/main/java/com/google/devtools/build/lib/runtime
parentb42734f4213e505d9582def4cd25bd510f0909a9 (diff)
Move the BlazeRuntime.initProfiler call to BlazeCommandDispatcher
The intend is to move the profiler setup earlier in the startup sequence, so we can get more profiler coverage. Ideally, we'd setup the profiler immediately after getting the client call, but this is not currently possible due to the requirement that initialization and shutdown happen in pairs (otherwise the next command invocation crashes with an exception from the Profiler). PiperOrigin-RevId: 200707029
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java3
3 files changed, 13 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
index dae2f597f8..5c55d8309f 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
@@ -437,12 +437,20 @@ public class BlazeCommandDispatcher {
}
}
+ // Profiler setup and shutdown _must_ always happen in pairs. Shutdown is currently performed
+ // in the finally block (in the afterCommand call), so this call must not be moved outside
+ // this try-finally block.
+ env.getRuntime().initProfiler(
+ env.getReporter(),
+ env.getBlazeWorkspace(),
+ commonOptions,
+ env.getCommandId(),
+ execStartTimeNanos);
try {
// Notify the BlazeRuntime, so it can do some initial setup.
env.beforeCommand(
options,
commonOptions,
- execStartTimeNanos,
waitTimeInMs,
invocationPolicy);
} catch (AbruptExitException e) {
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
index b2c9607920..12276f4547 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeRuntime.java
@@ -260,10 +260,8 @@ public final class BlazeRuntime {
return moduleInvocationPolicy;
}
- /**
- * Conditionally enable profiling.
- */
- private void initProfiler(
+ /** Configure profiling based on the provided options. */
+ void initProfiler(
EventHandler eventHandler,
BlazeWorkspace workspace,
CommonCommandOptions options,
@@ -439,14 +437,8 @@ public final class BlazeRuntime {
* @param options The CommonCommandOptions used by every command.
* @throws AbruptExitException if this command is unsuitable to be run as specified
*/
- void beforeCommand(CommandEnvironment env, CommonCommandOptions options, long execStartTimeNanos)
+ void beforeCommand(CommandEnvironment env, CommonCommandOptions options)
throws AbruptExitException {
- initProfiler(
- env.getReporter(),
- env.getBlazeWorkspace(),
- options,
- env.getCommandId(),
- execStartTimeNanos);
if (options.memoryProfilePath != null) {
Path memoryProfilePath = env.getWorkingDirectory().getRelative(options.memoryProfilePath);
MemoryProfiler.instance()
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
index fae1810fe3..34593b6662 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
@@ -566,7 +566,6 @@ public final class CommandEnvironment {
void beforeCommand(
OptionsProvider options,
CommonCommandOptions commonOptions,
- long execStartTimeNanos,
long waitTimeInMs,
InvocationPolicy invocationPolicy)
throws AbruptExitException {
@@ -622,7 +621,7 @@ public final class CommandEnvironment {
reporter);
// Start the performance and memory profilers.
- runtime.beforeCommand(this, commonOptions, execStartTimeNanos);
+ runtime.beforeCommand(this, commonOptions);
eventBus.post(new CommandStartEvent(
command.name(), getCommandId(), getClientEnv(), workingDirectory, getDirectories(),