Skip to content

Commit

Permalink
type size report
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmosmann committed Oct 22, 2012
1 parent 5ccd96f commit 57cd3c6
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.wicketstuff.pageserializer.kryo2.inspecting;

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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -15,6 +20,25 @@ public class TypeSizeReport implements ISerializedObjectTreeProcessor {
public void process(ISerializedObjectTree tree) {
Map<Class<?>, Counter> map=new HashMap<Class<?>, TypeSizeReport.Counter>();
process(tree,map);

List<Map.Entry<Class<?>, Counter>> sorted=new ArrayList<Map.Entry<Class<?>,Counter>>();
sorted.addAll(map.entrySet());
Collections.sort(sorted,new Comparator<Map.Entry<Class<?>, Counter>>() {
@Override
public int compare(Entry<Class<?>, Counter> o1,
Entry<Class<?>, Counter> o2) {
int s1=o1.getValue().size;
int s2=o2.getValue().size;
return s1==s2 ? 0 : s1>s2 ? -1 : 1;
}
});

StringBuilder sb=new StringBuilder();
sb.append("\n-----------------------------\n");
for (Map.Entry<Class<?>, Counter> e : sorted) {
sb.append(e.getKey().getName()).append("=").append(e.getValue().size).append("\n");
}
LOG.debug(sb.toString());
}

private void process(ISerializedObjectTree tree, Map<Class<?>, Counter> map) {
Expand All @@ -24,6 +48,7 @@ private void process(ISerializedObjectTree tree, Map<Class<?>, Counter> map) {
for (ISerializedObjectTree child : tree.children()) {
process(child,map);
}

}

private Counter getOrCreate(Map<Class<?>, Counter> map,
Expand Down

0 comments on commit 57cd3c6

Please sign in to comment.