From 6dff3cdf27cbd589cdd742df0134a121e344d567 Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Wed, 21 May 2014 14:45:24 -0500 Subject: [PATCH] Omaha #3093 add hprof output for grid cached data. Former-commit-id: 5ad982817052f3b7efa7a14390749eecdef70558 [formerly 68c8895ee3a956969cedfb111990f87665cb539f] [formerly 1c6609e0a9f83064efddc2f1de4c88c7cf7815b7 [formerly 202321d8973500f6e08a21be1e1757afc04e5766]] [formerly 405eabac07def851d533d081cac4fd64b6444dba [formerly 202321d8973500f6e08a21be1e1757afc04e5766 [formerly d509822129823efcdf67dd9c028bc72af99b1039]]] Former-commit-id: 405eabac07def851d533d081cac4fd64b6444dba Former-commit-id: 8ed47756959fd525bac51117ce1b2f5c5c187205 [formerly 402693a5c47e637dd32c62b77de988d7aa2db542] Former-commit-id: 6fbadff061d9ea7baecd89a8127a4ce12ba538ad --- .../src/com/raytheon/hprof/SmartInstance.java | 39 ++++++ .../raytheon/uf/viz/hprof/CaveExporter.java | 2 + .../GridRequestableDataFactoryExporter.java | 114 ++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/GridRequestableDataFactoryExporter.java 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 index baa0af4ee0..b27c9614eb 100644 --- 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 @@ -45,6 +45,8 @@ import com.raytheon.hprof.data.heap.dump.ObjectArrayDump; * ------------- -------- ----------- -------------------------- * Jan 08, 2014 2648 bsteffen Initial doc * May 05, 2014 3093 bsteffen Make getClassname public + * May 21, 2014 3093 bsteffen Add getFloatArray, + * toStringKeyedConcurrentHashMap * * * @@ -186,6 +188,24 @@ public class SmartInstance { return intArray; } + public float[] getFloatArray(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; + } + float[] floatArray = new float[primArray.length]; + + for (int i = 0; i < floatArray.length; i += 1) { + floatArray[i] = primArray[i].getFloat(); + } + return floatArray; + } + public String getString(String fieldName) { Id fieldId = getId(fieldName); if (fieldId == null) { @@ -253,6 +273,25 @@ public class SmartInstance { return map; } + public ConcurrentHashMap toStringKeyedConcurrentHashMap() { + 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.getString("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."); 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 index b6913781c3..9da9462837 100644 --- 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 @@ -38,6 +38,7 @@ import com.raytheon.hprof.HprofFile; * Jan 08, 2014 2648 bsteffen Initial doc * May 05, 2014 3093 bsteffen Add some new exporters * May 20, 2014 3093 bsteffen Add option to zero primitive arrays. + * May 21, 2014 3093 bsteffen Add GridRequestableDataFactoryExporter * * * @@ -98,5 +99,6 @@ public class CaveExporter { new AlertMessageExporter(hprof, outputDir).export(); new CacheObjectExporter(hprof, outputDir).export(); new RadarMosaicExporter(hprof, outputDir).export(); + new GridRequestableDataFactoryExporter(hprof, outputDir).export(); } } diff --git a/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/GridRequestableDataFactoryExporter.java b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/GridRequestableDataFactoryExporter.java new file mode 100644 index 0000000000..ef631b823a --- /dev/null +++ b/javaUtilities/com.raytheon.uf.viz.hprof/src/com/raytheon/uf/viz/hprof/GridRequestableDataFactoryExporter.java @@ -0,0 +1,114 @@ +/** + * 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; +import java.util.Map.Entry; + +import com.raytheon.hprof.HprofFile; +import com.raytheon.hprof.SmartInstance; + +/** + * + * Export information about the cached grid data. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * May 20, 2014  3093     bsteffen    Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class GridRequestableDataFactoryExporter extends + RequestableResourceExporter { + + public GridRequestableDataFactoryExporter(HprofFile hprof, + File outputDirectory) { + super(hprof, outputDirectory, null); + } + + @Override + protected String getFileName() { + return "gridRequestableDataFactory.txt"; + } + + @Override + protected String getComment() { + StringBuilder comment = new StringBuilder(); + comment.append("# This file contains information about GridRequestableDataFactory\n"); + comment.append("# which caches grids used in derived parameters using soft references.\n"); + return comment.toString(); + } + + @Override + protected String getInfo() { + return "Generating output for GridRequestableDataFactory..."; + } + + @Override + protected void exportInternal() throws IOException { + List factories = getInstances("com.raytheon.viz.grid.data.GridRequestableDataFactory"); + if (factories.isEmpty()) { + return; + } + long totalSize = 0; + for (SmartInstance factory : factories) { + Map dataMap = factory.get( + "requestableDataMap").toStringKeyedConcurrentHashMap(); + for (Entry entry : dataMap.entrySet()) { + SmartInstance data = entry.getValue(); + println(data + "{"); + println(" dataURI = " + entry.getKey()); + long size = 0; + HashMap cache = data.get("cache") + .get("m").toHashMap(); + for (SmartInstance ref : cache.values()) { + SmartInstance[] recArray = ref.getObjectArray("referent"); + if (recArray != null) { + for (SmartInstance rec : recArray) { + float[] rawFloats = rec.getFloatArray("floatData"); + size += rawFloats.length * 4; + } + } + } + totalSize += size; + println(" Soft Referenced Memory = " + (size / 1024) + "KB"); + println("}"); + } + + } + if (totalSize > 0) { + println("Total Soft Referenced Memory = " + + (totalSize / 1024 / 1024) + + "MB"); + } + } + +}