Skip to content

Commit

Permalink
Highcharts (krzysztofslusarski#17)
Browse files Browse the repository at this point in the history
* Highchart first edition

* Highchart first edition
  • Loading branch information
krzysztofslusarski authored Jan 9, 2021
1 parent e5df0b2 commit 4ffae10
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 113 deletions.
36 changes: 34 additions & 2 deletions gui-commons/src/main/java/pl/ks/profiling/gui/commons/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
package pl.ks.profiling.gui.commons;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.Builder;
import lombok.Getter;
import lombok.Value;

import java.util.Arrays;

@Getter
@Value
@Builder
Expand Down Expand Up @@ -63,6 +64,37 @@ private String emptyForNull(String value) {
return value;
}

public Object[] getHighChartYAxisLabels() {
int labels = data.length - 1;
Object[] ret = new Object[labels];
for (int j = 1; j < data.length; j++) {
ret[j - 1] = data[j][0];
}
return ret;
}

public List<HighChartSeries> getHighChartSeriesData() {
int columns = data[0].length;
List<HighChartSeries> ret = new ArrayList<>(columns - 1);
for (int i = 1; i < columns; i++) {
Object[] series = new Object[data.length - 1];
for (int j = 1; j < data.length; j++) {
series[j - 1] = data[j][i];
}
ret.add(new HighChartSeries(data[0][i].toString(), series));
}
return ret;
}

public List<HighChartPieSeries> getHighChartPieSeriesData() {
int labels = data.length - 1;
HighChartPieData[] array = new HighChartPieData[labels];
for (int j = 1; j < data.length; j++) {
array[j - 1] = new HighChartPieData(data[j][0].toString(), data[j][1]);
}
return List.of(new HighChartPieSeries("Chart", array));
}

public enum ChartType {
PIE,
LINE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package pl.ks.profiling.gui.commons;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class HighChartPieData {
String name;
Object y;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package pl.ks.profiling.gui.commons;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class HighChartPieSeries {
String name;
HighChartPieData[] data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package pl.ks.profiling.gui.commons;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class HighChartSeries {
String name;
Object[] data;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public Page create(JvmLogFile jvmLogFile, DecimalFormat decimalFormat) {
Chart.builder()
.title("Avg. of avg. allocation rate in time period")
.chartType(Chart.ChartType.POINTS)
.xAxisLabel("TODO What here?")
.xAxisLabel("Time (number of " + minuteCount + "min from application start)")
.yAxisLabel("Average Mb/s in the last " + minuteCount + " minutes")
.data(getChartAvg(byTimeMap))
.build(),
Chart.builder()
.title("Max. allocation rate in time period")
.chartType(Chart.ChartType.POINTS)
.xAxisLabel("TODO What here?")
.yAxisLabel("TODO What here?")
.xAxisLabel("Time (number of " + minuteCount + "min from application start)")
.yAxisLabel("Max Mb/s in the last " + minuteCount + " minutes")
.data(getChartMax(byTimeMap))
.build()

Expand Down Expand Up @@ -108,6 +108,7 @@ private static Object[][] getChartAvg(Map<Long, List<BigDecimal>> byTimeMap) {

private Map<Long, List<BigDecimal>> createByTimeMap(JvmLogFile jvmLogFile) {
List<GCLogCycleEntry> cycles = jvmLogFile.getGcLogFile().getCycleEntries();
BigDecimal fromSecondsToMinute = minuteCount.multiply(new BigDecimal(60));

if (cycles.size() <= 1) {
return null;
Expand All @@ -128,8 +129,8 @@ private Map<Long, List<BigDecimal>> createByTimeMap(JvmLogFile jvmLogFile) {

BigDecimal rate = new BigDecimal(current.getHeapBeforeGCMb() - prev.getHeapAfterGCMb()).divide(current.getTimeStamp().subtract(prev.getTimeStamp()), 2, RoundingMode.HALF_EVEN);

long prevCycleMinute = prev.getTimeStamp().divide(minuteCount, 2, RoundingMode.HALF_EVEN).longValue();
long currentCycleMinute = current.getTimeStamp().divide(minuteCount, 2, RoundingMode.HALF_EVEN).longValue();
long prevCycleMinute = prev.getTimeStamp().divide(fromSecondsToMinute, 2, RoundingMode.HALF_EVEN).longValue();
long currentCycleMinute = current.getTimeStamp().divide(fromSecondsToMinute, 2, RoundingMode.HALF_EVEN).longValue();
for (long j = prevCycleMinute; j <= currentCycleMinute; j++) {
byTimeMap.computeIfAbsent(j, minute -> new ArrayList<>()).add(rate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public Page create(JvmLogFile jvmLogFile, DecimalFormat decimalFormat) {
.chartType(Chart.ChartType.POINTS)
.title("Tenuring threshold")
.xAxisLabel("Seconds since application start")
.yAxisLabel("// TODO What here?")
.yAxisLabel("Tenuring threshold")
.data(getTenuringThreshold(jvmLogFile))
.build(),
Chart.builder()
.chartType(Chart.ChartType.POINTS)
.title("Desired survivor size")
.xAxisLabel("Seconds since application start")
.yAxisLabel("// TODO What here?")
.yAxisLabel("Desired survivor size")
.data(getDesiredSurvivorSize(jvmLogFile))
.build()
))
Expand Down
Loading

0 comments on commit 4ffae10

Please sign in to comment.