Skip to content

Commit

Permalink
add percentiles in output csv file
Browse files Browse the repository at this point in the history
  • Loading branch information
cuiweilong committed Aug 30, 2022
1 parent e5c31e1 commit d54eae8
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import java.io.PrintWriter;
import java.text.NumberFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.tagtraum.perf.gcviewer.exp.AbstractDataWriter;
import com.tagtraum.perf.gcviewer.math.DoubleData;
import com.tagtraum.perf.gcviewer.math.DoubleDataPercentile;
import com.tagtraum.perf.gcviewer.model.GCModel;
import com.tagtraum.perf.gcviewer.util.FormattedValue;
import com.tagtraum.perf.gcviewer.util.MemoryFormat;
Expand Down Expand Up @@ -69,7 +73,7 @@ public SummaryDataWriter(OutputStream out, Map<String, Object> configuration) {

private void initialiseFormatters() {
pauseFormatter = NumberFormat.getInstance();
pauseFormatter.setMaximumFractionDigits(5);
pauseFormatter.setMaximumFractionDigits(6);

totalTimeFormatter = new TimeFormat();

Expand Down Expand Up @@ -227,6 +231,74 @@ private void exportPauseSummary(PrintWriter out, GCModel model) {
exportValue(out, "fullGCPausePc", percentFormatter.format(model.getFullGCPause().getSum()*100.0/model.getPause().getSum()), "%");
exportValue(out, "gcPause", gcTimeFormatter.format(model.getGCPause().getSum()), "s");
exportValue(out, "gcPausePc", percentFormatter.format(model.getGCPause().getSum()*100.0/model.getPause().getSum()), "%");

// Add extra statistical data: sum, count, min, max, average, standardDeviation, median, 75th percentile, 95, 99, 99.5, 99.9
// All Pause stats
if (pauseDataAvailable) {
exportValue(out, "pauseSum", pauseFormatter.format(model.getPause().getSum()), "s");
// exportValue(out, "pauseCount", "" + model.getPause().getN(), "-");
exportValue(out, "pauseMin", pauseFormatter.format(model.getPause().getMin()), "s");
exportValue(out, "pauseMax", pauseFormatter.format(model.getPause().getMax()), "s");
exportValue(out, "pauseAverage", pauseFormatter.format(model.getPause().average()), "s");
exportValue(out, "pauseStandardDeviation", pauseFormatter.format(model.getPause().standardDeviation()), "s");
exportValue(out, "pauseMedian", pauseFormatter.format(((DoubleDataPercentile)model.getPause()).getPercentile(50)), "s");
exportValue(out, "pausePercentile75th", pauseFormatter.format(((DoubleDataPercentile)model.getPause()).getPercentile(50)), "s");
exportValue(out, "pausePercentile95th", pauseFormatter.format(((DoubleDataPercentile)model.getPause()).getPercentile(75)), "s");
exportValue(out, "pausePercentile99th", pauseFormatter.format(((DoubleDataPercentile)model.getPause()).getPercentile(95)), "s");
exportValue(out, "pausePercentile99.5th", pauseFormatter.format(((DoubleDataPercentile)model.getPause()).getPercentile(99)), "s");
exportValue(out, "pausePercentile99.9th", pauseFormatter.format(((DoubleDataPercentile)model.getPause()).getPercentile(99.9)), "s");
}
// GC Pause stats
if (gcDataAvailable) {
exportValue(out, "gcPauseSum", pauseFormatter.format(model.getGCPause().getSum()), "s");
// exportValue(out, "gcPauseCount", "" + model.getGCPause().getN(), "-");
exportValue(out, "gcPauseMin", pauseFormatter.format(model.getGCPause().getMin()), "s");
exportValue(out, "gcPauseMax", pauseFormatter.format(model.getGCPause().getMax()), "s");
exportValue(out, "gcPauseAverage", pauseFormatter.format(model.getGCPause().average()), "s");
exportValue(out, "gcPauseStandardDeviation", pauseFormatter.format(model.getGCPause().standardDeviation()), "s");
exportValue(out, "gcPauseMedian", pauseFormatter.format(((DoubleDataPercentile)model.getGCPause()).getPercentile(50)), "s");
exportValue(out, "gcPausePercentile75th", pauseFormatter.format(((DoubleDataPercentile)model.getGCPause()).getPercentile(50)), "s");
exportValue(out, "gcPausePercentile95th", pauseFormatter.format(((DoubleDataPercentile)model.getGCPause()).getPercentile(75)), "s");
exportValue(out, "gcPausePercentile99th", pauseFormatter.format(((DoubleDataPercentile)model.getGCPause()).getPercentile(95)), "s");
exportValue(out, "gcPausePercentile99.5th", pauseFormatter.format(((DoubleDataPercentile)model.getGCPause()).getPercentile(99)), "s");
exportValue(out, "gcPausePercentile99.9th", pauseFormatter.format(((DoubleDataPercentile)model.getGCPause()).getPercentile(99.9)), "s");
}
// Full GC Pause stats
if (fullGCDataAvailable) {
exportValue(out, "fullGCPauseSum", pauseFormatter.format(model.getFullGCPause().getSum()), "s");
// exportValue(out, "fullGCPauseCount", "" + model.getFullGCPause().getN(), "-");
exportValue(out, "fullGCPauseMin", pauseFormatter.format(model.getFullGCPause().getMin()), "s");
exportValue(out, "fullGCPauseMax", pauseFormatter.format(model.getFullGCPause().getMax()), "s");
exportValue(out, "fullGCPauseAverage", pauseFormatter.format(model.getFullGCPause().average()), "s");
exportValue(out, "fullGCPauseStandardDeviation", pauseFormatter.format(model.getFullGCPause().standardDeviation()), "s");
exportValue(out, "fullGCPauseMedian", pauseFormatter.format(((DoubleDataPercentile)model.getFullGCPause()).getPercentile(50)), "s");
exportValue(out, "fullGCPausePercentile75th", pauseFormatter.format(((DoubleDataPercentile)model.getFullGCPause()).getPercentile(50)), "s");
exportValue(out, "fullGCPausePercentile95th", pauseFormatter.format(((DoubleDataPercentile)model.getFullGCPause()).getPercentile(75)), "s");
exportValue(out, "fullGCPausePercentile99th", pauseFormatter.format(((DoubleDataPercentile)model.getFullGCPause()).getPercentile(95)), "s");
exportValue(out, "fullGCPausePercentile99.5th", pauseFormatter.format(((DoubleDataPercentile)model.getFullGCPause()).getPercentile(99)), "s");
exportValue(out, "fullGCPausePercentile99.9th", pauseFormatter.format(((DoubleDataPercentile)model.getFullGCPause()).getPercentile(99.9)), "s");
}
// ZGC stats: [gc,phases]
if (model.size() > 1 && model.getGcEventPhases().size() > 0) {
DoubleData gcPhases = new DoubleDataPercentile();
for (Entry<String, DoubleData> entry : model.getGcEventPhases().entrySet()) {
List<Double> phaseList = ((DoubleDataPercentile)entry.getValue()).getDoubleData();
for (Double d : phaseList)
gcPhases.add(d);
}
exportValue(out, "gcPhaseSum", pauseFormatter.format(gcPhases.getSum()), "s");
exportValue(out, "gcPhaseCount", "" + gcPhases.getN(), "-");
exportValue(out, "gcPhaseMin", pauseFormatter.format(gcPhases.getMin()), "s");
exportValue(out, "gcPhaseMax", pauseFormatter.format(gcPhases.getMax()), "s");
exportValue(out, "gcPhaseAverage", pauseFormatter.format(gcPhases.average()), "s");
exportValue(out, "gcPhaseStandardDeviation", pauseFormatter.format(gcPhases.standardDeviation()), "s");
exportValue(out, "gcPhaseMedian", pauseFormatter.format(((DoubleDataPercentile)gcPhases).getPercentile(50)), "s");
exportValue(out, "gcPhasePercentile75th", pauseFormatter.format(((DoubleDataPercentile)gcPhases).getPercentile(50)), "s");
exportValue(out, "gcPhasePercentile95th", pauseFormatter.format(((DoubleDataPercentile)gcPhases).getPercentile(75)), "s");
exportValue(out, "gcPhasePercentile99th", pauseFormatter.format(((DoubleDataPercentile)gcPhases).getPercentile(95)), "s");
exportValue(out, "gcPhasePercentile99.5th", pauseFormatter.format(((DoubleDataPercentile)gcPhases).getPercentile(99)), "s");
exportValue(out, "gcPhasePercentile99.9th", pauseFormatter.format(((DoubleDataPercentile)gcPhases).getPercentile(99.9)), "s");
}
}

private boolean isSignificant(final double average, final double standardDeviation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ else if (percentile > 100) {
}
return doubleSet.get((int)position-1);
}

/**
* return all double data.
* @return list of double data
*/
public List<Double> getDoubleData() {
return this.doubleSet;
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/tagtraum/perf/gcviewer/model/GCModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ public GCModel() {
this.postFullGCUsedHeap = new IntData();

this.postGCUsedMemory = new IntData();
this.totalPause = new DoubleData();
this.fullGCPause = new DoubleData();
this.totalPause = new DoubleDataPercentile();
this.fullGCPause = new DoubleDataPercentile();
this.fullGcPauseInterval = new DoubleData();
this.gcPause = new DoubleDataPercentile();
this.vmOperationPause = new DoubleData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.tagtraum.perf.gcviewer.exp.impl.SummaryDataWriter;
import com.tagtraum.perf.gcviewer.imp.DataReader;
import com.tagtraum.perf.gcviewer.imp.DataReaderFactory;
import com.tagtraum.perf.gcviewer.imp.DataReaderSun1_6_0;
import com.tagtraum.perf.gcviewer.imp.GcLogType;
import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.Type;
Expand Down Expand Up @@ -140,4 +141,40 @@ public void testWriteWithPromotion() throws IOException {

assertThat("avgPromotion", csv, Matchers.containsString("avgPromotion; " + memoryFormatter.formatToFormatted(2925).getValue() + "; K"));
}

@Test
public void testWriteWithZGCPhases() throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(
("[2022-08-18T17:18:46.761+0800][0.053s][info][gc ] Using The Z Garbage Collector\n" +
"[2022-08-18T17:18:47.977+0800][1.269s][info][gc,start ] GC(0) Garbage Collection (Warmup)\n" +
"[2022-08-18T17:18:47.978+0800][1.270s][info][gc,phases] GC(0) Pause Mark Start 0.385ms\n" +
"[2022-08-18T17:18:47.985+0800][1.277s][info][gc,phases] GC(0) Concurrent Mark 7.383ms\n" +
"[2022-08-18T17:18:47.985+0800][1.277s][info][gc,phases] GC(0) Pause Mark End 0.050ms\n" +
"[2022-08-18T17:18:47.986+0800][1.277s][info][gc,phases] GC(0) Concurrent Process Non-Strong References 0.239ms\n" +
"[2022-08-18T17:18:47.986+0800][1.277s][info][gc,phases] GC(0) Concurrent Reset Relocation Set 0.000ms\n" +
"[2022-08-18T17:18:47.986+0800][1.278s][info][gc,phases] GC(0) Concurrent Destroy Detached Pages 0.174ms\n" +
"[2022-08-18T17:18:47.989+0800][1.281s][info][gc,phases] GC(0) Concurrent Select Relocation Set 3.505ms\n" +
"[2022-08-18T17:18:47.990+0800][1.282s][info][gc,phases] GC(0) Concurrent Prepare Relocation Set 0.760ms\n" +
"[2022-08-18T17:18:47.991+0800][1.282s][info][gc,phases] GC(0) Pause Relocate Start 0.499ms\n" +
"[2022-08-18T17:18:47.994+0800][1.286s][info][gc,phases] GC(0) Concurrent Relocate 3.545ms\n" +
"[2022-08-18T17:18:47.994+0800][1.286s][info][gc ] GC(0) Garbage Collection (Warmup) 434M(11%)->32M(1%)")
.getBytes());
DataReader reader = new DataReaderFactory().getDataReader(new GcResourceFile("byteArray"), in);
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("pausePercentile75th", csv, Matchers.containsString("pausePercentile75th; 0,000934; s"));
assertThat("gcPausePercentile95th", csv, Matchers.containsString("gcPausePercentile95th; 0,000934; s"));
assertThat("pauseCount", csv, Matchers.containsString("pauseCount; 1; -"));
assertThat("gcPhaseCount", csv, Matchers.containsString("gcPhaseCount; 3; -"));
assertThat("gcPhaseAverage", csv, Matchers.containsString("gcPhaseAverage; 0,000311; s"));
assertThat("gcPhasePercentile99th", csv, Matchers.containsString("gcPhasePercentile99th; 0,000499; s"));
}
}

0 comments on commit d54eae8

Please sign in to comment.