aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/buildevent/ProfilerStartedEvent.java32
-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.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java8
4 files changed, 52 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/ProfilerStartedEvent.java b/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/ProfilerStartedEvent.java
new file mode 100644
index 0000000000..c3cf5e9e0c
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/ProfilerStartedEvent.java
@@ -0,0 +1,32 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.buildtool.buildevent;
+
+import com.google.devtools.build.lib.events.ExtendedEventHandler;
+import com.google.devtools.build.lib.vfs.Path;
+
+/**
+ * This event is fired when the profiler is started.
+ */
+public class ProfilerStartedEvent implements ExtendedEventHandler.Postable {
+ private final Path profilePath;
+
+ public ProfilerStartedEvent(Path profilePath) {
+ this.profilePath = profilePath;
+ }
+
+ public Path getProfilePath() {
+ return profilePath;
+ }
+}
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 92c1370882..70ae16876d 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
@@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Flushables;
import com.google.common.util.concurrent.UncheckedExecutionException;
+import com.google.devtools.build.lib.buildtool.buildevent.ProfilerStartedEvent;
import com.google.devtools.build.lib.clock.BlazeClock;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
@@ -42,6 +43,7 @@ import com.google.devtools.build.lib.util.LoggingUtil;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.util.io.DelegatingOutErr;
import com.google.devtools.build.lib.util.io.OutErr;
+import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.common.options.OpaqueOptionsData;
import com.google.devtools.common.options.OptionsParser;
import com.google.devtools.common.options.OptionsParsingException;
@@ -267,8 +269,12 @@ public class BlazeCommandDispatcher {
// TODO(ulfjack): Move the profiler initialization as early in the startup sequence as possible.
// Profiler setup and shutdown must always happen in pairs. Shutdown is currently performed in
// the afterCommand call in the finally block below.
- runtime.initProfiler(
- storedEventHandler, workspace, commonOptions, env.getCommandId(), execStartTimeNanos);
+ Path profilePath =
+ runtime.initProfiler(
+ storedEventHandler, workspace, commonOptions, env.getCommandId(), execStartTimeNanos);
+ if (commonOptions.postProfileStartedEvent) {
+ storedEventHandler.post(new ProfilerStartedEvent(profilePath));
+ }
BlazeCommandResult result = BlazeCommandResult.exitCode(ExitCode.BLAZE_INTERNAL_ERROR);
PrintStream savedOut = System.out;
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 ee4147f666..a8b1d0ae75 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
@@ -263,7 +263,7 @@ public final class BlazeRuntime {
}
/** Configure profiling based on the provided options. */
- void initProfiler(
+ Path initProfiler(
EventHandler eventHandler,
BlazeWorkspace workspace,
CommonCommandOptions options,
@@ -273,13 +273,13 @@ public final class BlazeRuntime {
boolean recordFullProfilerData = false;
ProfiledTaskKinds profiledTasks = ProfiledTaskKinds.NONE;
Profiler.Format format = Profiler.Format.BINARY_BAZEL_FORMAT;
+ Path profilePath = null;
try {
if (options.enableTracer) {
format =
options.enableTracerCompression
? Format.JSON_TRACE_FILE_COMPRESSED_FORMAT
: Profiler.Format.JSON_TRACE_FILE_FORMAT;
- Path profilePath;
if (options.profilePath != null) {
profilePath = workspace.getWorkspace().getRelative(options.profilePath);
} else {
@@ -294,7 +294,7 @@ public final class BlazeRuntime {
eventHandler.handle(Event.info("Writing tracer profile to '" + profilePath + "'"));
profiledTasks = ProfiledTaskKinds.ALL_FOR_TRACE;
} else if (options.profilePath != null) {
- Path profilePath = workspace.getWorkspace().getRelative(options.profilePath);
+ profilePath = workspace.getWorkspace().getRelative(options.profilePath);
recordFullProfilerData = options.recordFullProfilerData;
out = profilePath.getOutputStream();
@@ -335,6 +335,7 @@ public final class BlazeRuntime {
} catch (IOException e) {
eventHandler.handle(Event.error("Error while creating profile file: " + e.getMessage()));
}
+ return profilePath;
}
public FileSystem getFileSystem() {
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
index cef27315e6..4a32b2c405 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
@@ -204,6 +204,14 @@ public class CommonCommandOptions extends OptionsBase {
public boolean enableTracerCompression;
@Option(
+ name = "experimental_post_profile_started_event",
+ defaultValue = "false",
+ documentationCategory = OptionDocumentationCategory.LOGGING,
+ effectTags = {OptionEffectTag.AFFECTS_OUTPUTS, OptionEffectTag.BAZEL_MONITORING},
+ help = "If set, Bazel will post the ProfilerStartedEvent including the path to the profile.")
+ public boolean postProfileStartedEvent;
+
+ @Option(
name = "profile",
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.LOGGING,