Skip to content

Commit

Permalink
fix(flamegraph): Refresh wasn't reloading the data
Browse files Browse the repository at this point in the history
  • Loading branch information
bric3 committed Mar 16, 2022
1 parent e425109 commit 2c386ad
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.function.Consumer;

import static java.util.stream.Collectors.joining;

Expand All @@ -29,18 +30,26 @@ public class FlameGraphTab extends JPanel {
private static final JfrFrameColorMode defaultFrameColorMode = JfrFrameColorMode.BY_PACKAGE;
private static final boolean defaultPaintFrameBorder = true;
private FlameGraph<Node> jfrFlameGraph;
private Consumer<FlameGraph<Node>> dataApplier;

public FlameGraphTab() {
super(new BorderLayout());

jfrFlameGraph = new FlameGraph<>();
jfrFlameGraph.putClientProperty(FlameGraph.SHOW_STATS, true);
// jfrFlameGraph.setTooltipComponentSupplier(BalloonToolTip::new);
jfrFlameGraph.setMinimapShadeColorSupplier(() -> Colors.isDarkMode() ? Colors.translucent_black_40 : Colors.translucent_white_80);
var wrapper = new JPanel(new BorderLayout());
wrapper.add(jfrFlameGraph.component);

var timer = new Timer(2_000, e -> {
jfrFlameGraph = new FlameGraph<>();
jfrFlameGraph.putClientProperty(FlameGraph.SHOW_STATS, true);
jfrFlameGraph.setMinimapShadeColorSupplier(() -> Colors.isDarkMode() ? Colors.translucent_black_40 : Colors.translucent_white_80);
if (dataApplier != null) {
dataApplier.accept(jfrFlameGraph);
}

wrapper.removeAll();
wrapper.add(jfrFlameGraph.component);
wrapper.repaint(1_000);
Expand Down Expand Up @@ -97,8 +106,14 @@ public FlameGraphTab(StacktraceTreeModel stacktraceTreeModel) {
}

public void setStacktraceTreeModel(StacktraceTreeModel stackTraceTreeModel) {
jfrFlameGraph.setData(
JfrFrameNodeConverter.convert(stackTraceTreeModel),
dataApplier = dataApplier(stackTraceTreeModel);
dataApplier.accept(jfrFlameGraph);
}

private Consumer<FlameGraph<Node>> dataApplier(StacktraceTreeModel stackTraceTreeModel) {
var flatFrameList = JfrFrameNodeConverter.convert(stackTraceTreeModel);
return (flameGraph) -> flameGraph.setData(
flatFrameList,
List.of(
node -> node.getFrame().getHumanReadableShortString(),
node -> node.getFrame().getMethod().getMethodName()
Expand Down

0 comments on commit 2c386ad

Please sign in to comment.