Module: RSpecTelemetry::GcSample
- Defined in:
- lib/rspec_telemetry/gc_sample.rb
Overview
Snapshots GC counters around an example so example.finished can carry the GC cost of that example. GC time is process-global: an example may pay for garbage a previous example allocated, so treat the attribution as a trend indicator, not an exact per-example cost.
Class Method Summary collapse
Class Method Details
.delta(before, after) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rspec_telemetry/gc_sample.rb', line 22 def delta(before, after) return nil unless before && after { gc_time_ms: ((after[:total_time_ns] - before[:total_time_ns]) / 1_000_000.0).round(3), gc_count: after[:count] - before[:count], gc_major_count: after[:major] - before[:major], gc_minor_count: after[:minor] - before[:minor], allocated_objects: after[:allocated] - before[:allocated] } end |
.take ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rspec_telemetry/gc_sample.rb', line 11 def take stat = GC.stat { total_time_ns: GC.total_time, count: stat[:count], major: stat[:major_gc_count], minor: stat[:minor_gc_count], allocated: stat[:total_allocated_objects] } end |