Skip to content

Add Perm Alloc & Used Max to Summary #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) + "; %"));
}
}