Skip to content

Commit 129829d

Browse files
committed
Add Promotion Avg & Total To Summary
Adds avgPromotion and promotionTotal to the Summary output. Example: avgPromotion; 2,925; K promotionTotal; 3,820; M
1 parent 7db04c2 commit 129829d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/main/java/com/tagtraum/perf/gcviewer/exp/impl/SummaryDataWriter.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,19 @@ private void exportMemorySummary(PrintWriter out, GCModel model) {
349349
exportValue(out, "avgFreedMemoryByGCisSig", isSignificant(model.getFreedMemoryByGC().average(),
350350
model.getFreedMemoryByGC().standardDeviation()));
351351
}
352+
353+
final boolean promotionDataAvailable = model.getPromotion().getN() != 0;
354+
355+
if (!promotionDataAvailable) {
356+
exportValue(out, "avgPromotion", "n.a.", "M");
357+
exportValue(out, "promotionTotal", "n.a.", "M");
358+
}
359+
else {
360+
formed = footprintFormatter.formatToFormatted(model.getPromotion().average());
361+
exportValue(out, "avgPromotion", formed.getValue(), formed.getUnits());
362+
formed = footprintFormatter.formatToFormatted(model.getPromotion().getSum());
363+
exportValue(out, "promotionTotal", formed.getValue(), formed.getUnits());
364+
}
352365
}
353366

354367
private FormattedValue sigmaMemoryFormat(double value) {

src/test/java/com/tagtraum/perf/gcviewer/exp/SummaryDataWriterTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@
22

33
import static org.junit.Assert.assertThat;
44

5+
import java.io.ByteArrayInputStream;
56
import java.io.ByteArrayOutputStream;
67
import java.io.IOException;
78
import java.net.MalformedURLException;
89
import java.net.URL;
10+
import java.text.NumberFormat;
911

1012
import com.tagtraum.perf.gcviewer.exp.impl.SummaryDataWriter;
13+
import com.tagtraum.perf.gcviewer.imp.DataReader;
14+
import com.tagtraum.perf.gcviewer.imp.DataReaderSun1_6_0;
15+
import com.tagtraum.perf.gcviewer.imp.GcLogType;
1116
import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.Type;
1217
import com.tagtraum.perf.gcviewer.model.GCEvent;
1318
import com.tagtraum.perf.gcviewer.model.GCModel;
19+
import com.tagtraum.perf.gcviewer.model.GcResourceFile;
20+
import com.tagtraum.perf.gcviewer.util.MemoryFormat;
21+
1422
import org.hamcrest.Matchers;
23+
import org.junit.BeforeClass;
1524
import org.junit.Test;
1625

1726
/**
@@ -21,6 +30,17 @@
2130
*/
2231
public class SummaryDataWriterTest {
2332

33+
private static NumberFormat percentFormatter;
34+
private static MemoryFormat memoryFormatter;
35+
36+
@BeforeClass
37+
public static void setupClass() {
38+
percentFormatter = NumberFormat.getInstance();
39+
percentFormatter.setMaximumFractionDigits(1);
40+
percentFormatter.setMinimumFractionDigits(1);
41+
memoryFormatter = new MemoryFormat();
42+
}
43+
2444
private GCModel createGcModel() throws MalformedURLException {
2545
GCModel model = new GCModel();
2646
model.setURL(new URL("file", "localhost", "test-file"));
@@ -73,4 +93,27 @@ public void testWriteWithFullGc() throws IOException {
7393

7494
assertThat("totalHeapAllocMax", csv, Matchers.containsString("avgfootprintAfterFullGC; 724; K"));
7595
}
96+
97+
@Test
98+
public void testWriteWithPromotion() throws IOException {
99+
ByteArrayInputStream in = new ByteArrayInputStream(
100+
("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]" +
101+
"\n" +
102+
"\nDesired survivor size 720896 bytes, new threshold 1 (max 4)" +
103+
"\n- age 1: 1058016 bytes, 1058016 total" +
104+
"\n: 13056K->1408K(13056K), 0.0128277 secs] 131480K->122757K(141328K), 0.0131346 secs] [Times: user=0.15 sys=0.00, real=0.01 secs]")
105+
.getBytes());
106+
DataReader reader = new DataReaderSun1_6_0(new GcResourceFile("byteArray"), in, GcLogType.SUN1_6);
107+
GCModel model = reader.read();
108+
model.setURL(new URL("file", "localhost", "test-file"));
109+
110+
ByteArrayOutputStream output = new ByteArrayOutputStream();
111+
SummaryDataWriter objectUnderTest = new SummaryDataWriter(output);
112+
113+
objectUnderTest.write(model);
114+
115+
String csv = output.toString();
116+
117+
assertThat("avgPromotion", csv, Matchers.containsString("avgPromotion; " + memoryFormatter.formatToFormatted(2925).getValue() + "; K"));
118+
}
76119
}

0 commit comments

Comments
 (0)