java.lang.Object
net.i2p.router.web.HelperBase
net.i2p.router.web.helpers.TuningHelper

public class TuningHelperextends HelperBase
Helper for the transport tuning page (tuning.jsp). Renders tunable param tables with inline SVG sparklines.
  • Field Details

    • SPARK_W

      private static final int SPARK_W
      Width of a sparkline graph, in pixels.
      See Also:
    • SPARK_H

      private static final int SPARK_H
      Height of a sparkline graph, in pixels.
      See Also:
    • _nonce

      private String _nonce
      Nonce proving the tuner form came from this router.
    • DISPLAY_NAMES

      static final Map<String,String> DISPLAY_NAMES
      Param name to human label. Package-private so the conformance test can verify the two maps stay in step; see TuningHelperParamConformanceTest, which lives in the test tree and so is not on the javadoc classpath.
    • PARAM_DESCRIPTIONS

      static final Map<String,String> PARAM_DESCRIPTIONS
      Param name to console description, at most 70 characters since it renders beside its control in the tuning page. Package-visible for the same reason as DISPLAY_NAMES.
    • SUBSYSTEM_ORDER

      private static final String[] SUBSYSTEM_ORDER
      Subsystems in the order the tuner page displays them, alphabetical.
    • SECTION_LABELS

      private static final Map<String,String> SECTION_LABELS
      Single-word section heading for each subsystem.
    • METRIC_STATS

      private static final Map<String,String[]> METRIC_STATS
      Maps each Tuner subsystem metric identifier (as reported by Tuner.SubsystemScore.details) to the stat that backs it and a value format, so ring tooltips can show live values. Metrics with no backing stat are absent and omitted from the tooltip - a bare identifier without a value tells the reader nothing.

      Format is one of: "ms" (duration average), "pct" (0-100 average), "pct1000" (per-mille average), "count" (events in the last minute), "num" (plain average).

  • Constructor Details

    • TuningHelper

      public TuningHelper()
      No CSRF nonce set yet, so the rendered form would carry an empty hidden field until setNonce(String) is called.
  • Method Details

    • setNonce

      public void setNonce(String nonce)
      Records the CSRF nonce embedded in the rendered tuning form.
      Parameters:
      nonce - the console CSRF nonce to embed in the hidden field of the rendered tuning form
    • getTuning

      public String getTuning()
      Main content: editable tables of tunable params with sparklines.
      Returns:
      the tuning tables as HTML, or a notice if auto-tuning is unavailable
    • getDisplayName

      private String getDisplayName(String name)
      Return a human-readable display name for a raw param name, falling back to the raw name if unmapped.
      Parameters:
      name - the raw Tuner parameter name to look up
      Returns:
      the display name
    • renderSparkline

      private static String renderSparkline(int[] values, int defaultValue)
      Render an inline SVG sparkline. Diverging bar chart: center line = default value, bars in the single tuner graph colour, above the line when tuned up and below when tuned down. Newest sample on the left.
      Parameters:
      values - the sampled tuner values, newest sample drawn on the left
      defaultValue - the untuned value, drawn as the chart's center line
      Returns:
      the inline SVG markup, or a "Collecting..." span if fewer than two samples
    • esc

      private static String esc(String s)
      Escapes a value for display in HTML.
      Parameters:
      s - the text to escape
      Returns:
      the text to show
    • formatMetricValue

      static String formatMetricValue(String format, double avg, long count1m)
      Format one metric value for a ring tooltip.
      Parameters:
      format - one of "ms", "pct", "pct1000", "count", "num"
      avg - the 1-minute average event value
      count1m - events in the last minute (current partial window preferred)
      Returns:
      the formatted value, or null when the metric has no data to show
    • metricDetails

      private String[] metricDetails(String[] metrics)
      Resolve a subsystem's metric identifiers to tooltip lines carrying each stat's live value, e.g. "jobQueue.jobLag: 12ms". Metrics with no mapping or no stat are skipped. Returns null when nothing resolves, so the ring simply gets no tooltip instead of an identifier list.
      Parameters:
      metrics - the metric identifiers from the subsystem score, may be null
      Returns:
      tooltip lines, or null if none resolve
    • renderSubsystemRings

      private String renderSubsystemRings(Tuner tuner, boolean defer)
      Render the subsystem ring chart dashboard. Returns an HTML div with a grid of SVG ring charts, one per subsystem. NaN-scored subsystems show a gray "collecting..." ring.
      Parameters:
      tuner - the Tuner whose subsystem scores are rendered
      defer - true to force every score to NaN, showing gray collecting rings
      Returns:
      the HTML div with the ring grid, empty if there are no subsystem scores
    • getTuner

      private Tuner getTuner()
      Get the SSU transport tuner instance.
      Returns:
      the UDPTransport's Tuner, or null