Class AsciiFlameRenderer

java.lang.Object
com.helix.profiler.flamegraph.AsciiFlameRenderer

public class AsciiFlameRenderer extends Object
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.

  • Constructor Details

    • AsciiFlameRenderer

      public AsciiFlameRenderer()
    • AsciiFlameRenderer

      public AsciiFlameRenderer(FlameGraphTheme theme, MetricType metricType)
  • Method Details

    • getTheme

      public FlameGraphTheme getTheme()
    • getMetricType

      public MetricType getMetricType()
    • setMetricType

      public void setMetricType(MetricType metricType)
    • toggleMetricType

      public void toggleMetricType()
    • getRootNode

      public StackFrameNode getRootNode()
    • setRootNode

      public void setRootNode(StackFrameNode rootNode)
    • getZoomedNode

      public StackFrameNode getZoomedNode()
    • setZoomedNode

      public void setZoomedNode(StackFrameNode zoomedNode)
    • getSelectedNode

      public StackFrameNode getSelectedNode()
    • getSelectedDepth

      public int getSelectedDepth()
    • getSelectedIndex

      public int getSelectedIndex()
    • computeLayout

      public Map<Integer,List<AsciiFlameRenderer.FrameBar>> computeLayout(int totalWidth, int maxDepths)
      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

      public static String formatBarLabel(String frameName, long totalValue, long rootTotal, int width)
      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/bytes
      rootTotal - Root cumulative samples/bytes
      width - Available width (columns)
      Returns:
      Truncated, readable label
    • renderToString

      public String renderToString(int totalWidth, int maxDepths, boolean withAnsi)
      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 render
      withAnsi - 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 Lanterna TextGraphics viewport. Guarantees 100% legibility on any terminal theme with explicit foreground & background colors.
      Parameters:
      graphics - Lanterna TextGraphics instance
      originX - Top-left column offset
      originY - Top-left row offset
      width - Available columns
      height - Available rows
    • showToast

      public void showToast(String title, List<String> lines, long durationMs, com.googlecode.lanterna.TextColor.RGB borderColor)
    • clearToast

      public void clearToast()
    • getActiveToast

      public AsciiFlameRenderer.ToastNotification getActiveToast()
    • zoomIntoSelected

      public void zoomIntoSelected()
    • zoomOut

      public void zoomOut()
    • resetZoom

      public void resetZoom()
    • exportSvg

      public void exportSvg(Path outputPath, String title) throws IOException
      Exports the current frame hierarchy to a standalone vector SVG flame graph file.
      Parameters:
      outputPath - Path to output SVG file
      title - Chart title
      Throws:
      IOException - on I/O error
    • generateSvg

      public String generateSvg(String title)
      Generates a self-contained, interactive vector SVG string.
    • exportHtml

      public void exportHtml(Path outputPath, String title) throws IOException
      Exports the current frame hierarchy to a standalone interactive HTML flame graph file.
      Parameters:
      outputPath - Path to output HTML file
      title - Chart title
      Throws:
      IOException - on I/O error
    • exportBoth

      public Path[] exportBoth(Path outputDirectory, String fileBaseName) throws IOException
      Exports both SVG and HTML flame graph snapshots with timestamped filenames.
      Parameters:
      outputDirectory - Directory to write files
      fileBaseName - Base name prefix
      Returns:
      Array of [svgPath, htmlPath]
      Throws:
      IOException - on I/O error