Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
GC::Profiler.configure
GC::Profiler.configure(max_records: 4096) → nil
gc/default/default.c
View on GitHub ↗
static VALUE
gc_profile_configure(int argc, VALUE *argv, VALUE _)
{
static ID keywords[1] = {0};
VALUE options, max_records;
rb_objspace_t *objspace = rb_gc_get_objspace();
if (!keywords[0]) {
keywords[0] = rb_intern("max_records");
}
rb_scan_args_kw(rb_keyword_given_p(), argc, argv, ":", &options);
rb_get_kwargs(options, keywords, 0, 1, &max_records);
if (max_records == Qundef) {
return Qnil;
}
else if (NIL_P(max_records)) {
objspace->profile.max_records = GC_PROFILE_RECORD_UNBOUNDED;
}
else {
long value = NUM2LONG(max_records);
if (value <= 0) {
rb_raise(rb_eArgError, "max_records must be positive or nil");
}
objspace->profile.max_records = (size_t)value;
}
gc_profile_records_free(objspace);
return Qnil;
}
Configures how many raw profile records are retained by GC::Profiler.raw_data.
The profiler keeps at most max_records records in a bounded ring buffer. When the buffer is full, newer GC records overwrite the oldest retained records. The default limit is 4096 records.
Pass nil to restore the historical unbounded behavior:
Example
GC::Profiler.configure(max_records: nil)
Changing max_records clears existing raw profile data. This method does not enable or disable the profiler; use GC::Profiler.enable and GC::Profiler.disable for that.