Module: GC::Profiler
- Defined in:
- gc.c
Class Method Summary collapse
-
.GC::Profiler.clear ⇒ nil
Clears the GC profiler data.
-
.GC::Profiler.disable(->nil) ⇒ Object
Stops the GC profiler.
-
.GC::Profiler.enable(->nil) ⇒ Object
Starts the GC profiler.
-
.GC::Profiler.enabled?(->true) ⇒ Boolean
The current status of GC profile mode.
-
.GC::Profiler.raw_data(->[Hash, ...]) ⇒ Object
Returns an Array of individual raw profile data Hashes ordered from earliest to latest by
:GC_INVOKE_TIME
. -
.report ⇒ Object
Writes the GC::Profiler.result to
$stdout
or the given IO object. -
.GC::Profiler.result ⇒ String
Returns a profile data report such as:.
-
.GC::Profiler.total_time(->float) ⇒ Object
The total time used for garbage collection in seconds.
Class Method Details
.GC::Profiler.clear ⇒ nil
Clears the GC profiler data.
4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 |
# File 'gc.c', line 4110
static VALUE
gc_profile_clear(void)
{
rb_objspace_t *objspace = &rb_objspace;
if (GC_PROFILE_RECORD_DEFAULT_SIZE * 2 < objspace->profile.size) {
objspace->profile.size = GC_PROFILE_RECORD_DEFAULT_SIZE * 2;
objspace->profile.record = realloc(objspace->profile.record, sizeof(gc_profile_record) * objspace->profile.size);
if (!objspace->profile.record) {
rb_memerror();
}
}
MEMZERO(objspace->profile.record, gc_profile_record, objspace->profile.size);
objspace->profile.count = 0;
return Qnil;
}
|
.GC::Profiler.disable(->nil) ⇒ Object
Stops the GC profiler.
4358 4359 4360 4361 4362 4363 4364 4365 |
# File 'gc.c', line 4358
static VALUE
gc_profile_disable(void)
{
rb_objspace_t *objspace = &rb_objspace;
objspace->profile.run = FALSE;
return Qnil;
}
|
.GC::Profiler.enable(->nil) ⇒ Object
Starts the GC profiler.
4341 4342 4343 4344 4345 4346 4347 4348 |
# File 'gc.c', line 4341
static VALUE
gc_profile_enable(void)
{
rb_objspace_t *objspace = &rb_objspace;
objspace->profile.run = TRUE;
return Qnil;
}
|
.GC::Profiler.enabled?(->true) ⇒ Boolean
The current status of GC profile mode.
4326 4327 4328 4329 4330 4331 |
# File 'gc.c', line 4326
static VALUE
gc_profile_enable_get(VALUE self)
{
rb_objspace_t *objspace = &rb_objspace;
return objspace->profile.run ? Qtrue : Qfalse;
}
|
.GC::Profiler.raw_data(->[Hash, ...]) ⇒ Object
Returns an Array of individual raw profile data Hashes ordered from earliest to latest by :GC_INVOKE_TIME
.
For example:
[
:GC_TIME=>1.3000000000000858e-05,
:GC_INVOKE_TIME=>0.010634999999999999,
:HEAP_USE_SIZE=>289640,
:HEAP_TOTAL_SIZE=>588960,
:HEAP_TOTAL_OBJECTS=>14724,
:GC_IS_MARKED=>false
,
# ...
]
The keys mean:
:GC_TIME
-
Time elapsed in seconds for this GC run
:GC_INVOKE_TIME
-
Time elapsed in seconds from startup to when the GC was invoked
: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 phaseIf 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_SLOTS
:HEAP_LIVE_OBJECTS
:HEAP_FREE_OBJECTS
:HAVE_FINALIZE
4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 |
# File 'gc.c', line 4177
static VALUE
gc_profile_record_get(void)
{
VALUE prof;
VALUE gc_profile = rb_ary_new();
size_t i;
rb_objspace_t *objspace = (&rb_objspace);
if (!objspace->profile.run) {
return Qnil;
}
for (i =0; i < objspace->profile.count; i++) {
prof = rb_hash_new();
rb_hash_aset(prof, ID2SYM(rb_intern("GC_TIME")), DBL2NUM(objspace->profile.record[i].gc_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_INVOKE_TIME")), DBL2NUM(objspace->profile.record[i].gc_invoke_time));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_SIZE")), SIZET2NUM(objspace->profile.record[i].heap_use_size));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")), SIZET2NUM(objspace->profile.record[i].heap_total_size));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")), SIZET2NUM(objspace->profile.record[i].heap_total_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_IS_MARKED")), objspace->profile.record[i].is_marked);
#if GC_PROFILE_MORE_DETAIL
rb_hash_aset(prof, ID2SYM(rb_intern("GC_MARK_TIME")), DBL2NUM(objspace->profile.record[i].gc_mark_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_SWEEP_TIME")), DBL2NUM(objspace->profile.record[i].gc_sweep_time));
rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_INCREASE")), SIZET2NUM(objspace->profile.record[i].allocate_increase));
rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_LIMIT")), SIZET2NUM(objspace->profile.record[i].allocate_limit));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_SLOTS")), SIZET2NUM(objspace->profile.record[i].heap_use_slots));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_LIVE_OBJECTS")), SIZET2NUM(objspace->profile.record[i].heap_live_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_FREE_OBJECTS")), SIZET2NUM(objspace->profile.record[i].heap_free_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("HAVE_FINALIZE")), objspace->profile.record[i].have_finalize);
#endif
rb_ary_push(gc_profile, prof);
}
return gc_profile;
}
|
.GC::Profiler.report ⇒ Object .GC::Profiler.report(io) ⇒ Object
Writes the GC::Profiler.result to $stdout
or the given IO object.
4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 |
# File 'gc.c', line 4281
static VALUE
gc_profile_report(int argc, VALUE *argv, VALUE self)
{
VALUE out;
if (argc == 0) {
out = rb_stdout;
}
else {
rb_scan_args(argc, argv, "01", &out);
}
gc_profile_dump_on(out, rb_io_write);
return Qnil;
}
|
.GC::Profiler.result ⇒ String
Returns a profile data report such as:
GC 1 invokes.
Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC time(ms)
1 0.012 159240 212940 10647 0.00000000000001530000
4264 4265 4266 4267 4268 4269 4270 |
# File 'gc.c', line 4264
static VALUE
gc_profile_result(void)
{
VALUE str = rb_str_buf_new(0);
gc_profile_dump_on(str, rb_str_buf_append);
return str;
}
|
.GC::Profiler.total_time(->float) ⇒ Object
The total time used for garbage collection in seconds
4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 |
# File 'gc.c', line 4304
static VALUE
gc_profile_total_time(VALUE self)
{
double time = 0;
rb_objspace_t *objspace = &rb_objspace;
size_t i;
if (objspace->profile.run && objspace->profile.count) {
for (i = 0; i < objspace->profile.count; i++) {
time += objspace->profile.record[i].gc_time;
}
}
return DBL2NUM(time);
}
|