You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2014/02/11 02:44:48 UTC
git commit: [KARAF-2449] Minor improvements on the heapdump and
memory dump providers
Updated Branches:
refs/heads/karaf-2.3.x f5f091e2c -> fb2176ab5
[KARAF-2449] Minor improvements on the heapdump and memory dump providers
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/fb2176ab
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/fb2176ab
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/fb2176ab
Branch: refs/heads/karaf-2.3.x
Commit: fb2176ab5180204672a40d49c07b96f4794df305
Parents: f5f091e
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Tue Feb 11 02:44:20 2014 +0100
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Tue Feb 11 02:44:20 2014 +0100
----------------------------------------------------------------------
.../karaf/diagnostic/common/HeapDumpProvider.java | 17 ++++++++++++-----
.../diagnostic/common/MemoryDumpProvider.java | 5 +----
2 files changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/fb2176ab/diagnostic/common/src/main/java/org/apache/karaf/diagnostic/common/HeapDumpProvider.java
----------------------------------------------------------------------
diff --git a/diagnostic/common/src/main/java/org/apache/karaf/diagnostic/common/HeapDumpProvider.java b/diagnostic/common/src/main/java/org/apache/karaf/diagnostic/common/HeapDumpProvider.java
index 8628daf..8d4c2a2 100644
--- a/diagnostic/common/src/main/java/org/apache/karaf/diagnostic/common/HeapDumpProvider.java
+++ b/diagnostic/common/src/main/java/org/apache/karaf/diagnostic/common/HeapDumpProvider.java
@@ -29,6 +29,8 @@ import java.lang.management.ManagementFactory;
public class HeapDumpProvider implements DumpProvider {
public void createDump(DumpDestination destination) throws Exception {
+ FileInputStream in = null;
+ OutputStream out = null;
try {
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
HotSpotDiagnosticMXBean diagnosticMXBean = ManagementFactory.newPlatformMXBeanProxy(mBeanServer,
@@ -36,21 +38,26 @@ public class HeapDumpProvider implements DumpProvider {
diagnosticMXBean.dumpHeap("heapdump.txt", false);
// copy the dump in the destination
File heapDumpFile = new File("heapdump.txt");
- FileInputStream in = new FileInputStream(heapDumpFile);
- OutputStream out = destination.add("heapdump.txt");
+ in = new FileInputStream(heapDumpFile);
+ out = destination.add("heapdump.txt");
byte[] buffer = new byte[2048];
while ((in.read(buffer) != -1)) {
out.write(buffer);
}
- in.close();
- out.flush();
- out.close();
// remove the original dump
if (heapDumpFile.exists()) {
heapDumpFile.delete();
}
} catch (Exception e) {
// nothing to do
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ if (out != null) {
+ out.flush();
+ out.close();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/fb2176ab/diagnostic/common/src/main/java/org/apache/karaf/diagnostic/common/MemoryDumpProvider.java
----------------------------------------------------------------------
diff --git a/diagnostic/common/src/main/java/org/apache/karaf/diagnostic/common/MemoryDumpProvider.java b/diagnostic/common/src/main/java/org/apache/karaf/diagnostic/common/MemoryDumpProvider.java
index d0d2e32..f05fd2c 100644
--- a/diagnostic/common/src/main/java/org/apache/karaf/diagnostic/common/MemoryDumpProvider.java
+++ b/diagnostic/common/src/main/java/org/apache/karaf/diagnostic/common/MemoryDumpProvider.java
@@ -23,13 +23,10 @@ import java.io.OutputStreamWriter;
import java.lang.management.MemoryMXBean;
/**
- * Provider which dump the heap to file heap.txt
+ * Provider which provide memory information in memory.txt file
*/
public class MemoryDumpProvider extends TextDumpProvider {
- /**
- * Create a new dump entry which contains information about memory usage.
- */
public MemoryDumpProvider() {
super("memory.txt");
}