public static void printViewPatterns() { processedViewsForPatterns = new HashSet<ViewTrace>(); HashMap<String, Integer> viewPatterns = new HashMap<String, Integer>(); ps.println("ViewPatterns ------------------- \n"); for (ViewTrace trace : viewsRegistry) { if (processedViewsForPatterns.contains(trace)) { continue; } ViewTrace v = trace.getRootView(); StringBuilder p = new StringBuilder(); p.append("PATTERN "); extractViewPattern(0, v, p); p.append("\n"); String pattern = p.toString(); Integer count = viewPatterns.get(pattern); if (count == null) { viewPatterns.put(pattern, 1); } else { viewPatterns.put(pattern, count + 1); } } processedViewsForPatterns = null; for (Map.Entry<String, Integer> e : viewPatterns.entrySet()) { ps.print("(" + e.getValue() + ") "); ps.println(e.getKey()); } }
public static void printIndividualViews() { printedIndividualViews = new HashSet<ViewTrace>(); ps.println("Individual views statistics ------------------- \n"); for (ViewTrace trace : viewsRegistry) { if (printedIndividualViews.contains(trace)) { continue; } ViewTrace v = trace.getRootView(); ps.print("ROOT "); dumpView(0, v); ps.println(); } printViewPatterns(); printedIndividualViews = null; }
@Override public double getImag( int i) { // TODO: perhaps special handling for complex numbers? (will always report // redundancy) trace.get(i); return orig.getImag(i); }
@Override public RRaw materialize() { trace.materialize(); return orig.materialize(); }
@Override public byte getRaw(int i) { trace.get(i); return orig.getRaw(i); }
@Override public RLogical materialize() { trace.materialize(); return orig.materialize(); }
@Override public int getLogical(int i) { trace.get(i); return orig.getLogical(i); }
@Override public int getInt(int i) { trace.get(i); return orig.getInt(i); }
@Override public double sum(boolean narm) { trace.sum(); return orig.sum(narm); }
@Override public double getDouble(int i) { trace.get(i); return orig.getDouble(i); }
@Override public RComplex materialize() { trace.materialize(); return orig.materialize(); }
@Override public Complex getComplex(int i) { trace.get(i); return orig.getComplex(i); }
@Override public RString materialize() { trace.materialize(); return orig.materialize(); }
@Override public String getString(int i) { trace.get(i); return orig.getString(i); }
@Override public RAny getRAny(int i) { trace.get(i); return orig.getRAny(i); }
private static void dumpView(int depth, ViewTrace trace) { printedIndividualViews.add(trace); ps.println(trace.realView + " size = " + trace.realView.size()); if (TRACE_ALLOCATION_SITE) { indent(depth); ps.print(" allocationSite ="); Site.printSite(trace.allocationSite); ps.println(); } int unused = trace.unusedElements(); int redundant = trace.redundantGets(); boolean singleUse; Site[] useSites; if (TRACE_USE_SITES) { useSites = trace.useSites.toArray(new Site[trace.useSites.size()]); singleUse = (useSites.length == 1); } else if (TRACE_SINGLE_USE_SITE) { useSites = null; singleUse = !trace.multipleUseSites; } else { useSites = null; singleUse = false; } if (singleUse) { indent(depth); ps.print(" singleUseSite = US"); Site.printSite(useSites != null ? useSites[0] : trace.singleUseSite); if (trace.getCount > 0) { ps.println(" (get)"); } else if (trace.sumCount > 0) { ps.println(" (sum)"); } else { ps.println(" (materialize)"); } } else if (trace.getCount > 0) { if (TRACE_FIRST_GET_SITE) { indent(depth); ps.print(" firstGetSite ="); Site.printSite(trace.firstGetSite); ps.println(); } if (trace.materializeCount == 0 && trace.sumCount == 0) { if (unused > 0) { indent(depth); ps.println(" unusedElements = " + unused); } if (redundant > 0) { indent(depth); ps.println(" redundantGets = " + redundant + " (no materialize, sum)"); } } } else { if (trace.materializeCount == 0 && trace.sumCount == 0) { indent(depth); ps.println(" UNUSED"); } else { indent(depth); ps.println( " materializeCount = " + trace.materializeCount + " sumCount = " + trace.sumCount + " getCount = " + trace.getCount); } } if (TRACE_FIRST_MATERIALIZE_SITE && trace.materializeCount > 0 && !singleUse) { indent(depth); ps.print(" firstMaterializeSite ="); Site.printSite(trace.firstMaterializeSite); ps.println(); } if (TRACE_FIRST_SUM_SITE && trace.sumCount > 0 && !singleUse) { indent(depth); ps.print(" firstSumSite ="); Site.printSite(trace.firstSumSite); ps.println(); } if (TRACE_USE_SITES) { if (useSites.length != 1) { indent(depth); ps.println(" useSites (" + useSites.length + "):"); for (Site s : useSites) { indent(depth); ps.print(" US"); Site.printSite(s); ps.println(); } } } ps.println(); RArray view = trace.realView; Class viewClass = view.getClass(); Field[] fields = getAllFields(viewClass); boolean printedField = false; for (Field f : fields) { if (f.isSynthetic()) { continue; } Class fieldClass = f.getType(); if (RArray.class.isAssignableFrom(fieldClass)) { continue; // these later } indent(depth); ps.print(" " + f.getName() + " "); try { f.setAccessible(true); ps.println(f.get(view)); printedField = true; } catch (IllegalAccessException e) { assert Utils.check(false, "can't read a view field " + e); } } boolean printNewline = printedField; for (Field f : fields) { if (f.isSynthetic()) { continue; } Class fieldClass = f.getType(); if (!RArray.class.isAssignableFrom(fieldClass)) { continue; } if (printNewline) { ps.println(); printNewline = false; } indent(depth); ps.print(" " + f.getName() + " "); try { f.setAccessible(true); Object o = f.get(view); if (o instanceof TracingView) { ps.print("VIEW "); TracingView child = (TracingView) o; dumpView(depth + 2, child.getTrace()); } else { ps.print("ARRAY " + o + " size = " + ((RArray) o).size()); if (o instanceof View) { ps.println("MISSED VIEW " + o); } } ps.println(); } catch (IllegalAccessException e) { assert Utils.check(false, "can't read a view field " + e); } } }