Compress the heap dump generated by TestUtils.dump()
Motivation: It takes too long to download the heap dump from the CI server. Modifications: Compress the heap dump as much as possible. Result: When heap dump is generated by certain test failure, the generated heap dump file is about 3 times smaller than before, although the compression time will increase the build time when the test fails.
This commit is contained in:
parent
99a703be88
commit
d6160208c3
10
pom.xml
10
pom.xml
@ -561,7 +561,7 @@
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
<artifactId>jzlib</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ning</groupId>
|
||||
@ -718,6 +718,14 @@
|
||||
<version>1.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Test dependency for generating a compressed heap dump file -->
|
||||
<dependency>
|
||||
<groupId>org.tukaani</groupId>
|
||||
<artifactId>xz</artifactId>
|
||||
<version>1.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
@ -30,29 +30,9 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymockclassextension</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jmock</groupId>
|
||||
<artifactId>jmock-junit4</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>netty-transport-sctp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>netty-transport-sctp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
@ -75,6 +55,12 @@
|
||||
<classifier>${os.detected.classifier}</classifier>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.tukaani</groupId>
|
||||
<artifactId>xz</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
@ -20,11 +20,15 @@ import io.netty.util.NetUtil;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
import org.junit.rules.TestName;
|
||||
import org.tukaani.xz.LZMA2Options;
|
||||
import org.tukaani.xz.XZOutputStream;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadInfo;
|
||||
@ -238,6 +242,51 @@ public final class TestUtils {
|
||||
hotspotMXBeanDumpHeap.invoke(hotspotMXBean, filename, true);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to dump heap: {}", filename, e);
|
||||
return;
|
||||
}
|
||||
|
||||
final String xzFilename = filename + ".xz";
|
||||
logger.info("Compressing the heap dump: {}", xzFilename);
|
||||
final byte[] buf = new byte[65536];
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
in = new FileInputStream(filename);
|
||||
out = new XZOutputStream(new FileOutputStream(xzFilename), new LZMA2Options(9));
|
||||
for (;;) {
|
||||
int readBytes = in.read(buf);
|
||||
if (readBytes < 0) {
|
||||
break;
|
||||
}
|
||||
if (readBytes == 0) {
|
||||
continue;
|
||||
}
|
||||
out.write(buf, 0, readBytes);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to compress the heap dump: {}", xzFilename, e);
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException ignored) {
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException ignored) {
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the uncompressed dump in favor of the compressed one.
|
||||
if (!file.delete()) {
|
||||
logger.warn("Failed to delete the uncompressed heap dump: {}", filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user