Skip to content

Commit

Permalink
Fix for Issue #1.
Browse files Browse the repository at this point in the history
Moved heap dump code to use reflection and remove compile time
dependency on specific JVMs.
Updated README to markdown; added link to website and 'build from
source' instructions.
  • Loading branch information
Hunter Presnall committed Feb 10, 2014
1 parent d4805b6 commit e030e0e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 36 deletions.
1 change: 0 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/oracle_tools.jar"/>
<classpathentry kind="lib" path="lib/jcommon-1.0.17.jar"/>
<classpathentry kind="lib" path="lib/jfreechart-1.0.14.jar" sourcepath="D:/Development/Libraries/jfreechart-1.0.14/source"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.7.2.jar"/>
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/bin
/build
/NMONVisualizer_*.jar
/MANIFEST.MF
10 changes: 0 additions & 10 deletions MANIFEST.MF

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# NMON Visualizer

NMON Visualizer is a Java GUI tool for analyzing NMON system files from both AIX and Linux. It also parses IOStat files, IBM verbose GC logs, ESXTop CSV data and JSON data.
NMON Visualizer is a Java GUI tool for analyzing NMON system files from both AIX and Linux. It also parses IOStat files, IBM verbose GC logs, ESXTop CSV data and JSON data.
For more information, including links to download an executable JAR file, see [the website](http://nmonvisualizer.github.io/nmonvisualizer/).

## Build from Source

1. Download [Apache Ant](http://ant.apache.org/bindownload.cgi) and unpack into a directory, which we'll refer to as ${ANT_HOME}
2. From the root directory of nmonvisualizer, run ${ANT_HOME}/bin/ant
1. Download [Apache Ant](http://ant.apache.org/bindownload.cgi) and unpack into a directory, which we'll refer to as `${ANT_HOME}`
2. From the root directory of nmonvisualizer, run `${ANT_HOME}/bin/ant`. This will create an executable JAR file in the root directory.
55 changes: 34 additions & 21 deletions src/com/ibm/nmon/gui/main/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,22 @@ public void actionPerformed(ActionEvent e) {
item = new JMenuItem("Heap Dump");
item.setMnemonic('d');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Class<?> ibmDump = Class.forName("com.ibm.jvm.Dump");
Method ibmHeapDump = ibmDump.getMethod("HeapDump");
ibmHeapDump.invoke(null);
public void actionPerformed(ActionEvent evt) {
String vmVendor = System.getProperty("java.vm.vendor");

if (vmVendor.contains("IBM")) {
try {
Class<?> ibmDump = Class.forName("com.ibm.jvm.Dump");
Method ibmHeapDump = ibmDump.getMethod("HeapDump");
ibmHeapDump.invoke(null);
}
catch (Exception e) {
JOptionPane.showMessageDialog(gui.getMainFrame(), "Could not complete heap dump on " + "IBM"
+ " JVM\n\n" + e.getClass().getName() + ": " + e.getMessage(), "Heap Dump Error",
JOptionPane.ERROR_MESSAGE);
}
}
catch (Throwable t1) {
t1.printStackTrace();
// assume Oracle JVM
else if (vmVendor.contains("Oracle")) {
// assume runtime name is processid@hostname
String pid = java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
pid = pid.substring(0, pid.indexOf('@'));
Expand All @@ -531,22 +538,28 @@ public void actionPerformed(ActionEvent e) {
+ numberFormat.format(oracleJVMHeapDumpCount++) + ".hprof";

try {
Class<?> sunVM = Class.forName("com.sun.tools.attach.VirtualMachine");
Method sunAttach = sunVM.getMethod("attach", String.class);
Object attachResult = sunAttach.invoke(null, pid);
Class<?> attachResultClass = attachResult.getClass();
Method sunDumpHeap = attachResultClass.getMethod("dumpHeap", String.class, String.class);
sunDumpHeap.invoke(attachResult, filename, "-all");
Method sunDetach = attachResultClass.getMethod("detach");
sunDetach.invoke(attachResult);
Class<?> sunVM = Class.forName("sun.tools.attach.HotSpotVirtualMachine");
Method sunVMAttach = sunVM.getMethod("attach", String.class);
Object attachedVM = sunVMAttach.invoke(null, pid);

Class<?> actualVMClass = attachedVM.getClass();
Method dumpHeap = actualVMClass.getMethod("dumpHeap", Object[].class);
dumpHeap.invoke(attachedVM, new Object[] { new Object[] { filename, "-all" } });

Method detach = actualVMClass.getMethod("detach");
detach.invoke(attachedVM);
}
catch (Throwable t2) {
t2.printStackTrace();
JOptionPane.showMessageDialog(gui.getMainFrame(),
"Could not complete heap dump using either IBM or Oracle APIs:\n" + t1.getMessage() + "\n" + t2.getMessage(), "Heap Dump Error",
catch (Exception e) {
JOptionPane.showMessageDialog(gui.getMainFrame(), "Could not complete heap dump on " + "Oracle"
+ " JVM\n\n" + e.getClass().getName() + ": " + e.getMessage()
+ "\n\nAre you running a JDK?\nIs tools.jar in the classpath?", "Heap Dump Error",
JOptionPane.ERROR_MESSAGE);
}
}
else {
JOptionPane.showMessageDialog(gui.getMainFrame(), "Could not complete heap dump on " + vmVendor
+ " JVM\n\n", "Heap Dump Error", JOptionPane.ERROR_MESSAGE);
}
}
});

Expand Down Expand Up @@ -593,7 +606,7 @@ public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(
gui.getMainFrame(),
"Copyright \u00A9 2011-2013\n"
"Copyright \u00A9 2011-2014\n"
+ "IBM Software Group, Collaboration Services.\nAll Rights Reserved.\n\n"
+ "Support is on an 'as-is', 'best-effort' basis only.\n\n" + "Version "
+ VersionInfo.getVersion() + "\n\n" + "Icons from "
Expand Down

0 comments on commit e030e0e

Please sign in to comment.