Class: JekyllImgFlow::ProcessingStats
- Inherits:
-
Object
- Object
- JekyllImgFlow::ProcessingStats
- Defined in:
- lib/jekyll-imgflow/processing_stats.rb
Overview
ProcessingStats — collects cache hit/miss, per-operation timing, and compression ratio metrics during a Jekyll build. Accessed by the performance benchmark to report beyond wall-clock time.
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.
-
#compression_ratios ⇒ Object
readonly
Returns the value of attribute compression_ratios.
-
#operation_timings ⇒ Object
readonly
Returns the value of attribute operation_timings.
Instance Method Summary collapse
-
#average_compression_ratios ⇒ Object
Average compression ratio per format.
- #cache_hit_rate ⇒ Object
-
#initialize ⇒ ProcessingStats
constructor
A new instance of ProcessingStats.
- #record_cache_hit ⇒ Object
- #record_cache_miss ⇒ Object
-
#record_compression_ratio(format, original_size, output_size) ⇒ Object
Record compression ratio for a format (e.g. "webp" => 78.5 percent saved).
-
#record_operation_time(type, seconds) ⇒ Object
Record wall-clock time for a specific operation type (:resize, :format, etc.).
- #reset ⇒ Object
- #to_h ⇒ Object
- #total_processed ⇒ Object
Constructor Details
#initialize ⇒ ProcessingStats
Returns a new instance of ProcessingStats.
10 11 12 13 14 15 16 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 10 def initialize @cache_hits = 0 @cache_misses = 0 @operation_timings = Hash.new { |h, k| h[k] = 0.0 } @compression_ratios = {} @mutex = Mutex.new end |
Instance Attribute Details
#cache_hits ⇒ Object (readonly)
Returns the value of attribute cache_hits.
8 9 10 |
# File 'lib/jekyll-imgflow/processing_stats.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/jekyll-imgflow/processing_stats.rb', line 8 def cache_misses @cache_misses end |
#compression_ratios ⇒ Object (readonly)
Returns the value of attribute compression_ratios.
8 9 10 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 8 def compression_ratios @compression_ratios end |
#operation_timings ⇒ Object (readonly)
Returns the value of attribute operation_timings.
8 9 10 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 8 def operation_timings @operation_timings end |
Instance Method Details
#average_compression_ratios ⇒ Object
Average compression ratio per format
44 45 46 47 48 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 44 def average_compression_ratios @compression_ratios.transform_values do |data| (data[:ratios].sum / data[:count]).round(1) if data[:count].positive? end end |
#cache_hit_rate ⇒ Object
54 55 56 57 58 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 54 def cache_hit_rate return 0.0 if total_processed.zero? (@cache_hits.to_f / total_processed * 100).round(1) end |
#record_cache_hit ⇒ Object
18 19 20 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 18 def record_cache_hit @mutex.synchronize { @cache_hits += 1 } end |
#record_cache_miss ⇒ Object
22 23 24 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 22 def record_cache_miss @mutex.synchronize { @cache_misses += 1 } end |
#record_compression_ratio(format, original_size, output_size) ⇒ Object
Record compression ratio for a format (e.g. "webp" => 78.5 percent saved)
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 32 def record_compression_ratio(format, original_size, output_size) return if original_size.zero? ratio = ((original_size - output_size).to_f / original_size * 100).round(1) @mutex.synchronize do @compression_ratios[format] ||= { ratios: [], count: 0 } @compression_ratios[format][:ratios] << ratio @compression_ratios[format][:count] += 1 end end |
#record_operation_time(type, seconds) ⇒ Object
Record wall-clock time for a specific operation type (:resize, :format, etc.)
27 28 29 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 27 def record_operation_time(type, seconds) @mutex.synchronize { @operation_timings[type] += seconds } end |
#reset ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 71 def reset @mutex.synchronize do @cache_hits = 0 @cache_misses = 0 @operation_timings.clear @compression_ratios.clear end end |
#to_h ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 60 def to_h { cache_hits: @cache_hits, cache_misses: @cache_misses, cache_hit_rate: cache_hit_rate, total_processed: total_processed, operation_timings: @operation_timings.transform_values { |v| v.round(3) }, compression_ratios: average_compression_ratios } end |
#total_processed ⇒ Object
50 51 52 |
# File 'lib/jekyll-imgflow/processing_stats.rb', line 50 def total_processed @cache_hits + @cache_misses end |