diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/.classpath b/javaUtilities/com.raytheon.uf.viz.hprof/.classpath new file mode 100644 index 0000000000..ad32c83a78 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/.project b/javaUtilities/com.raytheon.uf.viz.hprof/.project new file mode 100644 index 0000000000..2ab3dc591a --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/.project @@ -0,0 +1,28 @@ + + + com.raytheon.uf.viz.hprof + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/.settings/org.eclipse.jdt.core.prefs b/javaUtilities/com.raytheon.uf.viz.hprof/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..0ead400a33 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Wed Sep 07 17:58:19 CDT 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/META-INF/MANIFEST.MF b/javaUtilities/com.raytheon.uf.viz.hprof/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..450fb8ef88 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Main-Class: com.raytheon.uf.viz.hprof.CaveExporter +Bundle-ManifestVersion: 2 +Bundle-Name: Viz Hprof Analysis +Bundle-SymbolicName: com.raytheon.uf.viz.hprof +Bundle-Version: 1.14.0.qualifier +Bundle-Vendor: RAYTHEON +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Export-Package: com.raytheon.hprof, + com.raytheon.hprof.data, + com.raytheon.hprof.data.heap, + com.raytheon.hprof.data.heap.dump, + com.raytheon.hprof.data.heap.root, + com.raytheon.uf.viz.hprof diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/build.properties b/javaUtilities/com.raytheon.uf.viz.hprof/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/build.xml b/javaUtilities/com.raytheon.uf.viz.hprof/build.xml new file mode 100644 index 0000000000..a35d235784 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/build.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/BigByteBuffer.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/BigByteBuffer.java new file mode 100644 index 0000000000..f7623cd34b --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/BigByteBuffer.java @@ -0,0 +1,211 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof; + +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.BufferUnderflowException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileChannel.MapMode; + +/** + * + * ByteBuffers cannot be used to index more than 2GB of data. Since some hprof + * files are larger than that a BigByteBuffer is used to allow long indexing + * into a much larger space. BigByteBuffers internally are represented by direct + * memory mapped byte buffers that map the contents of a single file. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class BigByteBuffer { + + private final long chunkSize = 1024 * 1024 * 256; + + private final ByteBuffer[] buffers; + + private final long offset; + + private final long capacity; + + private long mark = -1; + + private long position = 0; + + private long limit; + + public BigByteBuffer(String fileName) throws IOException { + FileInputStream fis = new FileInputStream(fileName); + FileChannel fileChannel = fis.getChannel(); + offset = 0; + limit = capacity = fileChannel.size(); + int nBuffers = (int) (capacity / chunkSize); + if (nBuffers * chunkSize < capacity) { + nBuffers += 1; + } + buffers = new ByteBuffer[nBuffers]; + for (int i = 0; i < buffers.length; i += 1) { + buffers[i] = fileChannel.map(MapMode.READ_ONLY, i * chunkSize, + Math.min(capacity - i * chunkSize, chunkSize)); + } + fis.close(); + } + + protected BigByteBuffer(ByteBuffer[] buffers, long offset, long capacity) { + this.buffers = buffers; + this.offset = offset; + this.capacity = capacity; + this.limit = capacity; + } + + public final long capacity() { + return capacity; + } + + public final long position() { + return position; + } + + public final BigByteBuffer position(long newPosition) { + if ((newPosition > limit) || (newPosition < 0)) + throw new IllegalArgumentException(); + position = newPosition; + if (mark > position) + mark = -1; + return this; + } + + public final long limit() { + return limit; + } + + public final BigByteBuffer limit(long newLimit) { + if ((newLimit > capacity) || (newLimit < 0)) + throw new IllegalArgumentException(); + limit = newLimit; + if (position > limit) + position = limit; + if (mark > limit) + mark = -1; + return this; + } + + public final BigByteBuffer rewind() { + position = 0; + mark = -1; + return this; + } + + public final long remaining() { + return limit - position; + } + + public final boolean hasRemaining() { + return position < limit; + } + + public BigByteBuffer slice() { + return new BigByteBuffer(buffers, this.position() + offset, + this.remaining()); + } + + public byte get() { + return get(nextGetIndex()); + } + + public byte get(long index) { + checkIndex(index); + return getBuffer(index).get(bufferIndex(index)); + } + + public void get(byte[] dst) { + long start = nextGetIndex(dst.length); + ByteBuffer buffer = getBuffer(start); + buffer.position(bufferIndex(start)); + int offset = 0; + int remaining = dst.length; + while (remaining > 0) { + int length = Math.min(remaining, buffer.remaining()); + buffer.get(dst, offset, length); + offset += length; + remaining -= length; + buffer = getBuffer(start + offset); + buffer.position(bufferIndex(start + offset)); + + } + } + + public short getShort() { + byte[] dst = new byte[2]; + get(dst); + return ByteBuffer.wrap(dst).getShort(); + } + + public int getInt() { + byte[] dst = new byte[4]; + get(dst); + return ByteBuffer.wrap(dst).getInt(); + } + + public long getLong() { + byte[] dst = new byte[8]; + get(dst); + return ByteBuffer.wrap(dst).getLong(); + } + + final ByteBuffer getBuffer(long index) { + return buffers[(int) ((offset + index) / chunkSize)]; + } + + final int bufferIndex(long index) { + return (int) ((offset + index) % chunkSize); + } + + final long nextGetIndex() { + if (position >= limit) + throw new BufferUnderflowException(); + return position++; + } + + final long nextGetIndex(int nb) { + if (limit - position < nb) + throw new BufferUnderflowException(); + long p = position; + position += nb; + return p; + } + + final long checkIndex(long i) { + if ((i < 0) || (i >= limit)) + throw new IndexOutOfBoundsException(); + return i; + } +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/HprofFile.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/HprofFile.java new file mode 100644 index 0000000000..b4f7a9688a --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/HprofFile.java @@ -0,0 +1,215 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ + +package com.raytheon.hprof; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.raytheon.hprof.data.HeapDumpEndRecord; +import com.raytheon.hprof.data.HeapDumpRecord; +import com.raytheon.hprof.data.HeapDumpSegmentRecord; +import com.raytheon.hprof.data.LoadClassRecord; +import com.raytheon.hprof.data.MergedHeapDumpSegmentRecord; +import com.raytheon.hprof.data.StackFrameRecord; +import com.raytheon.hprof.data.StackTraceRecord; +import com.raytheon.hprof.data.StringRecord; +import com.raytheon.hprof.data.heap.dump.InstanceDump; + +/** + * + * Root object for an hprof file, description of the data structure can be found + * in a java installation at java/demo/jvmti/hprof/src/manual.html. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class HprofFile { + + private HeapDumpRecord heapDump; + + private List strings = new ArrayList(); + + private List loadClasses = new ArrayList(); + + /* If these ever get full and cause problems they should be switched to LRU. */ + private Map usedStrings = new HashMap(); + + private Map usedClassnames = new HashMap(); + + public HprofFile(String fileName) throws IOException { + BigByteBuffer buffer = new BigByteBuffer(fileName); + + String format = null; + + while (buffer.hasRemaining()) { + if (buffer.get() == 0x00) { + byte[] formatBytes = new byte[(int) buffer.position() - 1]; + buffer.rewind(); + /* reread the string */ + buffer.get(formatBytes); + /* reread the null */ + buffer.get(); + format = new String(formatBytes); + break; + } + } + + if (format == null) { + throw new IllegalArgumentException( + "This does not appear to be a valid hprof file!"); + } + System.out.println("Hprof format is " + format); + int idSize = buffer.getInt(); + System.out.println("Dump is from " + new Date(buffer.getLong())); + + long segmentStart = 0; + + while (buffer.hasRemaining()) { + byte type = buffer.get(); + switch (type & 0xFF) { + case StringRecord.TAG: { + strings.add(new StringRecord(buffer, idSize)); + break; + } + case LoadClassRecord.TAG: { + loadClasses.add(new LoadClassRecord(buffer, idSize)); + break; + } + case StackFrameRecord.TAG: { + new StackFrameRecord(buffer, idSize); + break; + } + case StackTraceRecord.TAG: { + new StackTraceRecord(buffer, idSize); + break; + } + case HeapDumpRecord.TAG: { + heapDump = new HeapDumpRecord(buffer, idSize); + break; + } + case HeapDumpSegmentRecord.TAG: { + if (segmentStart == 0) { + segmentStart = buffer.position() - 1; + } + new HeapDumpSegmentRecord(buffer, idSize); + break; + } + case HeapDumpEndRecord.TAG: { + long segmentEnd = buffer.position() - 1; + buffer.position(segmentStart); + BigByteBuffer safeBuffer = buffer.slice(); + safeBuffer.limit(segmentEnd - segmentStart); + heapDump = new MergedHeapDumpSegmentRecord(safeBuffer, idSize); + segmentStart = 0; + buffer.position(segmentEnd + 1); + new HeapDumpEndRecord(buffer, idSize); + break; + } + default: + throw new IllegalStateException("Unknown type " + + Integer.toHexString(type & 0xFF)); + } + } + } + + public Id lookUpClass(String className) { + Id classNameId = getStringId(className.replace(".", "/")); + for (LoadClassRecord loadClass : loadClasses) { + if (loadClass.getClassNameId().equals(classNameId)) { + return loadClass.getClassId(); + } + } + return null; + } + + public HeapDumpRecord getHeapDump() { + return heapDump; + } + + public String getString(Id stringId) { + if (usedStrings.containsKey(stringId)) { + return usedStrings.get(stringId); + } + for (StringRecord string : strings) { + if (string.getId().equals(stringId)) { + usedStrings.put(stringId, string.getString()); + return string.getString(); + } + } + return null; + } + + public Id getStringId(String string) { + for (Entry entry : usedStrings.entrySet()) { + if (entry.getValue().equals(string)) { + return entry.getKey(); + } + } + for (StringRecord stringRec : strings) { + if (stringRec.getString().equals(string)) { + usedStrings.put(stringRec.getId(), stringRec.getString()); + return stringRec.getId(); + } + } + return null; + } + + public String getClassName(Id classId) { + if (usedClassnames.containsKey(classId)) { + return usedClassnames.get(classId); + } + for (LoadClassRecord loadClass : loadClasses) { + if (loadClass.getClassId().equals(classId)) { + String className = getString(loadClass.getClassNameId()) + .replace("/", "."); + usedClassnames.put(classId, className); + return className; + } + } + return null; + } + + public List getInstances(String className) { + Id classId = lookUpClass(className); + if (classId == null) { + return Collections.emptyList(); + } + return heapDump.getInstances(classId); + + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/Id.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/Id.java new file mode 100644 index 0000000000..f13dbbcf3d --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/Id.java @@ -0,0 +1,105 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof; + +import java.nio.ByteBuffer; +import java.util.Arrays; + +/** + * + * Represents an Id of an object in an hprof file. The id is generally either 4 + * or 8 bytes which is essentially an int or a long but the hprof format allows + * arbitrary id lengths. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class Id implements Comparable { + + private final byte[] id; + + public Id(BigByteBuffer buffer, int idSize) { + id = new byte[idSize]; + buffer.get(id); + } + + public Id(ByteBuffer buffer, int idSize) { + id = new byte[idSize]; + buffer.get(id); + } + + public int size() { + return id.length; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(id); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Id other = (Id) obj; + if (!Arrays.equals(id, other.id)) + return false; + return true; + } + + @Override + public String toString() { + StringBuilder str = new StringBuilder(); + str.append("id=0x"); + for (byte b : id) { + str.append(String.format("%02x", b & 0xFF)); + } + return str.toString(); + } + + @Override + public int compareTo(Id that) { + for (int i = 0; i < id.length; i++) { + int diff = id[i] - that.id[i]; + if (diff != 0) { + return diff; + } + } + return 0; + } + +} \ No newline at end of file diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/SmartInstance.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/SmartInstance.java new file mode 100644 index 0000000000..55b033cccf --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/SmartInstance.java @@ -0,0 +1,289 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + +import com.raytheon.hprof.data.HeapDumpRecord; +import com.raytheon.hprof.data.heap.BasicType; +import com.raytheon.hprof.data.heap.dump.ClassDump; +import com.raytheon.hprof.data.heap.dump.InstanceDump; +import com.raytheon.hprof.data.heap.dump.ObjectArrayDump; + +/** + * Represents an instance of an object within a heap dump. This is an enhanced + * version of an {@link InstanceDump} that uses all the information in an + * {@link HprofFile} to provide useful introspection. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class SmartInstance { + + private final HprofFile hprof; + + private final Id id; + + private final String className; + + private final Map fields = new HashMap(); + + public SmartInstance(HprofFile hprof, InstanceDump instance) { + this.hprof = hprof; + this.id = instance.getId(); + Id classId = instance.getClassId(); + className = hprof.getClassName(classId); + int idSize = classId.size(); + HeapDumpRecord heapDump = hprof.getHeapDump(); + ClassDump classDump = heapDump.getClassDump(classId); + BigByteBuffer instanceData = instance.getInstanceData(); + while (classDump != null) { + Map id2type = classDump.parseInstanceData( + instanceData, idSize); + for (Entry entry : id2type.entrySet()) { + String fieldName = hprof.getString(entry.getKey()); + fields.put(fieldName, entry.getValue()); + } + classDump = heapDump.getClassDump(classDump.getSuperId()); + } + + } + + protected Id getId(String fieldName) { + BasicType type = fields.get(fieldName); + if (type == null) { + return null; + } + return type.getObjectId(); + } + + protected String getClassName() { + return className; + } + + public SmartInstance get(String fieldName) { + Id fieldId = getId(fieldName); + if (fieldId == null) { + return null; + } + InstanceDump field = hprof.getHeapDump().getInstance(fieldId); + if (field == null) { + return null; + } + return new SmartInstance(hprof, field); + } + + private BasicType getTypeNotNull(String fieldName) { + BasicType type = fields.get(fieldName); + if (type == null) { + throw new IllegalStateException(fieldName + + " is not a a valid field"); + } + return type; + } + + public int getInt(String fieldName) { + return getTypeNotNull(fieldName).getInt(); + } + + public long getLong(String fieldName) { + return getTypeNotNull(fieldName).getLong(); + } + + public SmartInstance[] getObjectArray(String fieldName) { + BasicType type = fields.get(fieldName); + if (type == null) { + return null; + } + HeapDumpRecord heapDump = hprof.getHeapDump(); + Id fieldId = type.getObjectId(); + ObjectArrayDump objectArray = heapDump.getObjectArray(fieldId); + if (objectArray == null) { + return null; + } + Id[] idArray = objectArray.getArray(); + SmartInstance[] smartArray = new SmartInstance[idArray.length]; + for (int i = 0; i < idArray.length; i += 1) { + InstanceDump instance = heapDump.getInstance(idArray[i]); + if (instance != null) { + smartArray[i] = new SmartInstance(hprof, instance); + } + } + return smartArray; + } + + public char[] getCharArray(String fieldName) { + BasicType type = fields.get(fieldName); + if (type == null) { + return null; + } + Id fieldId = type.getObjectId(); + BasicType[] primArray = hprof.getHeapDump().getPrimitiveArray(fieldId); + if (primArray == null) { + return null; + } + char[] charArray = new char[primArray.length]; + + for (int i = 0; i < charArray.length; i += 1) { + charArray[i] = primArray[i].getChar(); + } + return charArray; + } + + public int[] getIntArray(String fieldName) { + BasicType type = fields.get(fieldName); + if (type == null) { + return null; + } + Id fieldId = type.getObjectId(); + BasicType[] primArray = hprof.getHeapDump().getPrimitiveArray(fieldId); + if (primArray == null) { + return null; + } + int[] intArray = new int[primArray.length]; + + for (int i = 0; i < intArray.length; i += 1) { + intArray[i] = primArray[i].getInt(); + } + return intArray; + } + + public String getString(String fieldName) { + Id fieldId = getId(fieldName); + if (fieldId == null) { + return null; + } + InstanceDump field = hprof.getHeapDump().getInstance(fieldId); + if (field != null) { + SmartInstance smartField = new SmartInstance(hprof, field); + if (!smartField.getClassName().equals(String.class.getName())) { + throw new IllegalStateException(fieldName + " is not a String."); + } + return smartField.toString(); + } else { + Iterator classDumps = hprof.getHeapDump() + .getClassDumps(); + while (classDumps.hasNext()) { + ClassDump classDump = classDumps.next(); + for (Entry entry : classDump.getStaticFields() + .entrySet()) { + BasicType f = entry.getValue(); + if (f.isObject() && f.getObjectId().equals(fieldId)) { + String className = hprof + .getClassName(classDump.getId()); + return "{@link " + shortenClass(className) + "#" + + hprof.getString(entry.getKey()) + "}"; + } + } + } + return "String (" + fieldId + ")"; + } + } + + public ArrayList toArrayList() { + if (!getClassName().equals(ArrayList.class.getName())) { + throw new IllegalStateException(this + " is not an ArrayList."); + } + int size = getInt("size"); + SmartInstance[] elementData = getObjectArray("elementData"); + ArrayList arrayList = new ArrayList(size); + for (int i = 0; i < size; i += 1) { + arrayList.add(elementData[i]); + } + return arrayList; + } + + public ConcurrentHashMap toConcurrentHashMap() { + if (!getClassName().equals(ConcurrentHashMap.class.getName())) { + throw new IllegalStateException(this + + " is not a ConcurrentHashMap."); + } + ConcurrentHashMap map = new ConcurrentHashMap(); + SmartInstance[] segments = getObjectArray("segments"); + for (SmartInstance segment : segments) { + SmartInstance[] table = segment.getObjectArray("table"); + for (SmartInstance entry : table) { + while (entry != null) { + map.put(entry.get("key"), entry.get("value")); + entry = entry.get("next"); + } + } + } + return map; + } + + public HashMap toHashMap() { + if (!getClassName().equals(HashMap.class.getName())) { + throw new IllegalStateException(this + " is not a HashMap."); + } + HashMap map = new HashMap(); + SmartInstance[] table = getObjectArray("table"); + for (SmartInstance entry : table) { + while (entry != null) { + map.put(entry.get("key"), entry.get("value")); + entry = entry.get("next"); + } + } + return map; + } + + public HashMap toStringKeyedHashMap() { + if (!getClassName().equals(HashMap.class.getName())) { + throw new IllegalStateException(this + " is not a HashMap."); + } + HashMap map = new HashMap(); + SmartInstance[] table = getObjectArray("table"); + for (SmartInstance entry : table) { + while (entry != null) { + map.put(entry.getString("key"), entry.get("value")); + entry = entry.get("next"); + } + } + return map; + } + + public String toString() { + if (className.equals(String.class.getName())) { + return "\"" + new String(getCharArray("value")) + "\""; + } + return shortenClass(className) + " (" + id + ")"; + } + + private String shortenClass(String className) { + int index = className.lastIndexOf('.'); + return className.substring(index + 1); + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/AbstractHprofRecord.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/AbstractHprofRecord.java new file mode 100644 index 0000000000..f0986eeb61 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/AbstractHprofRecord.java @@ -0,0 +1,60 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.HprofFile; + +/** + * + * Base class for the different types of records in an {@link HprofFile}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public abstract class AbstractHprofRecord { + + protected final int time; + + public AbstractHprofRecord(BigByteBuffer buffer, int idSize) { + time = buffer.getInt(); + long size = buffer.getInt(); + if (size < 0) { + /* size is really an unsigned int. */ + size = ((int) size) & 0xFFFFFFFFL; + } + BigByteBuffer safeBuffer = buffer.slice(); + safeBuffer.limit(size); + init(safeBuffer, idSize); + buffer.position(buffer.position() + size); + } + + protected abstract void init(BigByteBuffer buffer, int idSize); +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/HeapDumpEndRecord.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/HeapDumpEndRecord.java new file mode 100644 index 0000000000..6cd1daefd6 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/HeapDumpEndRecord.java @@ -0,0 +1,56 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.HprofFile; + +/** + * Object for the heap dump end record in an {@link HprofFile}, this type of + * record has no content. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + * @see MergedHeapDumpSegmentRecord + */ +public class HeapDumpEndRecord extends AbstractHprofRecord { + + public static final int TAG = 0x2c; + + public HeapDumpEndRecord(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + } + + @Override + protected void init(BigByteBuffer buffer, int idSize) { + /* This record has no content */ + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/HeapDumpRecord.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/HeapDumpRecord.java new file mode 100644 index 0000000000..17c97d4179 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/HeapDumpRecord.java @@ -0,0 +1,366 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.Id; +import com.raytheon.hprof.data.heap.BasicType; +import com.raytheon.hprof.data.heap.dump.ClassDump; +import com.raytheon.hprof.data.heap.dump.InstanceDump; +import com.raytheon.hprof.data.heap.dump.ObjectArrayDump; +import com.raytheon.hprof.data.heap.dump.PrimitiveArrayDump; +import com.raytheon.hprof.data.heap.root.AbstractRoot; +import com.raytheon.hprof.data.heap.root.RootJNIGlobal; +import com.raytheon.hprof.data.heap.root.RootJNILocal; +import com.raytheon.hprof.data.heap.root.RootJavaFrame; +import com.raytheon.hprof.data.heap.root.RootMonitorUsed; +import com.raytheon.hprof.data.heap.root.RootStickyClass; +import com.raytheon.hprof.data.heap.root.RootThreadObject; + +/** + * + * Heap dump Record within an {@link HprofFile}. This object holds most of the + * interesting infromation in a hprof file. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class HeapDumpRecord extends AbstractHprofRecord { + + public static final int TAG = 0x0c; + + protected int idSize; + + protected BigByteBuffer buffer; + + protected List roots; + + protected long[] instancesById; + + protected long[] instancesByClass; + + protected long[] objectArraysById; + + protected long[] primitiveArraysById; + + protected long[] classesById; + + protected Map usedClasses; + + + public HeapDumpRecord(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + } + + @Override + protected void init(BigByteBuffer buffer, int idSize) { + this.buffer = buffer; + this.idSize = idSize; + this.roots = new ArrayList(); + this.usedClasses = new HashMap(); + List instances = new ArrayList(); + List objectArrays = new ArrayList(); + List primitiveArrays = new ArrayList(); + List classes = new ArrayList(); + while (buffer.hasRemaining()) { + byte type = buffer.get(); + switch (type & 0xFF) { + case RootJNIGlobal.TAG: { + roots.add(new RootJNIGlobal(buffer, idSize)); + break; + } + case RootJNILocal.TAG: { + roots.add(new RootJNILocal(buffer, idSize)); + break; + } + case RootJavaFrame.TAG: { + roots.add(new RootJavaFrame(buffer, idSize)); + break; + } + case RootStickyClass.TAG: { + roots.add(new RootStickyClass(buffer, idSize)); + break; + } + case RootMonitorUsed.TAG: { + roots.add(new RootMonitorUsed(buffer, idSize)); + break; + } + case RootThreadObject.TAG: { + roots.add(new RootThreadObject(buffer, idSize)); + break; + } + case ClassDump.TAG: { + classes.add(buffer.position()); + new ClassDump(buffer, idSize); + break; + } + case InstanceDump.TAG: { + instances.add(buffer.position()); + new InstanceDump(buffer, idSize); + break; + } + case ObjectArrayDump.TAG: { + objectArrays.add(buffer.position()); + new ObjectArrayDump(buffer, idSize); + break; + } + case PrimitiveArrayDump.TAG: { + primitiveArrays.add(buffer.position()); + new PrimitiveArrayDump(buffer, idSize); + break; + } + case HeapDumpSegmentRecord.TAG: { + buffer.position(buffer.position() + 8); + break; + } + default: + throw new IllegalStateException("Unknown heap type " + + Integer.toHexString(type & 0xFF)); + } + } + + System.out.println("Sorting all objects..."); + long startTime = System.currentTimeMillis(); + + Collections.sort(instances, new DumpBufferIndexComparator()); + Collections.sort(objectArrays, new DumpBufferIndexComparator()); + Collections.sort(primitiveArrays, new DumpBufferIndexComparator()); + Collections.sort(classes, new DumpBufferIndexComparator()); + + this.instancesById = new long[instances.size()]; + for (int i = 0; i < instances.size(); i++) { + this.instancesById[i] = instances.get(i); + } + + this.objectArraysById = new long[objectArrays.size()]; + for (int i = 0; i < objectArrays.size(); i++) { + this.objectArraysById[i] = objectArrays.get(i); + } + + this.primitiveArraysById = new long[primitiveArrays.size()]; + for (int i = 0; i < primitiveArrays.size(); i++) { + this.primitiveArraysById[i] = primitiveArrays.get(i); + } + + this.classesById = new long[classes.size()]; + for (int i = 0; i < classes.size(); i++) { + this.classesById[i] = classes.get(i); + } + + /* Add one id and one int before the class id */ + Collections.sort(instances, new DumpBufferIndexComparator(idSize + 4)); + + this.instancesByClass = new long[instances.size()]; + for (int i = 0; i < instances.size(); i++) { + this.instancesByClass[i] = instances.get(i); + } + + System.out.println("Spent " + (System.currentTimeMillis() - startTime) + / 1000 + " seconds sorting"); + } + + public ClassDump getClassDump(Id classId) { + if (usedClasses.containsKey(classId)) { + return usedClasses.get(classId); + } + long index = binarySearch(classesById, classId); + if (index < 0) { + return null; + } + buffer.position(index); + ClassDump classDump = new ClassDump(buffer, idSize); + usedClasses.put(classId, classDump); + return classDump; + } + + public InstanceDump getInstance(Id objectId) { + long index = binarySearch(instancesById, objectId); + if (index < 0) { + return null; + } + buffer.position(index); + return new InstanceDump(buffer, idSize); + } + + public ObjectArrayDump getObjectArray(Id objectId) { + long index = binarySearch(objectArraysById, objectId); + if (index < 0) { + return null; + } + buffer.position(index); + return new ObjectArrayDump(buffer, idSize); + } + + public BasicType[] getPrimitiveArray(Id objectId) { + long index = binarySearch(primitiveArraysById, objectId); + if (index < 0) { + return null; + } + buffer.position(index); + return new PrimitiveArrayDump(buffer, idSize).getArray(); + } + + private long binarySearch(long[] array, Id objectId) { + int low = 0; + int high = array.length - 1; + while (low <= high) { + int mid = (low + high) / 2; + buffer.position(array[mid]); + Id id = new Id(buffer, idSize); + + int compval = id.compareTo(objectId); + if (compval < 0) { + low = mid + 1; + } else if (compval > 0) { + high = mid - 1; + } else { + return array[mid]; + } + } + return -1; + } + + public List getInstances(Id classId) { + int low = 0; + int high = instancesByClass.length - 1; + int mid = (low + high) / 2; + while (low <= high) { + mid = (low + high) / 2; + buffer.position(instancesByClass[mid] + idSize + 4); + Id id = new Id(buffer, idSize); + + int compval = id.compareTo(classId); + if (compval < 0) { + low = mid + 1; + } else if (compval > 0) { + high = mid - 1; + } else { + break; + } + } + if (low > high) { + return Collections.emptyList(); + } + List instances = new ArrayList(); + + int next = mid; + buffer.position(instancesByClass[next--]); + InstanceDump instance = new InstanceDump(buffer, idSize); + while (instance.getClassId().equals(classId) && next >= 0) { + instances.add(instance); + buffer.position(instancesByClass[next--]); + instance = new InstanceDump(buffer, idSize); + } + next = mid + 1; + buffer.position(instancesByClass[next++]); + instance = new InstanceDump(buffer, idSize); + while (instance.getClassId().equals(classId) + && next < instancesByClass.length) { + instances.add(instance); + buffer.position(instancesByClass[next++]); + instance = new InstanceDump(buffer, idSize); + } + return instances; + } + + public Map getInstanceFields(InstanceDump instance) { + Map id2type = new HashMap(); + ClassDump classDump = getClassDump(instance.getClassId()); + BigByteBuffer instanceData = instance.getInstanceData(); + while (classDump != null) { + id2type.putAll(classDump.parseInstanceData(instanceData, idSize)); + classDump = getClassDump(classDump.getSuperId()); + } + return id2type; + } + + public Iterator getClassDumps() { + return new Iterator() { + + private int index; + + @Override + public boolean hasNext() { + return index < classesById.length; + } + + @Override + public ClassDump next() { + buffer.position(classesById[index]); + index += 1; + return new ClassDump(buffer, idSize); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + }; + } + + protected class DumpBufferIndexComparator implements Comparator { + + private final int indexOffset; + + protected DumpBufferIndexComparator() { + this(0); + } + + protected DumpBufferIndexComparator(int indexOffset) { + this.indexOffset = indexOffset; + } + + @Override + public int compare(Long o1, Long o2) { + try { + HeapDumpRecord.this.buffer.position(o1 + indexOffset); + Id i1 = new Id(HeapDumpRecord.this.buffer, + HeapDumpRecord.this.idSize); + HeapDumpRecord.this.buffer.position(o2 + indexOffset); + Id i2 = new Id(HeapDumpRecord.this.buffer, + HeapDumpRecord.this.idSize); + return i1.compareTo(i2); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }; + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/HeapDumpSegmentRecord.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/HeapDumpSegmentRecord.java new file mode 100644 index 0000000000..38c3f21846 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/HeapDumpSegmentRecord.java @@ -0,0 +1,62 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.HprofFile; + +/** + * + * Object for a segmented heap dump record in an {@link HprofFile}. The segments + * are not actually processed seperately, this record is just used as a place + * holder until all segments are found and then all segments are processed + * together as a {@link MergedHeapDumpSegmentRecord}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + * @see MergedHeapDumpSegmentRecord + */ +public class HeapDumpSegmentRecord extends AbstractHprofRecord { + + public static final int TAG = 0x1c; + + public HeapDumpSegmentRecord(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + } + + @Override + protected void init(BigByteBuffer buffer, int idSize) { + /* + * Don't actually process this type of record, it gets processed after + * all the segments are found. + */ + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/LoadClassRecord.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/LoadClassRecord.java new file mode 100644 index 0000000000..f558d9bc68 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/LoadClassRecord.java @@ -0,0 +1,88 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.Id; + +/** + * + * Record of a loaded class in an {@link HprofFile}. Only really used for + * correlating class ids in the dump to their names. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class LoadClassRecord extends AbstractHprofRecord { + + public static final int TAG = 0x02; + + private int classSerialNumber; + + private Id classId; + + private int stackSerialNumber; + + private Id classNameId; + + public LoadClassRecord(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + } + + @Override + protected void init(BigByteBuffer buffer, int idSize) { + classSerialNumber = buffer.getInt(); + classId = new Id(buffer, idSize); + stackSerialNumber = buffer.getInt(); + classNameId = new Id(buffer, idSize); + } + + public static int getTag() { + return TAG; + } + + public int getClassSerialNumber() { + return classSerialNumber; + } + + public Id getClassId() { + return classId; + } + + public int getStackSerialNumber() { + return stackSerialNumber; + } + + public Id getClassNameId() { + return classNameId; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/MergedHeapDumpSegmentRecord.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/MergedHeapDumpSegmentRecord.java new file mode 100644 index 0000000000..17f26479b7 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/MergedHeapDumpSegmentRecord.java @@ -0,0 +1,55 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data; + +import com.raytheon.hprof.BigByteBuffer; + +/** + * + * Represents all the segments in a {@link HeapDumpSegmentRecord} together so + * that all segments can be treeated as a continuous {@link HeapDumpRecord}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class MergedHeapDumpSegmentRecord extends HeapDumpRecord { + + public MergedHeapDumpSegmentRecord(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + buffer.position(0); + super.init(buffer, idSize); + } + + @Override + protected void init(BigByteBuffer buffer, int idSize) { + /* This is not the full buffer */ + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/StackFrameRecord.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/StackFrameRecord.java new file mode 100644 index 0000000000..e30acbe13e --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/StackFrameRecord.java @@ -0,0 +1,100 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data; +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.Id; + +/** + * + * Represents a stack frame within an {@link HprofFile}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class StackFrameRecord extends AbstractHprofRecord { + + public static final int TAG = 0x04; + + private Id stackFrameId; + + private Id methodNameId; + + private Id methodSigId; + + private Id sourceFileId; + + private int classSerialNumber; + + private int lineNumber; + + public StackFrameRecord(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + } + + @Override + protected void init(BigByteBuffer buffer, int idSize) { + stackFrameId = new Id(buffer, idSize); + methodNameId = new Id(buffer, idSize); + methodSigId = new Id(buffer, idSize); + sourceFileId = new Id(buffer, idSize); + classSerialNumber = buffer.getInt(); + lineNumber = buffer.getInt(); + } + + public static int getTag() { + return TAG; + } + + public Id getStackFrameId() { + return stackFrameId; + } + + public Id getMethodNameId() { + return methodNameId; + } + + public Id getMethodSigId() { + return methodSigId; + } + + public Id getSourceFileId() { + return sourceFileId; + } + + public int getClassSerialNumber() { + return classSerialNumber; + } + + public int getLineNumber() { + return lineNumber; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/StackTraceRecord.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/StackTraceRecord.java new file mode 100644 index 0000000000..d74f0588bf --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/StackTraceRecord.java @@ -0,0 +1,78 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data; +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.Id; + +/** + * + * Represents a stack trace within an {@link HprofFile}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class StackTraceRecord extends AbstractHprofRecord { + + public static final int TAG = 0x05; + + private int stackSerialNumber; + + private int threadSerialNumber; + + private Id[] stackFrames; + + public StackTraceRecord(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + } + + @Override + protected void init(BigByteBuffer buffer, int idSize) { + stackSerialNumber = buffer.getInt(); + threadSerialNumber = buffer.getInt(); + int numberOfFrames = buffer.getInt(); + if (numberOfFrames < 0) { + numberOfFrames = 0; + } + stackFrames = new Id[numberOfFrames]; + for (int i = 0; i < numberOfFrames; i++) { + stackFrames[i] = new Id(buffer, idSize); + } + } + + public int getStackSerialNumber() { + return stackSerialNumber; + } + + public int getThreadSerialNumber() { + return threadSerialNumber; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/StringRecord.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/StringRecord.java new file mode 100644 index 0000000000..0ea6e03d06 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/StringRecord.java @@ -0,0 +1,71 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.Id; + +/** + * + * Represents a string within an {@link HprofFile}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class StringRecord extends AbstractHprofRecord { + + public static final int TAG = 0x01; + + private Id id; + + private String string; + + public StringRecord(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + } + + @Override + protected void init(BigByteBuffer buffer, int idSize) { + id = new Id(buffer, idSize); + byte[] string = new byte[(int) buffer.remaining()]; + buffer.get(string); + this.string = new String(string).intern(); + } + + public Id getId() { + return id; + } + + public String getString() { + return string; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/BasicType.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/BasicType.java new file mode 100644 index 0000000000..a4d439916a --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/BasicType.java @@ -0,0 +1,233 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap; + +import java.nio.ByteBuffer; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.Id; +import com.raytheon.hprof.data.HeapDumpRecord; + +/** + * + * Represents a basic type within a {@link HeapDumpRecord}. Used primarily for + * fields of objects starts with a byte indicating the type of the field and + * depending on the bytes holds either the primitive value or an object id. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class BasicType { + + private static final byte OBJECT = 2; + + private static final byte BOOLEAN = 4; + + private static final byte CHAR = 5; + + private static final byte FLOAT = 6; + + private static final byte DOUBLE = 7; + + private static final byte BYTE = 8; + + private static final byte SHORT = 9; + + private static final byte INT = 10; + + private static final byte LONG = 11; + + private final byte type; + + private final byte[] data; + + public BasicType(BigByteBuffer buffer, int idSize) { + this(buffer, buffer.get(), idSize); + } + + public BasicType(BigByteBuffer buffer, byte type, int idSize) { + this.type = type; + switch (type) { + case OBJECT: + data = new byte[idSize]; + break; + case FLOAT: + case INT: + data = new byte[4]; + break; + case BOOLEAN: + case BYTE: + data = new byte[1]; + break; + case CHAR: + case SHORT: + data = new byte[2]; + break; + case DOUBLE: + case LONG: + data = new byte[8]; + break; + default: + throw new IllegalArgumentException("Unknown basic type " + + Integer.toHexString(type & 0xFF)); + } + buffer.get(data); + } + + public boolean isObject() { + return type == OBJECT; + } + + public boolean isBoolean() { + return type == BOOLEAN; + } + + public boolean isChar() { + return type == CHAR; + } + + public boolean isFloat() { + return type == FLOAT; + } + + public boolean isDouble() { + return type == DOUBLE; + } + + public boolean isByte() { + return type == BYTE; + } + + public boolean isShort() { + return type == SHORT; + } + + public boolean isInt() { + return type == INT; + } + + public boolean isLong() { + return type == LONG; + } + + public Id getObjectId() { + if (!isObject()) { + throw new IllegalStateException(type + " is not an OBJECT"); + } + return new Id(ByteBuffer.wrap(data), data.length); + } + + public boolean getBoolean() { + if (!isBoolean()) { + throw new IllegalStateException(type + " is not a BOOLEAN"); + } + return ByteBuffer.wrap(data).get() != 0; + } + + public char getChar() { + if (!isChar()) { + throw new IllegalStateException(type + " is not a CHAR"); + } + return ByteBuffer.wrap(data).getChar(); + } + + public float getFloat() { + if (!isFloat()) { + throw new IllegalStateException(type + " is not a FLOAT"); + } + return ByteBuffer.wrap(data).getFloat(); + } + + public double getDouble() { + if (!isDouble()) { + throw new IllegalStateException(type + " is not a DOUBLE"); + } + return ByteBuffer.wrap(data).getDouble(); + } + + public byte getByte() { + if (!isByte()) { + throw new IllegalStateException(type + " is not a BYTE"); + } + return data[0]; + } + + public short getShort() { + if (!isShort()) { + throw new IllegalStateException(type + " is not a SHORT"); + } + return ByteBuffer.wrap(data).getShort(); + } + + public int getInt() { + if (!isInt()) { + throw new IllegalStateException(type + " is not an INT"); + } + return ByteBuffer.wrap(data).getInt(); + } + + public long getLong() { + if (!isLong()) { + throw new IllegalStateException(type + " is not a LONG"); + } + return ByteBuffer.wrap(data).getLong(); + } + + public int getSize() { + return data.length; + } + + @Override + public String toString() { + switch (type) { + case OBJECT: + return "Object: " + getObjectId(); + case FLOAT: + return "Float: " + getFloat(); + case INT: + return "Int: " + getInt(); + case BOOLEAN: + return "Boolean: " + getBoolean(); + case BYTE: + return "Byte: " + getByte(); + case CHAR: + return "Char: " + getChar(); + case SHORT: + return "Short: " + getShort(); + case DOUBLE: + return " Double: " + getDouble(); + case LONG: + return "Long: " + getLong(); + default: + return "Unknown basic type " + Integer.toHexString(type & 0xFF); + } + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/AbstractDump.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/AbstractDump.java new file mode 100644 index 0000000000..7dc71ae7c0 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/AbstractDump.java @@ -0,0 +1,58 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.dump; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.Id; +import com.raytheon.hprof.data.HeapDumpRecord; + +/** + * + * Base class for all the types of data dumped into a {@link HeapDumpRecord}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class AbstractDump { + + protected final Id id; + + protected final int stackSerialNumber; + + protected AbstractDump(BigByteBuffer buffer, int idSize) { + id = new Id(buffer, idSize); + stackSerialNumber = buffer.getInt(); + } + + public Id getId() { + return id; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/ClassDump.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/ClassDump.java new file mode 100644 index 0000000000..0272bcb435 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/ClassDump.java @@ -0,0 +1,124 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.dump; + +import java.util.HashMap; +import java.util.Map; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.Id; +import com.raytheon.hprof.data.HeapDumpRecord; +import com.raytheon.hprof.data.heap.BasicType; + +/** + * + * Class data for a single class in a {@link HeapDumpRecord}. This class + * contains most of the same information as a {@link Class} object, in a much + * more cryptic form. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class ClassDump extends AbstractDump { + + public static final int TAG = 0x20; + + private final Id superId; + + private final int instanceSize; + + private final BasicType[] constantPool; + + private final Id[] staticFieldIds; + + private final BasicType[] staticFieldValues; + + private final Id[] instanceFieldIds; + + private final byte[] instanceFieldTypes; + + public ClassDump(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + superId = new Id(buffer, idSize); + /* Id classLoaderId = */new Id(buffer, idSize); + /* Id signerId = */new Id(buffer, idSize); + /* Id protectionDomainId = */new Id(buffer, idSize); + /* Id reservedId1 = */new Id(buffer, idSize); + /* Id reservedId2 = */new Id(buffer, idSize); + instanceSize = buffer.getInt(); + short constantPoolSize = buffer.getShort(); + constantPool = new BasicType[constantPoolSize]; + for (int i = 0; i < constantPoolSize; i++) { + /* short constantPoolIndex = */buffer.getShort(); + constantPool[i] = new BasicType(buffer, idSize); + } + short numberOfStaticFields = buffer.getShort(); + staticFieldIds = new Id[numberOfStaticFields]; + staticFieldValues = new BasicType[numberOfStaticFields]; + for (int i = 0; i < numberOfStaticFields; i++) { + staticFieldIds[i] = new Id(buffer, idSize); + staticFieldValues[i] = new BasicType(buffer, idSize); + } + short numberOfInstanceFields = buffer.getShort(); + instanceFieldIds = new Id[numberOfInstanceFields]; + instanceFieldTypes = new byte[numberOfInstanceFields]; + for (int i = 0; i < numberOfInstanceFields; i++) { + instanceFieldIds[i] = new Id(buffer, idSize); + instanceFieldTypes[i] = buffer.get(); + } + } + + public Id getSuperId() { + return superId; + } + + public int getInstanceSize() { + return instanceSize; + } + + public Map parseInstanceData(BigByteBuffer buffer, int idSize) { + Map results = new HashMap(); + for (int i = 0; i < instanceFieldIds.length; i++) { + BasicType type = new BasicType(buffer, instanceFieldTypes[i], + idSize); + results.put(instanceFieldIds[i], type); + } + return results; + } + + public Map getStaticFields(){ + Map results = new HashMap(instanceFieldIds.length * 2); + for(int i = 0 ; i < staticFieldIds.length ; i += 1){ + results.put(staticFieldIds[i], staticFieldValues[i]); + } + return results; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/InstanceDump.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/InstanceDump.java new file mode 100644 index 0000000000..4317fb7575 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/InstanceDump.java @@ -0,0 +1,69 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.dump; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.Id; +import com.raytheon.hprof.data.HeapDumpRecord; + +/** + * + * Data for a single instance of an object in a {@link HeapDumpRecord}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class InstanceDump extends AbstractDump { + + public static final int TAG = 0x21; + + private final Id classId; + + private final BigByteBuffer instanceData; + + public InstanceDump(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + classId = new Id(buffer, idSize); + int size = buffer.getInt(); + instanceData = buffer.slice(); + instanceData.limit(size); + buffer.position(buffer.position() + size); + } + + public Id getClassId() { + return classId; + } + + public BigByteBuffer getInstanceData() { + instanceData.rewind(); + return instanceData; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/ObjectArrayDump.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/ObjectArrayDump.java new file mode 100644 index 0000000000..9b8cdc34fd --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/ObjectArrayDump.java @@ -0,0 +1,69 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.dump; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.Id; +import com.raytheon.hprof.data.HeapDumpRecord; + +/** + * + * Data for an array of object in a {@link HeapDumpRecord}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class ObjectArrayDump extends AbstractDump { + + public static final int TAG = 0x22; + + private final Id arrayClassId; + + private final Id[] array; + + public ObjectArrayDump(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + int numElements = buffer.getInt(); + arrayClassId = new Id(buffer, idSize); + array = new Id[numElements]; + for (int i = 0; i < numElements; i++) { + array[i] = new Id(buffer, idSize); + } + } + + public Id[] getArray() { + return array; + } + + public Id getArrayClassId() { + return arrayClassId; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/PrimitiveArrayDump.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/PrimitiveArrayDump.java new file mode 100644 index 0000000000..1406cbf7f4 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/dump/PrimitiveArrayDump.java @@ -0,0 +1,63 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.dump; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.data.HeapDumpRecord; +import com.raytheon.hprof.data.heap.BasicType; + +/** + * + * Data for an array of primitives in a {@link HeapDumpRecord}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class PrimitiveArrayDump extends AbstractDump { + + public static final int TAG = 0x23; + + private final BasicType[] array; + + public PrimitiveArrayDump(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + int numElements = buffer.getInt(); + byte type = buffer.get(); + array = new BasicType[numElements]; + for (int i = 0; i < numElements; i++) { + array[i] = new BasicType(buffer, type, idSize); + } + } + + public BasicType[] getArray() { + return array; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/AbstractRoot.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/AbstractRoot.java new file mode 100644 index 0000000000..cc3263f76d --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/AbstractRoot.java @@ -0,0 +1,55 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.root; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.Id; +import com.raytheon.hprof.data.HeapDumpRecord; + +/** + * + * Base class for all garbage collection(GC) roots in a {@link HeapDumpRecord}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class AbstractRoot { + + protected final Id id; + + protected AbstractRoot(BigByteBuffer buffer, int idSize) { + id = new Id(buffer, idSize); + } + + public Id getId() { + return id; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/AbstractRunningRoot.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/AbstractRunningRoot.java new file mode 100644 index 0000000000..532cf212cc --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/AbstractRunningRoot.java @@ -0,0 +1,55 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.root; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.data.HeapDumpRecord; + +/** + * + * Base class for all running roots in a {@link HeapDumpRecord}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class AbstractRunningRoot extends AbstractRoot { + + protected final int threadSerialNumber; + + protected AbstractRunningRoot(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + threadSerialNumber = buffer.getInt(); + } + + public int getThreadSerialNumber() { + return threadSerialNumber; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootJNIGlobal.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootJNIGlobal.java new file mode 100644 index 0000000000..c199233f27 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootJNIGlobal.java @@ -0,0 +1,56 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.root; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.Id; + +/** + * + * GC Root for a JNI Global. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class RootJNIGlobal extends AbstractRoot { + public static final int TAG = 0x01; + + private final Id globalRefId; + + public RootJNIGlobal(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + globalRefId = new Id(buffer, idSize); + } + + public Id getGlobalRefId() { + return globalRefId; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootJNILocal.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootJNILocal.java new file mode 100644 index 0000000000..dcd4bac896 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootJNILocal.java @@ -0,0 +1,56 @@ +/** + * This software was developed and / or mimport com.raytheon.hprof.BigByteBuffer; +to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.root; + +import com.raytheon.hprof.BigByteBuffer; + +/** + * + * GC Root for a JNI Local. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class RootJNILocal extends AbstractRunningRoot { + + public static final int TAG = 0x02; + + private final int frameNumberInStack; + + public RootJNILocal(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + frameNumberInStack = buffer.getInt(); + } + + public int getFrameNumberInStack() { + return frameNumberInStack; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootJavaFrame.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootJavaFrame.java new file mode 100644 index 0000000000..8c22ecc634 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootJavaFrame.java @@ -0,0 +1,56 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.root; + +import com.raytheon.hprof.BigByteBuffer; + +/** + * + * GC Root for a single java stack frame. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class RootJavaFrame extends AbstractRunningRoot { + + public static final int TAG = 0x03; + + private final int frameNumberInStack; + + public RootJavaFrame(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + frameNumberInStack = buffer.getInt(); + } + + public int getFrameNumberInStack() { + return frameNumberInStack; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootMonitorUsed.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootMonitorUsed.java new file mode 100644 index 0000000000..b4903d7a80 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootMonitorUsed.java @@ -0,0 +1,50 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.root; + +import com.raytheon.hprof.BigByteBuffer; +import com.raytheon.hprof.HprofFile; + +/** + * + * A type of root that appears in an {@link HprofFile}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + * @see HprofFile + */ +public class RootMonitorUsed extends AbstractRoot { + public static final int TAG = 0x07; + + public RootMonitorUsed(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootStickyClass.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootStickyClass.java new file mode 100644 index 0000000000..711aaf8e91 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootStickyClass.java @@ -0,0 +1,48 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.root; + +import com.raytheon.hprof.BigByteBuffer; + +/** + * + * GC Root for a sticky class. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class RootStickyClass extends AbstractRoot { + public static final int TAG = 0x05; + + public RootStickyClass(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootThreadObject.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootThreadObject.java new file mode 100644 index 0000000000..6614decabe --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/hprof/data/heap/root/RootThreadObject.java @@ -0,0 +1,56 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.hprof.data.heap.root; + +import com.raytheon.hprof.BigByteBuffer; + +/** + * + * GC Root for a thread object. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class RootThreadObject extends AbstractRunningRoot { + + public static final int TAG = 0x08; + + private final int stackTraceSerialNumber; + + public RootThreadObject(BigByteBuffer buffer, int idSize) { + super(buffer, idSize); + stackTraceSerialNumber = buffer.getInt(); + } + + public int getStackTraceSerialNumber() { + return stackTraceSerialNumber; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/AbstractExporter.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/AbstractExporter.java new file mode 100644 index 0000000000..57d3bfd8f6 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/AbstractExporter.java @@ -0,0 +1,123 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.hprof; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.SmartInstance; +import com.raytheon.hprof.data.heap.dump.InstanceDump; + +/** + * + * Base class for objects exporting information from an hprof file. Provides a + * framework for creating and commenting a file for output. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public abstract class AbstractExporter { + + protected final HprofFile hprof; + + private final File outputDirectory; + + private Writer writer; + + public AbstractExporter(HprofFile hprof, File outputDirectory) { + this.hprof = hprof; + this.outputDirectory = outputDirectory; + } + + public void export() { + System.out.println(getInfo()); + try { + exportInternal(); + } catch (Throwable e) { + e.printStackTrace(); + } + close(); + } + + protected abstract String getFileName(); + + protected abstract void exportInternal() throws IOException; + + protected String getComment() { + return null; + } + + protected String getInfo() { + return "Generating output for " + getClass().getSimpleName() + "..."; + } + + protected void print(String output) throws IOException { + if (writer == null) { + writer = new BufferedWriter(new FileWriter(new File( + outputDirectory, getFileName()))); + String comment = getComment(); + if (comment != null) { + println(comment); + } + } + writer.append(output); + } + + protected void println(String output) throws IOException { + print(output + "\n"); + } + + protected void close() { + if (writer != null) { + try { + writer.close(); + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + + protected List getInstances(String className) { + List instances = hprof.getInstances(className); + List smartInstances = new ArrayList( + instances.size()); + for (InstanceDump instance : instances) { + smartInstances.add(new SmartInstance(hprof, instance)); + } + return smartInstances; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/CaveExporter.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/CaveExporter.java new file mode 100644 index 0000000000..d8c61ebed8 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/CaveExporter.java @@ -0,0 +1,86 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.hprof; + +import java.io.File; +import java.io.IOException; + +import com.raytheon.hprof.HprofFile; + +/** + * + * Main class for exporting information from a cave heap dump. Parses command + * line options and passes all the real work to various exporters. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class CaveExporter { + + public static void main(String[] args) { + if (args.length < 1) { + System.out + .println("Provide some args, an hprof file is required, an output directory is optional."); + System.exit(1); + } + HprofFile hprof; + try { + hprof = new HprofFile(args[0]); + } catch (IOException e) { + throw new IllegalArgumentException("Error opening hprof file: " + + args[0], e); + } + + File outputDir = null; + if (args.length > 1) { + outputDir = new File(args[1]); + } else { + outputDir = new File("."); + } + if (!outputDir.isDirectory()) { + if (!outputDir.mkdirs()) { + throw new IllegalArgumentException( + "Cannot make output directory: " + outputDir); + } + } + DisplayedResourcesExporter displayPanes = new DisplayedResourcesExporter( + hprof, outputDir); + displayPanes.export(); + new RequestableResourceExporter(hprof, outputDir, + displayPanes.getResources()).export(); + + new D2DGridResourceExporter(hprof, outputDir).export(); + new GLInfoExporter(hprof, outputDir).export(); + new InputHandlerExporter(hprof, outputDir).export(); + new D2DProcedureDialogExporter(hprof, outputDir).export(); + new GFEResourceExporter(hprof, outputDir).export(); + + } +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/D2DGridResourceExporter.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/D2DGridResourceExporter.java new file mode 100644 index 0000000000..839bd4cbc4 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/D2DGridResourceExporter.java @@ -0,0 +1,206 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.hprof; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.SmartInstance; + +/** + * + * Export information about D2DGridResources, mostly analyze memory usage of raw + * data. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class D2DGridResourceExporter extends RequestableResourceExporter { + + private final boolean useDataMap = false; + + public D2DGridResourceExporter(HprofFile hprof, File outputDirectory) { + super(hprof, outputDirectory, null); + } + + @Override + protected String getFileName() { + return "d2dGridResources.txt"; + } + + @Override + protected String getComment() { + StringBuilder comment = new StringBuilder(); + comment.append("# This file contains information about D2DGridResources, there are 4 sections:\n"); + comment.append("# 1) Metadata maps for each resource. \n"); + comment.append("# 2) Size and type of all GeneralGridData. \n"); + comment.append("# 3) Total size of each resource. \n"); + comment.append("# 4) Total size of all resources.\n#"); + + return comment.toString(); + } + + @Override + protected String getInfo() { + return "Generating output for D2DGridResource..."; + } + + @Override + protected void exportInternal() throws IOException { + List resources = getInstances("com.raytheon.viz.grid.rsc.general.D2DGridResource"); + if (resources.isEmpty()) { + return; + } + println("# Section 1 metadata maps for each resource."); + for (SmartInstance resource : resources) { + outputResource(resource); + } + println("# Section 2 size and type of all GeneralGridData."); + Map sizes = new HashMap(); + if (useDataMap) { + for (SmartInstance resource : resources) { + int floats = 0; + ConcurrentHashMap dataMap = resource + .get("dataMap").toConcurrentHashMap(); + if (!dataMap.isEmpty()) { + println(resource + "{"); + for (Entry dataEntry : dataMap + .entrySet()) { + List dataList = dataEntry.getValue() + .toArrayList(); + for (SmartInstance gridData : dataList) { + floats += outputGeneralGridData(gridData); + } + } + println("}"); + } + sizes.put(resource, floats); + } + } else { + for (SmartInstance resource : resources) { + int floats = 0; + ArrayList requests = resource.get("requestJob") + .get("requests").toArrayList(); + if (!requests.isEmpty()) { + println(resource + "{"); + for (SmartInstance request : requests) { + SmartInstance data = request.get("gridData"); + if (data != null) { + List dataList = data.toArrayList(); + for (SmartInstance gridData : dataList) { + floats += outputGeneralGridData(gridData); + } + } + } + println("}"); + } + sizes.put(resource, floats); + } + } + println("# Section 3 total size of each resource."); + List> sizesList = new ArrayList>( + sizes.entrySet()); + Collections.sort(sizesList, + new Comparator>() { + + @Override + public int compare(Entry e1, + Entry e2) { + return e1.getValue().compareTo(e2.getValue()); + } + }); + int totalFloats = 0; + for (Entry entry : sizesList) { + SmartInstance resource = entry.getKey(); + int floats = entry.getValue(); + int size = floats * 4 / 1024; + String suffix = "KB"; + if (size > 1024) { + size /= 1024; + suffix = "MB"; + } + println(resource + " uses is " + size + suffix); + totalFloats += floats; + } + println("# Section 4 total size of all resources."); + println("Total memory usage for " + resources.size() + + " resources is " + totalFloats * 4 / 1024 / 1024 + "MB"); + } + + protected int outputGeneralGridData(SmartInstance generalGridData) + throws IOException { + println(" " + generalGridData + "{"); + SmartInstance gridGeometry = generalGridData.get("gridGeometry"); + SmartInstance gridRange = gridGeometry.get("gridRange"); + int[] index = gridRange.getIntArray("index"); + int width = index[2] - index[0]; + int height = index[3] - index[1]; + println(" dimensions are " + width + "x" + height + ""); + + int floats = 0; + SmartInstance buffer = generalGridData.get("scalarData"); + if (buffer != null) { + int capacity = buffer.getInt("capacity"); + println(" scalarData contains " + capacity + " floats."); + floats += capacity; + } + buffer = generalGridData.get("direction"); + if (buffer != null) { + int capacity = buffer.getInt("capacity"); + println(" direction contains " + capacity + " floats."); + floats += capacity; + } + buffer = generalGridData.get("uComponent"); + if (buffer != null) { + int capacity = buffer.getInt("capacity"); + println(" uComponent contains " + capacity + " floats."); + floats += capacity; + } + buffer = generalGridData.get("vComponent"); + if (buffer != null) { + int capacity = buffer.getInt("capacity"); + println(" vComponent contains " + capacity + " floats."); + floats += capacity; + } + println(" memory usage is " + floats * 4 / 1024 + "KB"); + println(" }"); + return floats; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/D2DProcedureDialogExporter.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/D2DProcedureDialogExporter.java new file mode 100644 index 0000000000..7aa231de27 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/D2DProcedureDialogExporter.java @@ -0,0 +1,120 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.hprof; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.Id; +import com.raytheon.hprof.SmartInstance; +import com.raytheon.hprof.data.HeapDumpRecord; +import com.raytheon.hprof.data.heap.BasicType; +import com.raytheon.hprof.data.heap.dump.ClassDump; + +/** + * + * Export information about D2DProcedures dialogs + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class D2DProcedureDialogExporter extends AbstractExporter { + + public D2DProcedureDialogExporter(HprofFile hprof, File outputDirectory) { + super(hprof, outputDirectory); + } + + @Override + protected String getFileName() { + return "d2dProcedureDialogs.txt"; + } + + @Override + protected String getComment() { + return "# This file contains information about open D2D Procedure Dialogs."; + } + + @Override + protected String getInfo() { + return "Generating output for D2D Procedure Dialogs..."; + } + + @Override + protected void exportInternal() throws IOException { + Id classId = hprof + .lookUpClass("com.raytheon.uf.viz.d2d.ui.dialogs.procedures.ProcedureDlg"); + if (classId == null) { + System.out.println("None found."); + return; + } + HeapDumpRecord heapDump = hprof.getHeapDump(); + ClassDump classDump = heapDump.getClassDump(classId); + SmartInstance openDialogs = null; + for (Entry staticEntry : classDump.getStaticFields() + .entrySet()) { + String name = hprof.getString(staticEntry.getKey()); + if ("openDialogs".equals(name)) { + openDialogs = new SmartInstance(hprof, + heapDump.getInstance(staticEntry.getValue() + .getObjectId())); + break; + } + } + HashMap openDialogsMap = openDialogs + .toStringKeyedHashMap(); + if (!openDialogsMap.isEmpty()) { + println("ProcedureDlg.openDialogs{"); + for (Entry entry : openDialogsMap.entrySet()) { + println(" " + entry.getKey() + " = " + entry.getValue()); + + } + println("}\n"); + } + + List dialogs = getInstances("com.raytheon.uf.viz.d2d.ui.dialogs.procedures.ProcedureDlg"); + for (SmartInstance dialog : dialogs) { + outputProcedureDialog(dialog); + } + } + + protected void outputProcedureDialog(SmartInstance dialog) + throws IOException { + + println(dialog + "{"); + println(" fileName = " + dialog.getString("fileName") + ""); + println("}"); + + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/DisplayPaneContainerExporter.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/DisplayPaneContainerExporter.java new file mode 100644 index 0000000000..771c394872 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/DisplayPaneContainerExporter.java @@ -0,0 +1,109 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.hprof; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.SmartInstance; + +/** + * + * Base class for exporters that want to display information about things in + * DispalyPaneContainers/PaneManagers. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 8, 2014           bsteffen    Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public abstract class DisplayPaneContainerExporter extends AbstractExporter { + + public DisplayPaneContainerExporter(HprofFile hprof, File outputDirectory) { + super(hprof, outputDirectory); + } + + @Override + protected void exportInternal() throws IOException { + try { + outputVizMultiPaneEditors("com.raytheon.uf.viz.core.maps.display.VizMapEditor"); + } catch (Throwable e) { + e.printStackTrace(); + } + try { + outputVizMultiPaneEditors("com.raytheon.uf.viz.xy.VizXyEditor"); + } catch (Throwable e) { + e.printStackTrace(); + } + try { + outputSideViews(); + } catch (Throwable e) { + e.printStackTrace(); + } + + } + + protected void outputVizMultiPaneEditors(String className) + throws IOException { + List editors = getInstances(className); + for (SmartInstance editor : editors) { + outputVizMultiPaneEditor(editor); + } + } + + protected void outputSideViews() throws IOException { + List views = getInstances("com.raytheon.uf.viz.d2d.ui.map.SideView"); + for (SmartInstance view : views) { + outputSideView(view); + } + } + + protected void outputVizMultiPaneEditor(SmartInstance editor) + throws IOException { + SmartInstance paneManager = editor.get("editorInput") + .get("paneManager"); + + println(editor + "{"); + outputPaneManager(paneManager); + println("}"); + } + + protected void outputSideView(SmartInstance view) throws IOException { + SmartInstance paneManager = view.get("paneManager"); + + println(view + "{"); + outputPaneManager(paneManager); + println("}"); + } + + protected abstract void outputPaneManager(SmartInstance paneManager) + throws IOException; + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/DisplayedResourcesExporter.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/DisplayedResourcesExporter.java new file mode 100644 index 0000000000..c713f954de --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/DisplayedResourcesExporter.java @@ -0,0 +1,106 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.hprof; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.SmartInstance; + +/** + * + * Export information about all the resources in display pane containers. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class DisplayedResourcesExporter extends DisplayPaneContainerExporter { + + private final List resources = new ArrayList(); + + public DisplayedResourcesExporter(HprofFile hprof, File outputDirectory) { + super(hprof, outputDirectory); + } + + @Override + protected String getFileName() { + return "displayedResources.txt"; + } + + @Override + protected String getComment() { + StringBuilder comment = new StringBuilder(); + comment.append("# This file contains descriptors and resources of all the display pane containers\\n"); + comment.append("# (SideViews VizMapEditors, and VizXyEditors)\n"); + return comment.toString(); + } + + @Override + protected String getInfo() { + return "Generating output for DisplayPaneContainer resources..."; + } + + @Override + protected void outputPaneManager( + SmartInstance paneManager) throws IOException { + List displayPanes = paneManager.get("displayPanes") + .toArrayList(); + for (SmartInstance dispalyPane : displayPanes) { + SmartInstance descriptor = dispalyPane.get("renderableDisplay") + .get("descriptor"); + SmartInstance resourceList = descriptor.get("resourceList"); + SmartInstance[] array = resourceList.getObjectArray("array"); + println(" " + descriptor + "{"); + for (SmartInstance resourcePair : array) { + SmartInstance resource = resourcePair.get("resource"); + if (resource == null) { + SmartInstance resourceData = resourcePair + .get("resourceData"); + if (resourceData == null) { + println(" Empty Resource Pair"); + } else { + println(" " + resourceData + "(resource was null)"); + } + } else { + println(" " + resource); + resources.add(resource); + } + } + println(" }"); + } + } + public List getResources() { + return resources; + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/GFEResourceExporter.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/GFEResourceExporter.java new file mode 100644 index 0000000000..7bccbdb52c --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/GFEResourceExporter.java @@ -0,0 +1,82 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.hprof; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.SmartInstance; + +/** + * + * Export information about GFEResources, really just the parmId at this point. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class GFEResourceExporter extends AbstractExporter { + + public GFEResourceExporter(HprofFile hprof, File outputDirectory) { + super(hprof, outputDirectory); + } + + @Override + protected String getFileName() { + return "gfeResources.txt"; + } + + @Override + protected String getComment() { + return "# This file contains the parmId of every GFE Resource"; + } + + @Override + protected String getInfo() { + return "Generating output for GFEResource..."; + } + + @Override + protected void exportInternal() throws IOException { + List resources = getInstances("com.raytheon.viz.gfe.rsc.GFEResource"); + if (resources.isEmpty()) { + return; + } + for (SmartInstance resource : resources) { + println(resource + "{"); + println(" parmID = " + + resource.get("parm").get("gridInfo").get("parmID") + .getString("parmId")); + println("}"); + } + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/GLInfoExporter.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/GLInfoExporter.java new file mode 100644 index 0000000000..dfc1795815 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/GLInfoExporter.java @@ -0,0 +1,116 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.hprof; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map.Entry; + +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.Id; +import com.raytheon.hprof.SmartInstance; +import com.raytheon.hprof.data.HeapDumpRecord; +import com.raytheon.hprof.data.heap.BasicType; +import com.raytheon.hprof.data.heap.dump.ClassDump; + +/** + * + * Export information about openGl memory useage. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class GLInfoExporter extends AbstractExporter { + + public GLInfoExporter(HprofFile hprof, File outputDirectory) { + super(hprof, outputDirectory); + } + + @Override + protected String getFileName() { + return "glInfo.txt"; + } + + @Override + protected String getComment() { + return "# This file contains information about possible openGL memory usage."; + } + + @Override + protected String getInfo() { + return "Generating output for GL..."; + } + + @Override + protected void exportInternal() throws IOException { + Id classId = hprof + .lookUpClass("com.raytheon.viz.core.gl.internal.cache.ImageCache"); + HeapDumpRecord heapDump = hprof.getHeapDump(); + ClassDump classDump = heapDump.getClassDump(classId); + SmartInstance textureCache = null; + SmartInstance memoryCache = null; + for (Entry staticEntry : classDump.getStaticFields() + .entrySet()) { + String name = hprof.getString(staticEntry.getKey()); + if ("textureCache".equals(name)) { + textureCache = new SmartInstance(hprof, + heapDump.getInstance(staticEntry.getValue() + .getObjectId())); + } else if ("memoryCache".equals(name)) { + memoryCache = new SmartInstance(hprof, + heapDump.getInstance(staticEntry.getValue() + .getObjectId())); + } + } + long memUsed = memoryCache.getLong("curSize"); + long memMax = memoryCache.getLong("maxSize"); + long texUsed = textureCache.getLong("curSize"); + long texMax = textureCache.getLong("maxSize"); + println("RAM texture cache using " + (memUsed / 1024 / 1024) + "MB of " + + (memMax / 1024 / 1024) + "MB"); + println("GL texture cache using " + (texUsed / 1024 / 1024) + "MB of " + + (texMax / 1024 / 1024) + "MB"); + List geoms = getInstances("com.raytheon.viz.core.gl.GLGeometryObject2D"); + int coords = 0; + for (SmartInstance geom : geoms) { + SmartInstance lengthBuffer = geom.get("compiledLengths"); + if (lengthBuffer != null) { + int[] lengthArr = lengthBuffer.getIntArray("hb"); + for (int length : lengthArr) { + coords += length; + } + } + } + println("GL vbo size(estimate) is " + (coords * 2 * 4 / 1024 / 1024) + + "MB"); + } + +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/InputHandlerExporter.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/InputHandlerExporter.java new file mode 100644 index 0000000000..3f127e3468 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/InputHandlerExporter.java @@ -0,0 +1,88 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.hprof; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.SmartInstance; + +/** + * + * Outputs all input handlers for all pane managers. The most useful thing this + * can be used for is checking if pan tool is active. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class InputHandlerExporter extends + DisplayPaneContainerExporter { + + public InputHandlerExporter(HprofFile hprof, File outputDirectory) { + super(hprof, outputDirectory); + } + + @Override + protected String getFileName() { + return "inputHandlers.txt"; + } + + @Override + protected String getComment() { + StringBuilder comment = new StringBuilder(); + comment.append("# This file contains inputHandlers of all the display pane containers\n"); + comment.append("# (SideViews VizMapEditors, and VizXyEditors). The editor with the most\n"); + comment.append("# handlers is probably the active editor.\n"); + return comment.toString(); + } + + @Override + protected String getInfo() { + return "Generating output for DisplayPaneContainer input handlers..."; + } + + @Override + protected void outputPaneManager( + SmartInstance paneManager) throws IOException { + List handlers = paneManager.get("inputManager") + .get("handlers").toArrayList(); + + if (!handlers.isEmpty()) { + println(" InputManager{"); + for (SmartInstance phandler : handlers) { + SmartInstance handler = phandler.get("handler"); + println(" " + handler); + } + println(" }"); + } + } +} diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/RequestableResourceExporter.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/RequestableResourceExporter.java new file mode 100644 index 0000000000..45d5b8da9c --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/RequestableResourceExporter.java @@ -0,0 +1,159 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.hprof; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map.Entry; + +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.SmartInstance; + +/** + * + * Outputs metadata map for all requestable resource datas. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jan 08, 2014  2648     bsteffen    Initial doc
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class RequestableResourceExporter extends AbstractExporter { + + private final List resources; + + public RequestableResourceExporter(HprofFile hprof, File outputDirectory, + List resources) { + super(hprof, outputDirectory); + this.resources = resources; + } + + @Override + protected String getFileName() { + return "requestableResources.txt"; + } + + @Override + protected String getComment() { + StringBuilder comment = new StringBuilder(); + comment + .append("# This file contains the metadataMap for all resources that are on containers found in\n"); + comment + .append("# displayPaneContainers.txt. Keys and values which are interned constants are not always\n"); + comment.append("# saved to the heap and might not output pretty."); + return comment.toString(); + } + + @Override + protected String getInfo() { + return "Generating output for RequestableResources..."; + } + + @Override + protected void exportInternal() throws IOException { + for (SmartInstance resource : resources) { + outputResource(resource); + } + } + + protected void outputResource(SmartInstance resource) + throws IOException { + if (resource == null) { + return; + } + SmartInstance resourceData = resource.get("resourceData"); + if (resourceData == null) { + println(resource + "{"); + println(" No resourceData available."); + println("}"); + return; + } + SmartInstance metadataMap = resourceData.get( + "metadataMap"); + if (metadataMap == null) { + return; + } + println(resource + "{"); + outputMetadataMap(metadataMap); + println("}"); + } + + protected void outputMetadataMap(SmartInstance metadataMap) + throws IOException { + for (Entry entry : metadataMap + .toStringKeyedHashMap().entrySet()) { + String key = entry.getKey(); + SmartInstance value = entry.getValue(); + SmartInstance constraintType = value.get("constraintType"); + int ordinal = constraintType.getInt("ordinal"); + String constraintValue = value.getString("constraintValue"); + String operand = ""; + switch (ordinal) { + case 0: + operand = "="; + break; + case 1: + operand = "!="; + break; + case 2: + operand = ">"; + break; + case 3: + operand = ">="; + break; + case 4: + operand = "<"; + break; + case 5: + operand = "<="; + break; + case 6: + operand = "between"; + break; + case 7: + operand = "in"; + break; + case 8: + operand = "like"; + break; + case 9: + operand = "ilike"; + break; + case 10: + operand = "isnull"; + break; + case 11: + operand = "isnotnull"; + break; + } + println(" " + key + " " + operand + " " + constraintValue); + } + } + +}