Class BadgeGenerator

java.lang.Object
de.cuioss.benchmarking.common.report.BadgeGenerator

public class BadgeGenerator extends Object
Generates shields.io compatible JSON badge files for benchmark metrics.

This generator creates three types of badges:

  • Performance badge - Shows the current performance grade
  • Trend badge - Shows the trend direction with percentage change
  • Last run badge - Shows when the benchmarks were last executed

All badges follow the shields.io JSON endpoint schema for easy integration with GitHub README files and documentation.

  • Constructor Details

  • Method Details

    • generatePerformanceBadge

      Generates a performance badge JSON based on the benchmark metrics. Format: "Grade A (45k ops/s, 0.15ms)"
      Parameters:
      metrics - the current benchmark metrics
      Returns:
      JSON string for the performance badge
    • generateTrendBadge

      Generates a trend badge JSON based on the trend metrics.
      Parameters:
      trendMetrics - the calculated trend metrics
      Returns:
      JSON string for the trend badge
    • generateLastRunBadge

      public String generateLastRunBadge(Instant timestamp)
      Generates a last run timestamp badge.
      Parameters:
      timestamp - the benchmark run timestamp
      Returns:
      JSON string for the last run badge
    • generateDefaultTrendBadge

      Generates a default trend badge when no historical data is available.
      Returns:
      JSON string for the default trend badge
    • writeBadgeFiles

      public void writeBadgeFiles(BenchmarkMetrics metrics, TrendDataProcessor.TrendMetrics trendMetrics, String outputDir) throws IOException
      Writes all badge files to the specified directory using default MICRO benchmark type. Convenience overload that defaults to BenchmarkType.MICRO.
      Parameters:
      metrics - the current benchmark metrics
      trendMetrics - the trend metrics (can be null)
      outputDir - the output directory path
      Throws:
      IOException - if writing badge files fails
    • writeBadgeFiles

      public void writeBadgeFiles(BenchmarkMetrics metrics, TrendDataProcessor.TrendMetrics trendMetrics, BenchmarkType type, String outputDir) throws IOException
      Writes all badge files to the specified directory.
      Parameters:
      metrics - the current benchmark metrics
      trendMetrics - the trend metrics (can be null)
      type - the benchmark type (MICRO or INTEGRATION)
      outputDir - the output directory path
      Throws:
      IOException - if writing badge files fails