Permalink
Browse files

kryo2 serializer report output

  • Loading branch information...
1 parent 1d07026 commit 6fe0eff8f022501fb70fc4a30ae8e729d2439457 @michaelmosmann michaelmosmann committed Jun 12, 2013
View
27 ...in/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/IReportOutput.java
@@ -0,0 +1,27 @@
+/**
+ * Copyright (C)
+ * 2008 Jeremy Thomerson <jeremy@thomersonfamily.com>
+ * 2012 Michael Mosmann <michael@mosmann.de>
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report;
+
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ISerializedObjectTree;
+
+public interface IReportOutput {
+ void write(ISerializedObjectTree tree,IReportRenderer renderer);
+}
View
27 .../java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/IReportRenderer.java
@@ -0,0 +1,27 @@
+/**
+ * Copyright (C)
+ * 2008 Jeremy Thomerson <jeremy@thomersonfamily.com>
+ * 2012 Michael Mosmann <michael@mosmann.de>
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report;
+
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ISerializedObjectTree;
+
+public interface IReportRenderer {
+ String render(ISerializedObjectTree tree);
+}
View
39 ...va/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/LoggerReportOutput.java
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C)
+ * 2008 Jeremy Thomerson <jeremy@thomersonfamily.com>
+ * 2012 Michael Mosmann <michael@mosmann.de>
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ISerializedObjectTree;
+
+public class LoggerReportOutput implements IReportOutput {
+
+ private final static Logger LOG = LoggerFactory.getLogger(LoggerReportOutput.class);
+
+ @Override
+ public void write(ISerializedObjectTree tree, IReportRenderer renderer) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(renderer.render(tree));
+ }
+ }
+
+
+}
View
3 .../org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/SortedTreeSizeReport.java
@@ -34,6 +34,9 @@
*/
public class SortedTreeSizeReport extends TreeSizeReport
{
+ public SortedTreeSizeReport(IReportOutput reportOutput) {
+ super(reportOutput);
+ }
@Override
protected List<? extends ISerializedObjectTree> preProcess(
View
32 ...n/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeSizeReport.java
@@ -69,20 +69,30 @@
.build());
private final static Logger LOG = LoggerFactory.getLogger(TreeSizeReport.class);
+
+ private final IReportOutput reportOutput;
+ public TreeSizeReport(IReportOutput reportOutput) {
+ this.reportOutput = reportOutput;
+ }
+
@Override
- public void process(ISerializedObjectTree tree)
- {
- if (LOG.isDebugEnabled()) {
- Report report = new Report("\n");
- process(tree, report, 0, tree.size() + tree.childSize());
- String result=report.export(emptyFirst, id, label, percent, sum, local, child)
- .separateColumnNamesWith('-')
- .tableBorderWith('=')
- .asString();
+ public void process(ISerializedObjectTree tree) {
+ reportOutput.write(tree, new IReportRenderer() {
- LOG.debug(result);
- }
+ @Override
+ public String render(ISerializedObjectTree tree) {
+
+ Report report = new Report("TreeSizeReport\n");
+ process(tree, report, 0, tree.size() + tree.childSize());
+ String result = report
+ .export(emptyFirst, id, label, percent, sum, local,
+ child).separateColumnNamesWith('-')
+ .tableBorderWith('=').asString();
+
+ return result;
+ }
+ });
}
private void process(ISerializedObjectTree tree, Report report, int indent, int allSize)
View
72 ...n/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TypeSizeReport.java
@@ -60,46 +60,48 @@
.set(Column.FillBefore, '.')
.set(Column.Separator, "|")
.build());
+
+ private final IReportOutput reportOutput;
- @Override
- public void process(ISerializedObjectTree tree)
- {
- if (LOG.isDebugEnabled())
- {
- Map<Class<?>, Counter> map = new HashMap<Class<?>, TypeSizeReport.Counter>();
- process(tree, map);
+ public TypeSizeReport(IReportOutput reportOutput) {
+ this.reportOutput = reportOutput;
+ }
- 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;
+ @Override
+ public void process(ISerializedObjectTree tree) {
+
+ reportOutput.write(tree, new IReportRenderer() {
+
+ @Override
+ public String render(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;
+ }
+ });
+
+ Report report = new Report("TypeSizeReport\n");
+ for (Map.Entry<Class<?>, Counter> e : sorted) {
+ report.newRow().set(label, 0, e.getKey().getName())
+ .set(size, 0, "" + e.getValue().size);
}
- });
-
-// StringBuilder sb = new StringBuilder();
-
-// sb.append("\n-----------------------------\n");
+ String result = report.export(emptyFirst, label, size)
+ .separateColumnNamesWith('-').tableBorderWith('=')
+ .asString();
- Report report = new Report("\n");
- for (Map.Entry<Class<?>, Counter> e : sorted)
- {
- report.newRow()
- .set(label, 0, e.getKey().getName())
- .set(size, 0, "" + e.getValue().size);
+ return result;
}
- String result = report.export(emptyFirst, label, size)
- .separateColumnNamesWith('-')
- .tableBorderWith('=')
- .asString();
-
- LOG.debug(result);
- }
+ });
}
private void process(ISerializedObjectTree tree, Map<Class<?>, Counter> map)
View
11 ...erializer-kryo2/src/test/java/org/wicketstuff/pageserializer/kryo2/WicketApplication.java
@@ -29,7 +29,9 @@
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ISerializedObjectTree;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ISerializedObjectTreeProcessor;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.TreeProcessors;
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.IReportOutput;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.Level;
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.LoggerReportOutput;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.SimilarNodeTreeTransformator;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.SortedTreeSizeReport;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.TreeTransformator;
@@ -70,9 +72,12 @@ public String labelFor(Object object)
return null;
}
};
- ISerializedObjectTreeProcessor treeProcessor = TreeProcessors.listOf(new TypeSizeReport(),
- new SortedTreeSizeReport(), new SimilarNodeTreeTransformator(
- new SortedTreeSizeReport()));
+
+ IReportOutput reportOutput=new LoggerReportOutput();
+
+ ISerializedObjectTreeProcessor treeProcessor = TreeProcessors.listOf(new TypeSizeReport(reportOutput),
+ new SortedTreeSizeReport(reportOutput), new SimilarNodeTreeTransformator(
+ new SortedTreeSizeReport(reportOutput)));
ITreeFilter filter = new ITreeFilter()
{
@Override
View
8 ...alizer-kryo2/src/test/java/org/wicketstuff/pageserializer/kryo2/examples/Application.java
@@ -28,6 +28,8 @@
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ISerializedObjectTreeProcessor;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.NativeTypesAsLabel;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.TreeProcessors;
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.IReportOutput;
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.LoggerReportOutput;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.SimilarNodeTreeTransformator;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.SortedTreeSizeReport;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.TreeTransformator;
@@ -55,12 +57,12 @@
public void init()
{
super.init();
-
+ IReportOutput reportOutput=new LoggerReportOutput();
// output of report of type sizes, sorted tree report (by size), aggregated tree
ISerializedObjectTreeProcessor typeAndSortedTreeAndCollapsedSortedTreeProcessors = TreeProcessors.listOf(
- new TypeSizeReport(), new SortedTreeSizeReport(), new SimilarNodeTreeTransformator(
- new SortedTreeSizeReport()));
+ new TypeSizeReport(reportOutput), new SortedTreeSizeReport(reportOutput), new SimilarNodeTreeTransformator(
+ new SortedTreeSizeReport(reportOutput)));
// strips class object writes from tree
TreeTransformator treeProcessors = new TreeTransformator(
View
11 ...yo2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/InspectingKryoTest.java
@@ -33,6 +33,8 @@
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.IObjectLabelizer;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ISerializedObjectTreeProcessor;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.TreeProcessors;
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.IReportOutput;
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.LoggerReportOutput;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.SimilarNodeTreeTransformator;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.SortedTreeSizeReport;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.TreeSizeReport;
@@ -70,9 +72,12 @@ public String labelFor(Object object)
return null;
}
};
- ISerializedObjectTreeProcessor treeProcessor = TreeProcessors.listOf(new TypeSizeReport(),
- new TreeSizeReport(), new SortedTreeSizeReport(), new SimilarNodeTreeTransformator(
- new SortedTreeSizeReport()));
+
+ IReportOutput reportOutput=new LoggerReportOutput();
+
+ ISerializedObjectTreeProcessor treeProcessor = TreeProcessors.listOf(new TypeSizeReport(reportOutput),
+ new TreeSizeReport(reportOutput), new SortedTreeSizeReport(reportOutput), new SimilarNodeTreeTransformator(
+ new SortedTreeSizeReport(reportOutput)));
ITreeFilter filter = new TypeFilter(Class.class);
ISerializedObjectTreeProcessor cleanedTreeProcessor = new TreeTransformator(treeProcessor,
TreeTransformator.strip(filter));
View
20 ...tuff/pageserializer/kryo2/inspecting/analyze/report/SimilarNodeTreeTransformatorTest.java
@@ -84,34 +84,40 @@ public void compressListView()
tester.startPage(ListViewPage.class, new PageParameters());
Assert.assertNotNull(tester.getLastRenderedPage());
+ IReportOutput reportOutput=new LoggerReportOutput();
+
InspectingKryoSerializer kryo = new InspectingKryoSerializer(Bytes.megabytes(1),
new AnalyzingSerializationListener(new ComponentIdAsLabel(), TreeProcessors.listOf(
- new TreeSizeReport(), new TreeTransformator(new SimilarNodeTreeTransformator(
- new TreeSizeReport()), TreeTransformator.strip(new TypeFilter(Class.class))))));
+ new TreeSizeReport(reportOutput), new TreeTransformator(new SimilarNodeTreeTransformator(
+ new TreeSizeReport(reportOutput)), TreeTransformator.strip(new TypeFilter(Class.class))))));
kryo.serialize(tester.getLastRenderedPage());
}
@Test
public void testCompression() throws IOException {
+ IReportOutput reportOutput=new LoggerReportOutput();
+
ISerializedObjectTree source = Trees.fromResource(getClass(), "sample1");
Assert.assertEquals("asSample", source.label());
ISerializedObjectTree result = SimilarNodeTreeTransformator.transformTree(source);
- new TreeSizeReport().process(result);
+ new TreeSizeReport(reportOutput).process(result);
ISerializedObjectTree match = Trees.fromResource(getClass(), "sample1-match");
- new TreeSizeReport().process(match);
+ new TreeSizeReport(reportOutput).process(match);
Trees.assertEqualsTree(match, result);
}
@Test
public void secondNodeHasMoreChilds() throws IOException {
+ IReportOutput reportOutput=new LoggerReportOutput();
+
ISerializedObjectTree source = Trees.fromResource(getClass(), "nodeChildSize");
Assert.assertEquals("asSample", source.label());
- new TreeSizeReport().process(source);
+ new TreeSizeReport(reportOutput).process(source);
ISerializedObjectTree result = SimilarNodeTreeTransformator.transformTree(source);
- new TreeSizeReport().process(result);
+ new TreeSizeReport(reportOutput).process(result);
ISerializedObjectTree match = Trees.fromResource(getClass(), "nodeChildSize-match");
- new TreeSizeReport().process(match);
+ new TreeSizeReport(reportOutput).process(match);
Trees.assertEqualsTree(match, result);
}

0 comments on commit 6fe0eff

Please sign in to comment.