Omaha #3093 add hprof output for grid cached data.

Former-commit-id: 202321d897 [formerly 202321d897 [formerly d509822129823efcdf67dd9c028bc72af99b1039]]
Former-commit-id: 405eabac07
Former-commit-id: 402693a5c4
This commit is contained in:
Ben Steffensmeier 2014-05-21 14:45:24 -05:00
parent 2ddde07e7f
commit 1e0868826d
3 changed files with 155 additions and 0 deletions

View file

@ -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
*
*
* </pre>
@ -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<String, SmartInstance> toStringKeyedConcurrentHashMap() {
if (!getClassName().equals(ConcurrentHashMap.class.getName())) {
throw new IllegalStateException(this
+ " is not a ConcurrentHashMap.");
}
ConcurrentHashMap<String, SmartInstance> map = new ConcurrentHashMap<String, SmartInstance>();
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<SmartInstance, SmartInstance> toHashMap() {
if (!getClassName().equals(HashMap.class.getName())) {
throw new IllegalStateException(this + " is not a HashMap.");

View file

@ -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
*
* </pre>
*
@ -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();
}
}

View file

@ -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.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------- -------- ----------- --------------------------
* May 20, 2014 3093 bsteffen Initial creation
*
* </pre>
*
* @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<SmartInstance> factories = getInstances("com.raytheon.viz.grid.data.GridRequestableDataFactory");
if (factories.isEmpty()) {
return;
}
long totalSize = 0;
for (SmartInstance factory : factories) {
Map<String, SmartInstance> dataMap = factory.get(
"requestableDataMap").toStringKeyedConcurrentHashMap();
for (Entry<String, SmartInstance> entry : dataMap.entrySet()) {
SmartInstance data = entry.getValue();
println(data + "{");
println(" dataURI = " + entry.getKey());
long size = 0;
HashMap<SmartInstance, SmartInstance> 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");
}
}
}