Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method · added in Ruby 3.1

GC.total_time

() -> ::Integer
GC.total_time → integer

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.

Example
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):

Example
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

  1. 4.1
    • GC.stat accepts scope: :ractor (the default), scope: :local (a synonym for :ractor), and scope: :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. Unscoped GC.stat, GC.count, and GC.total_time retain their current-Ractor behavior.

  2. 3.1