Skip to content

Commit

Permalink
Allocation stats
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofslusarski committed Jan 20, 2022
1 parent ffe4bc9 commit 79cb9ab
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@
*/
package pl.ks.profiling.safepoint.analyzer.commons.shared.gc.page;

import static pl.ks.profiling.gui.commons.PageCreatorHelper.numToString;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import pl.ks.profiling.gui.commons.Page;
import pl.ks.profiling.gui.commons.PageContent;
import pl.ks.profiling.gui.commons.Table;
Expand All @@ -33,6 +24,16 @@
import pl.ks.profiling.safepoint.analyzer.commons.shared.gc.parser.GCStats;
import pl.ks.profiling.safepoint.analyzer.commons.shared.report.JvmLogFile;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static pl.ks.profiling.gui.commons.PageCreatorHelper.numToString;

public class GCTableStats implements PageCreator {
@Override
public Page create(JvmLogFile jvmLogFile, DecimalFormat decimalFormat) {
Expand All @@ -51,6 +52,15 @@ public Page create(JvmLogFile jvmLogFile, DecimalFormat decimalFormat) {
.collect(Collectors.toList()))
.build());
}
pageContents.add(Table.builder()
.header(List.of("Total allocation (MB)"))
.title("Allocation statistics")
.info("Table presents allocation statistics")
.screenWidth("25%")
.table(List.of(List.of(
numToString(gcStats.getAllocationStats().getTotalAllocation(), decimalFormat)))
)
.build());
if (gcStats.getGcAgingSummary().getAgingSizes().size() > 0) {
pageContents.add(Table.builder()
.header(List.of("Age", "Per. 50", "Per. 75", "Per. 90", "Per. 95", "Per. 99", "Per. 99.9", "Per. 100", "Average"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pl.ks.profiling.safepoint.analyzer.commons.shared.gc.parser;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;

@Getter
@Setter(AccessLevel.PACKAGE)
public class GCAllocationStats {
private BigDecimal totalAllocation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/
package pl.ks.profiling.safepoint.analyzer.commons.shared.gc.parser;

import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import pl.ks.profiling.safepoint.analyzer.commons.shared.OneFiledAllStats;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Getter
@Setter(AccessLevel.PACKAGE)
public class GCStats {
Expand All @@ -42,4 +43,5 @@ public class GCStats {
private List<GCToSpaceStats> toSpaceStats;
private List<Long> fullGcSequenceIds;
private Map<String, Long> reasonCount;
private GCAllocationStats allocationStats;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
package pl.ks.profiling.safepoint.analyzer.commons.shared.gc.parser;

import org.apache.commons.collections4.MapUtils;
import pl.ks.profiling.safepoint.analyzer.commons.shared.OneFiledAllStats;
import pl.ks.profiling.safepoint.analyzer.commons.shared.OneFiledAllStatsUtil;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
Expand All @@ -29,9 +33,6 @@
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.collections4.MapUtils;
import pl.ks.profiling.safepoint.analyzer.commons.shared.OneFiledAllStats;
import pl.ks.profiling.safepoint.analyzer.commons.shared.OneFiledAllStatsUtil;

public class GCStatsCreator {
public static GCStats createStats(GCLogFile gcLogFile) {
Expand Down Expand Up @@ -75,9 +76,26 @@ public static GCStats createStats(GCLogFile gcLogFile) {
generateHumongousStats(gcLogFile, gcStats);
generateToSpaceStats(gcLogFile, gcStats);
generateFullGcStats(gcLogFile, gcStats);
generateAllocationStats(gcLogFile, gcStats);
return gcStats;
}

private static void generateAllocationStats(GCLogFile gcLogFile, GCStats gcStats) {
GCLogCycleEntry prev = null;
GCLogCycleEntry current = null;
BigDecimal allocation = BigDecimal.ZERO;
for (GCLogCycleEntry cycle : gcLogFile.getCycleEntries()) {
prev = current;
current = cycle;
if (prev == null) {
continue;
}
allocation = allocation.add(new BigDecimal(current.getHeapBeforeGCMb())).subtract(new BigDecimal(prev.getHeapAfterGCMb()));
}
gcStats.setAllocationStats(new GCAllocationStats());
gcStats.getAllocationStats().setTotalAllocation(allocation);
}

private static void generateCauseCounts(GCLogFile gcLogFile, GCStats gcStats) {
Map<String, Long> map = gcLogFile.getCycleEntries().stream()
.map(GCLogCycleEntry::getCause)
Expand Down

0 comments on commit 79cb9ab

Please sign in to comment.