aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime
diff options
context:
space:
mode:
authorGravatar twerth <twerth@google.com>2018-07-31 04:52:54 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-31 04:54:54 -0700
commit1e5514902007f8919a52fcd77d939ef6f09c9a9d (patch)
tree92fa9dacd5e7ec1fd414b64ac2a610845e9cc790 /src/main/java/com/google/devtools/build/lib/runtime
parent03a20ef89bf3c7b1c90f69ce4ae1eb841419bb03 (diff)
Add option to post ProfileStartedEvent containing the profile's path.
RELNOTES: None PiperOrigin-RevId: 206741115
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.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java8
3 files changed, 20 insertions, 5 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 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,