discourse/lib/gc_stat_instrumenter.rb
Alan Guo Xiang Tan 773b22e8d0
DEV: Seperate concerns of tracking GC stat from MethodProfiler (#22921)
Why this change?

This is a follow up to e8f7b62752.
Tracking of GC stats didn't really belong in the `MethodProfiler` class
so we want to extract that concern into its own class.

As part of this PR, the `track_gc_stat_per_request` site setting has
also been renamed to `instrument_gc_stat_per_request`.
2023-08-02 10:46:37 +08:00

18 lines
422 B
Ruby

# frozen_string_literal: true
class GCStatInstrumenter
def self.instrument
start_gc_stat = GC.stat
yield
end_gc_stat = GC.stat
{
gc: {
time: (end_gc_stat[:time] - start_gc_stat[:time]) / 1000.0,
major_count: end_gc_stat[:major_gc_count] - start_gc_stat[:major_gc_count],
minor_count: end_gc_stat[:minor_gc_count] - start_gc_stat[:minor_gc_count],
},
}
end
end