Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
GC.total_time
# File tmp/rubies/ruby-4.1.0-preview1/gc.rb, line 684
def self.total_time
Primitive.cexpr! %{
ULL2NUM(rb_gc_impl_get_total_time(rb_gc_get_objspace()))
}
end
Returns the GC total time in nanoseconds:
With the default collector, this is the current Ractor’s measured GC CPU work, not wall-clock pause time.
GC.total_time # => 156250
Note that total time accumulates only when total time measurement is enabled (that is, when GC.measure_total_time is true):
GC.measure_total_time # => true GC.total_time # => 625000 GC.start GC.total_time # => 937500 GC.start GC.total_time # => 1093750 GC.measure_total_time = false GC.total_time # => 1250000 GC.start GC.total_time # => 1250000 GC.start GC.total_time # => 1250000 GC.measure_total_time = true GC.total_time # => 1250000 GC.start GC.total_time # => 1406250
Ruby version changes
-
4.1
-
GC.statacceptsscope: :ractor(the default),scope: :local(a synonym for:ractor), andscope: :global. With the default collector, the global scope reports cumulative collection counts and measured marking/sweeping CPU time across Ractors, including history from destroyed object spaces, without requesting a stop-the-world snapshot. UnscopedGC.stat,GC.count, andGC.total_timeretain their current-Ractor behavior.
-
-
3.1
-
GC.total_timereturns measured time in nano-seconds. [[Feature #10917]]
-