class Fontist::IndexStats
Statistics tracking for index building (thread-safe)
Attributes
Public Class Methods
Source
# File lib/fontist/system_index.rb, line 11 def initialize @cache_hits = 0 @cache_misses = 0 @total_fonts = 0 @parsed_fonts = 0 @skipped_fonts = 0 @errors = 0 @validation_failures = 0 @start_time = Time.now @mutex = Mutex.new end
Public Instance Methods
Source
# File lib/fontist/system_index.rb, line 56 def avg_time_per_font return 0 if @parsed_fonts.zero? elapsed_time / @parsed_fonts end
Source
# File lib/fontist/system_index.rb, line 62 def cache_hit_rate return 0 if @total_fonts.zero? (@cache_hits.to_f / @total_fonts * 100).round(1) end
Source
# File lib/fontist/system_index.rb, line 52 def elapsed_time Time.now - @start_time end
Source
# File lib/fontist/system_index.rb, line 81 def print_summary(verbose: false) return unless verbose s = summary puts "\n#{Paint['=' * 80, :cyan]}" puts Paint["Index Build Statistics:", :cyan, :bright] puts Paint["=" * 80, :cyan] puts " Total time: #{Paint[format('%.2f', s[:total_time]), :green]} seconds" puts " Total fonts: #{Paint[s[:total_fonts], :yellow]}" puts " Parsed fonts: #{Paint[s[:parsed_fonts], :yellow]}" puts " Cached fonts: #{Paint[s[:cached_fonts], :green]}" puts " Cache hit rate: #{Paint[s[:cache_hit_rate], :green]}" puts " Errors: #{Paint[s[:errors], s[:errors].zero? ? :green : :red]}" puts " Validation failures: #{Paint[s[:validation_failures], s[:validation_failures].zero? ? :green : :yellow]}" puts " Avg time per font: #{Paint[format('%.4f', s[:avg_time_per_font]), :green]} seconds" puts Paint["=" * 80, :cyan] end
Source
# File lib/fontist/system_index.rb, line 27 def record_cache_hit @mutex.synchronize do @cache_hits += 1 @skipped_fonts += 1 end end
Source
# File lib/fontist/system_index.rb, line 34 def record_cache_miss @mutex.synchronize do @cache_misses += 1 @parsed_fonts += 1 end end
Source
# File lib/fontist/system_index.rb, line 41 def record_error @mutex.synchronize { @errors += 1 } end
Source
# File lib/fontist/system_index.rb, line 45 def record_validation_failure @mutex.synchronize do @validation_failures += 1 @errors += 1 end end
Source
# File lib/fontist/system_index.rb, line 68 def summary { total_time: elapsed_time.round(2), total_fonts: @total_fonts, parsed_fonts: @parsed_fonts, cached_fonts: @cache_hits, errors: @errors, validation_failures: @validation_failures, cache_hit_rate: "#{cache_hit_rate}%", avg_time_per_font: avg_time_per_font.round(4), } end
Source
# File lib/fontist/system_index.rb, line 23 def total_fonts=(value) @mutex.synchronize { @total_fonts = value } end