ProfileGrapher: support gzipped profiles
@@ -19,6 +19,7 @@ import com.google.gson.stream.JsonReader;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -27,6 +28,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
+import java.util.zip.GZIPInputStream;
/**
* An experimental tool to turn Json profiles into graphs. Do not depend on the continuing existence
@@ -83,6 +85,7 @@ public class ProfileGrapher {
System.exit(1);
}
String filename = args[0];
+ boolean gzipped = filename.endsWith(".gz");
// TODO(twerth): Make it possible to select the set of profiler task descriptions on the command
// line.
@@ -101,7 +104,8 @@ public class ProfileGrapher {
try (JsonReader reader =
new JsonReader(
new BufferedReader(
- new InputStreamReader(new FileInputStream(filename), StandardCharsets.UTF_8)))) {
+ new InputStreamReader(
+ maybeUnzip(new FileInputStream(filename), gzipped), StandardCharsets.UTF_8)))) {
reader.beginArray();
while (reader.hasNext()) {
Map<String, Object> data = decodeJsonObject(reader);
@@ -150,6 +154,13 @@ public class ProfileGrapher {
}
}
+ private static InputStream maybeUnzip(InputStream in, boolean gzipped) throws IOException {
+ if (!gzipped) {
+ return in;
+ }
+ return new GZIPInputStream(in);
+ }
+
/**
* Decodes the start time and duration from the data, adds it to the given series and returns the
* end time in milliseconds if it was possible to decode the data, otherwise null.
