From 129829d9153589fd2d29f702de61b4a7e13b4d84 Mon Sep 17 00:00:00 2001 From: amcreynolds Date: Tue, 31 Jul 2018 13:40:26 -0700 Subject: [PATCH] Add Promotion Avg & Total To Summary Adds avgPromotion and promotionTotal to the Summary output. Example: avgPromotion; 2,925; K promotionTotal; 3,820; M --- .../gcviewer/exp/impl/SummaryDataWriter.java | 13 ++++++ .../gcviewer/exp/SummaryDataWriterTest.java | 43 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/main/java/com/tagtraum/perf/gcviewer/exp/impl/SummaryDataWriter.java b/src/main/java/com/tagtraum/perf/gcviewer/exp/impl/SummaryDataWriter.java index 3946d156..4a69d209 100755 --- a/src/main/java/com/tagtraum/perf/gcviewer/exp/impl/SummaryDataWriter.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/exp/impl/SummaryDataWriter.java @@ -349,6 +349,19 @@ private void exportMemorySummary(PrintWriter out, GCModel model) { exportValue(out, "avgFreedMemoryByGCisSig", isSignificant(model.getFreedMemoryByGC().average(), model.getFreedMemoryByGC().standardDeviation())); } + + final boolean promotionDataAvailable = model.getPromotion().getN() != 0; + + if (!promotionDataAvailable) { + exportValue(out, "avgPromotion", "n.a.", "M"); + exportValue(out, "promotionTotal", "n.a.", "M"); + } + else { + formed = footprintFormatter.formatToFormatted(model.getPromotion().average()); + exportValue(out, "avgPromotion", formed.getValue(), formed.getUnits()); + formed = footprintFormatter.formatToFormatted(model.getPromotion().getSum()); + exportValue(out, "promotionTotal", formed.getValue(), formed.getUnits()); + } } private FormattedValue sigmaMemoryFormat(double value) { diff --git a/src/test/java/com/tagtraum/perf/gcviewer/exp/SummaryDataWriterTest.java b/src/test/java/com/tagtraum/perf/gcviewer/exp/SummaryDataWriterTest.java index d50ccf0f..cb66ff2e 100644 --- a/src/test/java/com/tagtraum/perf/gcviewer/exp/SummaryDataWriterTest.java +++ b/src/test/java/com/tagtraum/perf/gcviewer/exp/SummaryDataWriterTest.java @@ -2,16 +2,25 @@ import static org.junit.Assert.assertThat; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.text.NumberFormat; import com.tagtraum.perf.gcviewer.exp.impl.SummaryDataWriter; +import com.tagtraum.perf.gcviewer.imp.DataReader; +import com.tagtraum.perf.gcviewer.imp.DataReaderSun1_6_0; +import com.tagtraum.perf.gcviewer.imp.GcLogType; import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.Type; import com.tagtraum.perf.gcviewer.model.GCEvent; import com.tagtraum.perf.gcviewer.model.GCModel; +import com.tagtraum.perf.gcviewer.model.GcResourceFile; +import com.tagtraum.perf.gcviewer.util.MemoryFormat; + import org.hamcrest.Matchers; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -21,6 +30,17 @@ */ public class SummaryDataWriterTest { + private static NumberFormat percentFormatter; + private static MemoryFormat memoryFormatter; + + @BeforeClass + public static void setupClass() { + percentFormatter = NumberFormat.getInstance(); + percentFormatter.setMaximumFractionDigits(1); + percentFormatter.setMinimumFractionDigits(1); + memoryFormatter = new MemoryFormat(); + } + private GCModel createGcModel() throws MalformedURLException { GCModel model = new GCModel(); model.setURL(new URL("file", "localhost", "test-file")); @@ -73,4 +93,27 @@ public void testWriteWithFullGc() throws IOException { assertThat("totalHeapAllocMax", csv, Matchers.containsString("avgfootprintAfterFullGC; 724; K")); } + + @Test + public void testWriteWithPromotion() throws IOException { + ByteArrayInputStream in = new ByteArrayInputStream( + ("2011-01-25T17:10:16.889+0100: 12076.859: [GC 12076.859: [ParNew2011-01-25T17:10:16.896+0100: 12076.866: [CMS-concurrent-abortable-preclean: 0.929/4.899 secs] [Times: user=2.13 sys=0.04, real=4.90 secs]" + + "\n" + + "\nDesired survivor size 720896 bytes, new threshold 1 (max 4)" + + "\n- age 1: 1058016 bytes, 1058016 total" + + "\n: 13056K->1408K(13056K), 0.0128277 secs] 131480K->122757K(141328K), 0.0131346 secs] [Times: user=0.15 sys=0.00, real=0.01 secs]") + .getBytes()); + DataReader reader = new DataReaderSun1_6_0(new GcResourceFile("byteArray"), in, GcLogType.SUN1_6); + GCModel model = reader.read(); + model.setURL(new URL("file", "localhost", "test-file")); + + ByteArrayOutputStream output = new ByteArrayOutputStream(); + SummaryDataWriter objectUnderTest = new SummaryDataWriter(output); + + objectUnderTest.write(model); + + String csv = output.toString(); + + assertThat("avgPromotion", csv, Matchers.containsString("avgPromotion; " + memoryFormatter.formatToFormatted(2925).getValue() + "; K")); + } }