diff options
author | twerth <twerth@google.com> | 2018-07-27 06:11:47 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-27 06:13:25 -0700 |
commit | 2193da931c6804c497f8320dcc81e0d119d26c8c (patch) | |
tree | ab9f07f9684437c25da0dc89a5fc9c74d7f23422 /src/main/java/com/google/devtools/build/lib/profiler/Profiler.java | |
parent | 0858ae1f6eb890c1e203a2aa21130ba34ca36a27 (diff) |
Add an option to compress the JSON trace profile.
chrome://tracing is able to load gzipped profiles out of the box.
RELNOTES: None
PiperOrigin-RevId: 206308018
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/profiler/Profiler.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/profiler/Profiler.java | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java b/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java index 50af19b80b..3256159162 100644 --- a/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java +++ b/src/main/java/com/google/devtools/build/lib/profiler/Profiler.java @@ -46,6 +46,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream; +import java.util.zip.GZIPOutputStream; /** * Blaze internal profiler. Provides facility to report various Blaze tasks and store them @@ -139,9 +140,10 @@ public final class Profiler { private static final TaskData POISON_PILL = new TaskData(0, 0, null, null, "poison pill"); /** File format enum. */ - public static enum Format { + public enum Format { BINARY_BAZEL_FORMAT, - JSON_TRACE_FILE_FORMAT; + JSON_TRACE_FILE_FORMAT, + JSON_TRACE_FILE_COMPRESSED_FORMAT; } /** A task that was very slow. */ @@ -528,9 +530,8 @@ public final class Profiler { /** * Enable profiling. * - * <p>Subsequent calls to beginTask/endTask will be recorded - * in the provided output stream. Please note that stream performance is - * extremely important and buffered streams should be utilized. + * <p>Subsequent calls to beginTask/endTask will be recorded in the provided output stream. Please + * note that stream performance is extremely important and buffered streams should be utilized. * * @param profiledTaskKinds which kinds of {@link ProfilerTask}s to track * @param stream output stream to store profile data. Note: passing unbuffered stream object @@ -548,7 +549,8 @@ public final class Profiler { String comment, boolean recordAllDurations, Clock clock, - long execStartTimeNanos) { + long execStartTimeNanos) + throws IOException { Preconditions.checkState(!isActive(), "Profiler already active"); initHistograms(); @@ -565,14 +567,18 @@ public final class Profiler { this.recordAllDurations = recordAllDurations; this.taskStack = new TaskStack(); FileWriter writer = null; - if (stream != null) { - if (format == Format.BINARY_BAZEL_FORMAT) { - writer = new BinaryFormatWriter(stream, execStartTimeNanos, comment); - writer.start(); - } else if (format == Format.JSON_TRACE_FILE_FORMAT) { - writer = new JsonTraceFileWriter(stream, execStartTimeNanos); - writer.start(); + if (stream != null && format != null) { + switch (format) { + case BINARY_BAZEL_FORMAT: + writer = new BinaryFormatWriter(stream, execStartTimeNanos, comment); + break; + case JSON_TRACE_FILE_FORMAT: + writer = new JsonTraceFileWriter(stream, execStartTimeNanos); + break; + case JSON_TRACE_FILE_COMPRESSED_FORMAT: + writer = new JsonTraceFileWriter(new GZIPOutputStream(stream), execStartTimeNanos); } + writer.start(); } this.writerRef.set(writer); |