Class: Fontist::IndexStats
- Inherits:
-
Object
- Object
- Fontist::IndexStats
- Defined in:
- lib/fontist/system_index.rb
Overview
Statistics tracking for index building (thread-safe)
Instance Attribute Summary collapse
-
#cache_hits ⇒ Object
readonly
Returns the value of attribute cache_hits.
-
#cache_misses ⇒ Object
readonly
Returns the value of attribute cache_misses.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#parsed_fonts ⇒ Object
readonly
Returns the value of attribute parsed_fonts.
-
#skipped_fonts ⇒ Object
readonly
Returns the value of attribute skipped_fonts.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#total_fonts ⇒ Object
Returns the value of attribute total_fonts.
-
#validation_failures ⇒ Object
readonly
Returns the value of attribute validation_failures.
Instance Method Summary collapse
- #avg_time_per_font ⇒ Object
- #cache_hit_rate ⇒ Object
- #elapsed_time ⇒ Object
-
#initialize ⇒ IndexStats
constructor
A new instance of IndexStats.
- #print_summary(verbose: false) ⇒ Object
- #record_cache_hit ⇒ Object
- #record_cache_miss ⇒ Object
- #record_error ⇒ Object
- #record_validation_failure ⇒ Object
- #summary ⇒ Object
Constructor Details
#initialize ⇒ IndexStats
Returns a new instance of IndexStats.
11 12 13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Attribute Details
#cache_hits ⇒ Object (readonly)
Returns the value of attribute cache_hits.
8 9 10 |
# File 'lib/fontist/system_index.rb', line 8 def cache_hits @cache_hits end |
#cache_misses ⇒ Object (readonly)
Returns the value of attribute cache_misses.
8 9 10 |
# File 'lib/fontist/system_index.rb', line 8 def cache_misses @cache_misses end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/fontist/system_index.rb', line 8 def errors @errors end |
#parsed_fonts ⇒ Object (readonly)
Returns the value of attribute parsed_fonts.
8 9 10 |
# File 'lib/fontist/system_index.rb', line 8 def parsed_fonts @parsed_fonts end |
#skipped_fonts ⇒ Object (readonly)
Returns the value of attribute skipped_fonts.
8 9 10 |
# File 'lib/fontist/system_index.rb', line 8 def skipped_fonts @skipped_fonts end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
8 9 10 |
# File 'lib/fontist/system_index.rb', line 8 def start_time @start_time end |
#total_fonts ⇒ Object
Returns the value of attribute total_fonts.
8 9 10 |
# File 'lib/fontist/system_index.rb', line 8 def total_fonts @total_fonts end |
#validation_failures ⇒ Object (readonly)
Returns the value of attribute validation_failures.
8 9 10 |
# File 'lib/fontist/system_index.rb', line 8 def validation_failures @validation_failures end |
Instance Method Details
#avg_time_per_font ⇒ Object
56 57 58 59 60 |
# File 'lib/fontist/system_index.rb', line 56 def avg_time_per_font return 0 if @parsed_fonts.zero? elapsed_time / @parsed_fonts end |
#cache_hit_rate ⇒ Object
62 63 64 65 66 |
# 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 |
#elapsed_time ⇒ Object
52 53 54 |
# File 'lib/fontist/system_index.rb', line 52 def elapsed_time Time.now - @start_time end |
#print_summary(verbose: false) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# 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 |
#record_cache_hit ⇒ Object
27 28 29 30 31 32 |
# File 'lib/fontist/system_index.rb', line 27 def record_cache_hit @mutex.synchronize do @cache_hits += 1 @skipped_fonts += 1 end end |
#record_cache_miss ⇒ Object
34 35 36 37 38 39 |
# File 'lib/fontist/system_index.rb', line 34 def record_cache_miss @mutex.synchronize do @cache_misses += 1 @parsed_fonts += 1 end end |
#record_error ⇒ Object
41 42 43 |
# File 'lib/fontist/system_index.rb', line 41 def record_error @mutex.synchronize { @errors += 1 } end |
#record_validation_failure ⇒ Object
45 46 47 48 49 50 |
# File 'lib/fontist/system_index.rb', line 45 def record_validation_failure @mutex.synchronize do @validation_failures += 1 @errors += 1 end end |
#summary ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# 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 |