Package com.helix.profiler.flamegraph
Class AsciiFlameRenderer
java.lang.Object
com.helix.profiler.flamegraph.AsciiFlameRenderer
High-performance Unicode ASCII Flame Graph Renderer.
Translates hierarchical prefix tries (StackFrameNode) into Unicode box-drawing
bar layouts (┌, ┐, └, ┘, ─, │, ┬, ┴, ┼). Dynamically adapts bar widths to terminal columns,
applies smart text truncation, and renders interactive, theme-safe colors.
Also provides standalone vector SVG and interactive HTML export capabilities.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a single positioned frame bar in the terminal layout.static classModern floating toast notification anchored to the top-right corner of the terminal. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcomputeLayout(int totalWidth, int maxDepths) Computes the 2D layout of flame graph bars for the current zoomed frame.Path[]exportBoth(Path outputDirectory, String fileBaseName) Exports both SVG and HTML flame graph snapshots with timestamped filenames.voidexportHtml(Path outputPath, String title) Exports the current frame hierarchy to a standalone interactive HTML flame graph file.voidExports the current frame hierarchy to a standalone vector SVG flame graph file.static StringformatBarLabel(String frameName, long totalValue, long rootTotal, int width) Smartly formats and truncates a frame label to fit within the specified column width.generateSvg(String title) Generates a self-contained, interactive vector SVG string.intintgetTheme()voidnavigateDown(int terminalWidth) voidnavigateLeft(int terminalWidth) voidnavigateRight(int terminalWidth) voidnavigateUp(int terminalWidth) voidrenderToLanterna(com.googlecode.lanterna.graphics.TextGraphics graphics, int originX, int originY, int width, int height) Renders the flame graph directly onto a LanternaTextGraphicsviewport.renderToString(int totalWidth, int maxDepths, boolean withAnsi) Renders a multi-level Unicode box-drawing flame graph to a String.voidvoidsetMetricType(MetricType metricType) voidsetRootNode(StackFrameNode rootNode) voidsetZoomedNode(StackFrameNode zoomedNode) voidshowToast(String title, List<String> lines, long durationMs, com.googlecode.lanterna.TextColor.RGB borderColor) voidvoidvoidzoomOut()
-
Constructor Details
-
AsciiFlameRenderer
public AsciiFlameRenderer() -
AsciiFlameRenderer
-
-
Method Details
-
getTheme
-
getMetricType
-
setMetricType
-
toggleMetricType
public void toggleMetricType() -
getRootNode
-
setRootNode
-
getZoomedNode
-
setZoomedNode
-
getSelectedNode
-
getSelectedDepth
public int getSelectedDepth() -
getSelectedIndex
public int getSelectedIndex() -
computeLayout
Computes the 2D layout of flame graph bars for the current zoomed frame.- Parameters:
totalWidth- Total available terminal columns (e.g. 80 - 160+)maxDepths- Maximum call depth levels to include- Returns:
- Map of depth level (0-based) to list of positioned FrameBar instances
-
formatBarLabel
Smartly formats and truncates a frame label to fit within the specified column width.- Parameters:
frameName- Full method/frame signature (e.g. "com.helix.core.RuleEvaluator.evaluate")totalValue- Cumulative samples/bytesrootTotal- Root cumulative samples/byteswidth- Available width (columns)- Returns:
- Truncated, readable label
-
renderToString
Renders a multi-level Unicode box-drawing flame graph to a String. Uses box-drawing characters: ┌, ┐, └, ┘, ─, │, ┬, ┴.- Parameters:
totalWidth- Total width in columns (e.g. 80 to 160+)maxDepths- Maximum stack depths to renderwithAnsi- Whether to embed 24-bit ANSI colors- Returns:
- Rendered flame graph string
-
renderToLanterna
public void renderToLanterna(com.googlecode.lanterna.graphics.TextGraphics graphics, int originX, int originY, int width, int height) Renders the flame graph directly onto a LanternaTextGraphicsviewport. Guarantees 100% legibility on any terminal theme with explicit foreground & background colors.- Parameters:
graphics- Lanterna TextGraphics instanceoriginX- Top-left column offsetoriginY- Top-left row offsetwidth- Available columnsheight- Available rows
-
showToast
-
clearToast
public void clearToast() -
getActiveToast
-
zoomIntoSelected
public void zoomIntoSelected() -
zoomOut
public void zoomOut() -
resetZoom
public void resetZoom() -
exportSvg
Exports the current frame hierarchy to a standalone vector SVG flame graph file.- Parameters:
outputPath- Path to output SVG filetitle- Chart title- Throws:
IOException- on I/O error
-
generateSvg
Generates a self-contained, interactive vector SVG string. -
exportHtml
Exports the current frame hierarchy to a standalone interactive HTML flame graph file.- Parameters:
outputPath- Path to output HTML filetitle- Chart title- Throws:
IOException- on I/O error
-
exportBoth
Exports both SVG and HTML flame graph snapshots with timestamped filenames.- Parameters:
outputDirectory- Directory to write filesfileBaseName- Base name prefix- Returns:
- Array of [svgPath, htmlPath]
- Throws:
IOException- on I/O error
-