Skip to content

Commit

Permalink
Reduce memory usage, allow selection of multiple metrics in MetricsPa…
Browse files Browse the repository at this point in the history
…ne [HZG-208] (#7)

This PR reduces the memory footprint while loading large diagnostics
files.

Previously each individual `DiagnosticFile` contained an index for the
metric entries contained within it. Now there is a single index per
instance of `InstanceDiagnostics`, this hugely reduces the number of
index entries needed and allows the tool to load several gigabytes of
diagnostic logs.

In addition a number of IDE compiler warnings have been fixed and the
`MetricsPane` has been updated to allow selection and comparison of
multiple metrics.
  • Loading branch information
hazelcast-alexb authored Nov 15, 2024
1 parent 45af55f commit 6002f31
Show file tree
Hide file tree
Showing 23 changed files with 483 additions and 680 deletions.
202 changes: 0 additions & 202 deletions src/main/java/com/hazelcast/diagnostics/AutoCompletion.java

This file was deleted.

11 changes: 7 additions & 4 deletions src/main/java/com/hazelcast/diagnostics/BuildInfoPane.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.hazelcast.diagnostics;

import javax.swing.*;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import java.util.Iterator;
import java.util.Map;

import static com.hazelcast.diagnostics.InstanceDiagnostics.DiagnosticType.TYPE_BUILD_INFO;

public class BuildInfoPane {

private final JTable table;
private final DefaultTableModel model;
private final JScrollPane pane;

public BuildInfoPane() {
table = new JTable();
JTable table = new JTable();
model = new DefaultTableModel();
table.setModel(model);
model.addColumn("Key");
Expand All @@ -31,7 +34,7 @@ public void setInstanceDiagnostics(InstanceDiagnostics diagnostics) {
return;
}

Iterator<Map.Entry<Long, String>> it = diagnostics.between(InstanceDiagnostics.TYPE_BUILD_INFO, 0, Long.MAX_VALUE);
Iterator<Map.Entry<Long, String>> it = diagnostics.between(TYPE_BUILD_INFO, 0, Long.MAX_VALUE);
if (!it.hasNext()) {
System.out.println("No BuildInfo found in directory: " + diagnostics.getDirectory());
return;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/hazelcast/diagnostics/ConnectionPane.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.hazelcast.diagnostics;

import javax.swing.*;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import static com.hazelcast.diagnostics.InstanceDiagnostics.DiagnosticType.TYPE_CONNECTION;

public class ConnectionPane {

private final JComponent component;
Expand Down Expand Up @@ -37,9 +41,9 @@ public void update() {
return;
}

TreeMap<Long, List<String>> treeMap = new TreeMap();
TreeMap<Long, List<String>> treeMap = new TreeMap<>();
for (InstanceDiagnostics diagnostics : diagnosticsList) {
Iterator<Map.Entry<Long, String>> iterator = diagnostics.between(InstanceDiagnostics.TYPE_CONNECTION, startMs, endMs);
Iterator<Map.Entry<Long, String>> iterator = diagnostics.between(TYPE_CONNECTION, startMs, endMs);

if (!iterator.hasNext()) {
continue;
Expand All @@ -48,11 +52,7 @@ public void update() {
while (iterator.hasNext()) {
Map.Entry<Long, String> entry = iterator.next();
Long key = entry.getKey();
List<String> list = treeMap.get(key);
if (list == null) {
list = new ArrayList<>();
treeMap.put(key, list);
}
List<String> list = treeMap.computeIfAbsent(key, k -> new ArrayList<>());
list.add(entry.getValue());
}
}
Expand Down
20 changes: 7 additions & 13 deletions src/main/java/com/hazelcast/diagnostics/CpuUtilizationPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

import javax.swing.*;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Iterator;
Expand All @@ -19,25 +20,17 @@

public class CpuUtilizationPane {
private final JPanel component;
private final JFreeChart chart;
private final ChartPanel chartPanel;
private final TimeSeriesCollection collection;
private long startMs = Long.MIN_VALUE;
private long endMs = Long.MAX_VALUE;
private Collection<InstanceDiagnostics> diagnosticsList = new LinkedList<>();

public CpuUtilizationPane() {
collection = new TimeSeriesCollection();
chart = ChartFactory.createTimeSeriesChart(
"CPU Utilization",
"Time",
"Utilization",
collection,
true,
true,
JFreeChart chart = ChartFactory.createTimeSeriesChart("CPU Utilization", "Time", "Utilization", collection, true, true,
false);
this.chartPanel = new ChartPanel(chart);
XYPlot plot = (XYPlot)chartPanel.getChart().getPlot();
ChartPanel chartPanel = new ChartPanel(chart);
XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
DateAxis axis = (DateAxis)plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
this.component = chartPanel;
Expand All @@ -56,7 +49,8 @@ public void update() {
collection.removeAllSeries();

for (InstanceDiagnostics diagnostics : diagnosticsList) {
Iterator<Map.Entry<Long, Number>> iterator = diagnostics.metricsBetween("[metric=os.processCpuLoad]", startMs, endMs);
Iterator<Map.Entry<Long, Number>> iterator = diagnostics.metricsBetween(
InstanceDiagnostics.METRIC_OS_PROCESS_CPU_LOAD, startMs, endMs);

if (!iterator.hasNext()) {
continue;
Expand Down
Loading

0 comments on commit 6002f31

Please sign in to comment.