Skip to content

Commit

Permalink
refactor(flamegraph): Avoid breaking builds
Browse files Browse the repository at this point in the history
Introduce another method, and keep the old one.
  • Loading branch information
bric3 committed Apr 14, 2022
1 parent 2d339ac commit 8b06b01
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.awt.event.ActionListener;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -188,7 +187,7 @@ public void setStacktraceTreeModel(StacktraceTreeModel stacktraceTreeModel) {

private Consumer<FlameGraph<Node>> dataApplier(StacktraceTreeModel stacktraceTreeModel) {
var flatFrameList = JfrFrameNodeConverter.convert(stacktraceTreeModel);
return (flameGraph) -> flameGraph.setData(
return (flameGraph) -> flameGraph.setConfigurationAndData(
flatFrameList,
NodeDisplayStringProvider.of(
(frame) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,52 @@ public void setHoveringListener(HoveringListener<T> hoverListener) {
* <li>The tooltip text from the current node</li>
* </ul>
*
* @param frames The {@code FrameBox} list to display.
* @param frameToString function to display label in frames.
* @param frameColorFunction the frame to background color function.
* @param tooltipTextFunction the frame tooltip text function.
* @param frames The {@code FrameBox} list to display.
* @param frameToString function to display label in frames.
* @param frameColorFunction the frame to background color function.
* @param tooltipTextFunction the frame tooltip text function.
*/
@Deprecated(forRemoval = true)
public void setData(List<FrameBox<T>> frames,
NodeDisplayStringProvider<T> frameToString,
Function<FrameBox<T>, Color> frameColorFunction,
Function<T, Color> frameColorFunction,
Function<FrameBox<T>, String> tooltipTextFunction) {
setConfigurationAndData(
frames,
frameToString,
frame -> frameColorFunction.apply(frame.actualNode),
tooltipTextFunction
);
}

/**
* Actually set the {@link FlameGraph} with typed data and configure how to use it.
* <p>
* It takes a list of {@link FrameBox} objects that wraps the actual data,
* which is referred to as <em>node</em>.
* </p>
* <p>
* In particular this function defines the behavior to access the typed data:
* <ul>
* <li>Possible string candidates to display in frames, those are
* selected based on the available space</li>
* <li>The root node text to display, if something specific is relevant,
* like the type of events, their number, etc.</li>
* <li>The frame background color, this function can be replaced by
* {@link #setColorFunction(Function)}, note that the foreground color
* is chosen automatically</li>
* <li>The tooltip text from the current node</li>
* </ul>
*
* @param frames The {@code FrameBox} list to display.
* @param frameToString function to display label in frames.
* @param frameColorFunction the frame to background color function.
* @param tooltipTextFunction the frame tooltip text function.
*/
public void setConfigurationAndData(List<FrameBox<T>> frames,
NodeDisplayStringProvider<T> frameToString,
Function<FrameBox<T>, Color> frameColorFunction,
Function<FrameBox<T>, String> tooltipTextFunction) {
var flameGraphPainter = new FlameGraphPainter<>(
Objects.requireNonNull(frames),
Objects.requireNonNull(frameToString),
Expand Down Expand Up @@ -373,7 +410,7 @@ public void highlightFrames(Set<FrameBox<T>> framesToHighlight, String searched)
Objects.requireNonNull(framesToHighlight);
Objects.requireNonNull(searched);
canvas.getFlameGraphPainter().ifPresent(painter ->
painter.setHighlightFrames(framesToHighlight, searched)
painter.setHighlightFrames(framesToHighlight, searched)
);
canvas.repaint();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void loadJfr(String[] args, Label text, FlameGraph<Node> fg) {
var flatFrameList = convert(stacktraceTreeModel);

SwingUtilities.invokeLater(() -> {
flameGraph.setData(
flameGraph.setConfigurationAndData(
flatFrameList,
NodeDisplayStringProvider.of(
(frame) -> {
Expand Down

0 comments on commit 8b06b01

Please sign in to comment.