Skip to content

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

class method

GC::Profiler.raw_data

() -> ::Array[::Hash[::Symbol, untyped]]?
GC::Profiler.raw_data(limit: nil, since: nil) → [Hash, ...]

Returns an Array of retained raw profile data Hashes ordered from earliest to latest by :GC_INVOKE_TIME. limit: returns at most the newest retained records. since: returns records with :GC_SEQUENCE greater than the given sequence.

For example:

Example
[
  {
     :GC_TIME=>1.3000000000000858e-05,
     :GC_INVOKE_TIME=>0.010634999999999999,
     :GC_WALL_TIME=>1.4000000000000001e-05,
     :GC_INVOKE_WALL_TIME=>0.010640000000000000,
     :GC_PAUSE_TIME=>1.5000000000000000e-05,
     :GC_STOP_TIME=>1.0000000000000000e-06,
     :GC_STW_TIME=>1.4000000000000001e-05,
     :GC_MARK_WALL_TIME=>9.0000000000000002e-06,
     :GC_SWEEP_WALL_TIME=>5.0000000000000004e-06,
     :GC_COMPACT_WALL_TIME=>0.0000000000000000e+00,
     :HEAP_USE_SIZE=>289640,
     :HEAP_TOTAL_SIZE=>588960,
     :HEAP_TOTAL_OBJECTS=>14724,
     :GC_IS_MARKED=>false
  },
  # ...
]

The keys mean:

:GC_SEQUENCE

Monotonically increasing sequence number for this profiler record.

:GC_TIME

CPU time elapsed in seconds for this GC run. This is process CPU time, not elapsed wall-clock time.

:GC_INVOKE_TIME

CPU time elapsed in seconds from startup to when the GC was invoked.

:GC_WALL_TIME

Monotonic wall-clock counterpart to :GC_TIME for this GC record. This does not include time spent stopping other ractors before the VM enters GC. Use the phase wall-clock fields below for mark, sweep, and compaction attribution.

:GC_INVOKE_WALL_TIME

Monotonic wall-clock time elapsed in seconds from startup to when the GC was invoked.

:GC_PAUSE_TIME

Monotonic wall-clock time elapsed in seconds while user execution was blocked by this GC entry, including time to stop other ractors. This may include time from incremental marking or lazy sweeping continuation charged to this record.

:GC_STOP_TIME

Monotonic wall-clock time elapsed in seconds stopping other ractors.

:GC_STW_TIME

Monotonic wall-clock time elapsed in seconds after other ractors have stopped and before the VM exits GC.

:GC_MARK_WALL_TIME

Monotonic wall-clock time elapsed in seconds spent marking for this GC record, accumulated across incremental marking continuations.

:GC_SWEEP_WALL_TIME

Monotonic wall-clock time elapsed in seconds spent sweeping for this GC record, accumulated across lazy sweeping continuations. This does not include compaction time, which is reported separately as :GC_COMPACT_WALL_TIME.

:GC_COMPACT_WALL_TIME

Monotonic wall-clock time elapsed in seconds spent compacting for this GC record, or 0.0 if this GC did not compact.

:HEAP_USE_SIZE

Total bytes of heap used

:HEAP_TOTAL_SIZE

Total size of heap in bytes

:HEAP_TOTAL_OBJECTS

Total number of objects

:GC_IS_MARKED

Returns true if the GC is in mark phase

The wall-clock timing fields relate to each other as follows:

Example
GC_PAUSE_TIME == GC_STOP_TIME + GC_STW_TIME

:GC_MARK_WALL_TIME, :GC_SWEEP_WALL_TIME, and :GC_COMPACT_WALL_TIME report separate phase timings and must not be added to :GC_WALL_TIME.

:GC_WALL_TIME is the wall-clock counterpart to :GC_TIME and is nested inside :GC_STW_TIME, so it must not be added to :GC_STW_TIME. The difference +GC_STW_TIME - GC_WALL_TIME+ is VM overhead inside the stopped interval (GC event hooks, bookkeeping, consistency checks, and continuation work).

If ruby was built with GC_PROFILE_MORE_DETAIL, you will also have access to the following hash keys:

:GC_MARK_TIME
:GC_SWEEP_TIME
:ALLOCATE_INCREASE
:ALLOCATE_LIMIT
:HEAP_USE_PAGES
:HEAP_LIVE_OBJECTS
:HEAP_FREE_OBJECTS
:HAVE_FINALIZE
See also .enabled? .report .enable .result also in 3.3 · 3.2 · 3.1 · 3.0