aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/profiler/analysis
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2018-06-11 09:46:50 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-11 09:48:24 -0700
commit15b8c259db111012b4642287172cb4d1d82151f3 (patch)
tree0d46f77b5b25bfd67440c102de54c7de5ff05add /src/main/java/com/google/devtools/build/lib/profiler/analysis
parent6841a748109250f65448627bc5695d537990b686 (diff)
Refactor profiler
- move the save method to an inner class - don't use a timer, use a blocking queue instead - add a format enum (in anticipation of adding a json output format) - update the test to use an in memory buffer, and avoid FoundationTestCase PiperOrigin-RevId: 200065404
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/profiler/analysis')
-rw-r--r--src/main/java/com/google/devtools/build/lib/profiler/analysis/ProfileInfo.java27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/profiler/analysis/ProfileInfo.java b/src/main/java/com/google/devtools/build/lib/profiler/analysis/ProfileInfo.java
index 6104674086..5050eb4436 100644
--- a/src/main/java/com/google/devtools/build/lib/profiler/analysis/ProfileInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/profiler/analysis/ProfileInfo.java
@@ -35,6 +35,7 @@ import com.google.devtools.build.lib.vfs.Path;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
@@ -882,23 +883,22 @@ public class ProfileInfo {
/**
* Loads and parses Blaze profile file.
*
- * @param profileFile profile file path
+ * @param profileStream profile file path
*
* @return ProfileInfo object with some fields populated (call calculateStats()
* and analyzeRelationships() to populate the remaining fields)
* @throws UnsupportedEncodingException if the file format is invalid
* @throws IOException if the file can't be read
*/
- public static ProfileInfo loadProfile(Path profileFile)
- throws IOException {
- // It is extremely important to wrap InflaterInputStream using
- // BufferedInputStream because majority of reads would be done using
- // readInt()/readLong() methods and InflaterInputStream is very inefficient
- // in handling small read requests (performance difference with 1MB buffer
- // used below is almost 10x).
- DataInputStream in = new DataInputStream(
- new BufferedInputStream(new InflaterInputStream(
- profileFile.getInputStream(), new Inflater(false), 65536), 1024 * 1024));
+ public static ProfileInfo loadProfile(InputStream profileStream) throws IOException {
+ // It is extremely important to wrap InflaterInputStream using BufferedInputStream because
+ // the majority of reads would be done using readInt()/readLong() methods and
+ // InflaterInputStream is very inefficient in handling small read requests (performance
+ // difference with 1MB buffer used below is almost 10x).
+ DataInputStream in =
+ new DataInputStream(
+ new BufferedInputStream(
+ new InflaterInputStream(profileStream, new Inflater(false), 65536), 1024 * 1024));
if (in.readInt() != Profiler.MAGIC) {
in.close();
@@ -995,7 +995,10 @@ public class ProfileInfo {
public static ProfileInfo loadProfileVerbosely(Path profileFile, InfoListener reporter)
throws IOException {
reporter.info("Loading " + profileFile.getPathString());
- ProfileInfo profileInfo = ProfileInfo.loadProfile(profileFile);
+ ProfileInfo profileInfo;
+ try (InputStream in = profileFile.getInputStream()) {
+ profileInfo = ProfileInfo.loadProfile(in);
+ }
if (profileInfo.isCorruptedOrIncomplete()) {
reporter.warn("Profile file is incomplete or corrupted - not all records were parsed");
}