Skip to content

Commit

Permalink
Adds totalPermAllocMax, totalPermUsedMax, and
Browse files Browse the repository at this point in the history
totalPermUsedMaxpc to the Summary output.

Example:

    totalPermAllocMax; 512; M
    totalPermUsedMax; 103.398; M
    totalPermUsedMaxpc; 20.2; %
  • Loading branch information
amcrn committed Aug 1, 2018
1 parent 7db04c2 commit 06b2df7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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"));
Expand Down Expand Up @@ -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) + "; %"));
}
}

0 comments on commit 06b2df7

Please sign in to comment.