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(*args) ⇒ 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.
13364 13365 13366 13367 13368 13369 13370 13371 13372 13373 13374 13375 |
# File 'gc.c', line 13364 static VALUE gc_profile_clear(VALUE _) { rb_objspace_t *objspace = &rb_objspace; void *p = objspace->profile.records; objspace->profile.records = NULL; objspace->profile.size = 0; objspace->profile.next_index = 0; objspace->profile.current_record = 0; free(p); return Qnil; } |
.GC::Profiler.disable(->nil) ⇒ Object
Stops the GC profiler.
13707 13708 13709 13710 13711 13712 13713 13714 13715 |
# File 'gc.c', line 13707 static VALUE gc_profile_disable(VALUE _) { rb_objspace_t *objspace = &rb_objspace; objspace->profile.run = FALSE; objspace->profile.current_record = 0; return Qnil; } |
.GC::Profiler.enable(->nil) ⇒ Object
Starts the GC profiler.
13690 13691 13692 13693 13694 13695 13696 13697 |
# File 'gc.c', line 13690 static VALUE gc_profile_enable(VALUE _) { rb_objspace_t *objspace = &rb_objspace; objspace->profile.run = TRUE; objspace->profile.current_record = 0; return Qnil; } |
.GC::Profiler.enabled?(->true) ⇒ Boolean
The current status of GC profile mode.
13675 13676 13677 13678 13679 13680 |
# File 'gc.c', line 13675 static VALUE gc_profile_enable_get(VALUE self) { rb_objspace_t *objspace = &rb_objspace; return RBOOL(objspace->profile.run); } |
.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_PAGES
:HEAP_LIVE_OBJECTS
:HEAP_FREE_OBJECTS
:HAVE_FINALIZE
13427 13428 13429 13430 13431 13432 13433 13434 13435 13436 13437 13438 13439 13440 13441 13442 13443 13444 13445 13446 13447 13448 13449 13450 13451 13452 13453 13454 13455 13456 13457 13458 13459 13460 13461 13462 13463 13464 13465 13466 13467 13468 13469 13470 13471 13472 13473 13474 13475 |
# File 'gc.c', line 13427 static VALUE gc_profile_record_get(VALUE _) { 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.next_index; i++) { gc_profile_record *record = &objspace->profile.records[i]; prof = rb_hash_new(); rb_hash_aset(prof, ID2SYM(rb_intern("GC_FLAGS")), gc_info_decode(objspace, rb_hash_new(), record->flags)); rb_hash_aset(prof, ID2SYM(rb_intern("GC_TIME")), DBL2NUM(record->gc_time)); rb_hash_aset(prof, ID2SYM(rb_intern("GC_INVOKE_TIME")), DBL2NUM(record->gc_invoke_time)); rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_SIZE")), SIZET2NUM(record->heap_use_size)); rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")), SIZET2NUM(record->heap_total_size)); rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")), SIZET2NUM(record->heap_total_objects)); rb_hash_aset(prof, ID2SYM(rb_intern("MOVED_OBJECTS")), SIZET2NUM(record->moved_objects)); rb_hash_aset(prof, ID2SYM(rb_intern("GC_IS_MARKED")), Qtrue); #if GC_PROFILE_MORE_DETAIL rb_hash_aset(prof, ID2SYM(rb_intern("GC_MARK_TIME")), DBL2NUM(record->gc_mark_time)); rb_hash_aset(prof, ID2SYM(rb_intern("GC_SWEEP_TIME")), DBL2NUM(record->gc_sweep_time)); rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_INCREASE")), SIZET2NUM(record->allocate_increase)); rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_LIMIT")), SIZET2NUM(record->allocate_limit)); rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_PAGES")), SIZET2NUM(record->heap_use_pages)); rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_LIVE_OBJECTS")), SIZET2NUM(record->heap_live_objects)); rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_FREE_OBJECTS")), SIZET2NUM(record->heap_free_objects)); rb_hash_aset(prof, ID2SYM(rb_intern("REMOVING_OBJECTS")), SIZET2NUM(record->removing_objects)); rb_hash_aset(prof, ID2SYM(rb_intern("EMPTY_OBJECTS")), SIZET2NUM(record->empty_objects)); rb_hash_aset(prof, ID2SYM(rb_intern("HAVE_FINALIZE")), RBOOL(record->flags & GPR_FLAG_HAVE_FINALIZE)); #endif #if RGENGC_PROFILE > 0 rb_hash_aset(prof, ID2SYM(rb_intern("OLD_OBJECTS")), SIZET2NUM(record->old_objects)); rb_hash_aset(prof, ID2SYM(rb_intern("REMEMBERED_NORMAL_OBJECTS")), SIZET2NUM(record->remembered_normal_objects)); rb_hash_aset(prof, ID2SYM(rb_intern("REMEMBERED_SHADY_OBJECTS")), SIZET2NUM(record->remembered_shady_objects)); #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.
13633 13634 13635 13636 13637 13638 13639 13640 13641 13642 |
# File 'gc.c', line 13633 static VALUE gc_profile_report(int argc, VALUE *argv, VALUE self) { VALUE out; out = (!rb_check_arity(argc, 0, 1) ? rb_stdout : argv[0]); 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
13616 13617 13618 13619 13620 13621 13622 |
# File 'gc.c', line 13616 static VALUE gc_profile_result(VALUE _) { 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
13651 13652 13653 13654 13655 13656 13657 13658 13659 13660 13661 13662 13663 13664 13665 13666 |
# File 'gc.c', line 13651 static VALUE gc_profile_total_time(VALUE self) { double time = 0; rb_objspace_t *objspace = &rb_objspace; if (objspace->profile.run && objspace->profile.next_index > 0) { size_t i; size_t count = objspace->profile.next_index; for (i = 0; i < count; i++) { time += objspace->profile.records[i].gc_time; } } return DBL2NUM(time); } |