Skip to content

Commit

Permalink
after generating a heap dump, zip it
Browse files Browse the repository at this point in the history
  • Loading branch information
evernat committed May 13, 2018
1 parent 081d187 commit 98cb8bc
Showing 1 changed file with 29 additions and 2 deletions.
Expand Up @@ -18,6 +18,8 @@
package net.bull.javamelody.internal.model;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
Expand All @@ -26,6 +28,8 @@
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import javax.management.JMException;
import javax.management.MBeanServer;
Expand Down Expand Up @@ -212,9 +216,12 @@ public String execute(Collector collector, CollectorServer collectorServer, // N
// heap dump à générer dans le répertoire temporaire sur le serveur
// avec un suffixe contenant le host, la date et l'heure et avec une extension hprof
// (utiliser jvisualvm du jdk ou MAT d'eclipse en standalone ou en plugin)
final String heapDumpPath = heapDump().getPath();
final File heapDump = heapDump();
final File zipFile = zip(heapDump);
heapDump.delete();
final String path = zipFile.getPath();
messageForReport = I18N.getFormattedString("heap_dump_genere",
heapDumpPath.replace('\\', '/'));
path.replace('\\', '/'));
}
break;
case INVALIDATE_SESSIONS:
Expand Down Expand Up @@ -387,6 +394,26 @@ private File heapDump() throws IOException {
}
}

private static File zip(File source) throws IOException {
final File target = new File(source.getParentFile(), source.getName() + ".zip");
final FileOutputStream fos = new FileOutputStream(target);
final ZipOutputStream zos = new ZipOutputStream(fos);
try {
final ZipEntry ze = new ZipEntry(source.getName());
zos.putNextEntry(ze);
final FileInputStream in = new FileInputStream(source);
try {
TransportFormat.pump(in, zos);
} finally {
in.close();
}
zos.closeEntry();
} finally {
zos.close();
}
return target;
}

private void ibmHeapDump() {
try {
final Class<?> dumpClass = getClass().getClassLoader().loadClass("com.ibm.jvm.Dump"); // NOPMD
Expand Down

0 comments on commit 98cb8bc

Please sign in to comment.