From 06b2df7be8de04547b0f6ebcacab35011b7e5d6d Mon Sep 17 00:00:00 2001 From: amcreynolds Date: Tue, 31 Jul 2018 11:44:48 -0700 Subject: [PATCH] Adds totalPermAllocMax, totalPermUsedMax, and totalPermUsedMaxpc to the Summary output. Example: totalPermAllocMax; 512; M totalPermUsedMax; 103.398; M totalPermUsedMaxpc; 20.2; % --- .../gcviewer/exp/impl/SummaryDataWriter.java | 12 ++++++ .../gcviewer/exp/SummaryDataWriterTest.java | 39 +++++++++++++++++++ 2 files changed, 51 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..af824b57 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 @@ -266,6 +266,18 @@ private void exportMemorySummary(PrintWriter out, GCModel model) { exportValue(out, "totalYoungUsedMaxpc", percentFormatter.format(model.getYoungUsedSizes().getMax() * 100.0 / model.getYoungAllocatedSizes().getMax()), "%"); } + if (model.getPermAllocatedSizes().getN() == 0) { + exportValue(out, "totalPermAllocMax", "n/a", "M"); + exportValue(out, "totalPermUsedMax", "n/a", "M"); + exportValue(out, "totalPermUsedMaxpc", "n/a", "%"); + } else { + formed = footprintFormatter.formatToFormatted(model.getPermAllocatedSizes().getMax()); + exportValue(out, "totalPermAllocMax", formed.getValue(), formed.getUnits()); + formed = footprintFormatter.formatToFormatted(model.getPermUsedSizes().getMax()); + exportValue(out, "totalPermUsedMax", formed.getValue(), formed.getUnits()); + exportValue(out, "totalPermUsedMaxpc", percentFormatter.format(model.getPermUsedSizes().getMax() * 100.0 / model.getPermAllocatedSizes().getMax()), "%"); + } + // check whether we have full gc data at all final boolean fullGCDataVailable = model.getFootprintAfterFullGC().getN() != 0; final boolean fullGCSlopeDataVailable = model.getFootprintAfterFullGC().getN() > 1; 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..586ff6a0 100644 --- a/src/test/java/com/tagtraum/perf/gcviewer/exp/SummaryDataWriterTest.java +++ b/src/test/java/com/tagtraum/perf/gcviewer/exp/SummaryDataWriterTest.java @@ -6,12 +6,16 @@ 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.model.AbstractGCEvent.Type; import com.tagtraum.perf.gcviewer.model.GCEvent; import com.tagtraum.perf.gcviewer.model.GCModel; +import com.tagtraum.perf.gcviewer.util.MemoryFormat; + import org.hamcrest.Matchers; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -21,6 +25,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 +88,28 @@ public void testWriteWithFullGc() throws IOException { assertThat("totalHeapAllocMax", csv, Matchers.containsString("avgfootprintAfterFullGC; 724; K")); } + + @Test + public void testWriteWithPerm() throws IOException { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + SummaryDataWriter objectUnderTest = new SummaryDataWriter(output); + + // 83.403: [Full GC 83.403: [Tenured: 38156K->54636K(349568K), 0.6013150 secs] 141564K->54636K(506944K), [Perm : 73727K->73727K(73728K)], 0.6014256 secs] [Times: user=0.58 sys=0.00, real=0.59 secs] + GCEvent fullGcEvent = new GCEvent(83.403, 141564, 54636, 506944, 0.6014256, Type.FULL_GC); + GCEvent tenured = new GCEvent(83.403, 38156, 54636, 349568, 0.6013150, Type.TENURED); + GCEvent perm = new GCEvent(83.403, 73727, 73727, 73728, 0.6014256, Type.PERM); + fullGcEvent.add(tenured); + fullGcEvent.add(perm); + + GCModel model = createGcModel(); + model.add(fullGcEvent); + + objectUnderTest.write(model); + + String csv = output.toString(); + + assertThat("totalPermAllocMax", csv, Matchers.containsString("totalPermAllocMax; 72; M")); + assertThat("totalPermUsedMax", csv, Matchers.containsString("totalPermUsedMax; " + memoryFormatter.formatToFormatted(73727).getValue() + "; M")); + assertThat("totalPermUsedMaxpc", csv, Matchers.containsString("totalPermUsedMaxpc; " + percentFormatter.format(100.0) + "; %")); + } }