Module: GC::Profiler
- Defined in:
- gc.c
Overview
The GC profiler provides access to information on GC runs including time, length and object space size.
Example:
GC::Profiler.enable
require 'rdoc/rdoc'
puts GC::Profiler.result
GC::Profiler.disable
See also GC.count, GC.malloc_allocated_size and GC.malloc_allocations
Class Method Summary (collapse)
-
+ (nil) GC::Profiler.clear
Clears the GC profiler data.
-
+ (nil) GC::Profiler.disable
Stops the GC profiler.
-
+ (nil) GC::Profiler.enable
Starts the GC profiler.
-
+ (Boolean) GC::Profiler.enable?
The current status of GC profile mode.
-
+ (Object) report
Writes the GC::Profiler#result to $stdout or the given IO object.
-
+ (String) GC::Profiler.result
Returns a profile data report such as:.
-
+ (Float) GC::Profiler.total_time
The total time used for garbage collection in milliseconds.
Class Method Details
+ (nil) GC::Profiler.clear
Clears the GC profiler data.
|
|
# File 'gc.c'
static VALUE
gc_profile_clear(void)
{
rb_objspace_t *objspace = &rb_objspace;
MEMZERO(objspace->profile.record, gc_profile_record, objspace->profile.size);
objspace->profile.count = 0;
return Qnil;
}
|
+ (nil) GC::Profiler.disable
Stops the GC profiler.
|
|
# File 'gc.c'
static VALUE
gc_profile_disable(void)
{
rb_objspace_t *objspace = &rb_objspace;
objspace->profile.run = FALSE;
return Qnil;
}
|
+ (nil) GC::Profiler.enable
Starts the GC profiler.
|
|
# File 'gc.c'
static VALUE
gc_profile_enable(void)
{
rb_objspace_t *objspace = &rb_objspace;
objspace->profile.run = TRUE;
return Qnil;
}
|
+ (Boolean) GC::Profiler.enable?
The current status of GC profile mode.
|
|
# File 'gc.c'
static VALUE
gc_profile_enable_get(VALUE self)
{
rb_objspace_t *objspace = &rb_objspace;
return objspace->profile.run;
}
|
+ (Object) GC::Profiler.report + (Object) GC::Profiler.report(io)
Writes the GC::Profiler#result to $stdout or the given IO object.
|
|
# File 'gc.c'
static VALUE
gc_profile_report(int argc, VALUE *argv, VALUE self)
{
VALUE out;
if (argc == 0) {
out = rb_stdout;
}
|
+ (String) GC::Profiler.result
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
|
|
# File 'gc.c'
static VALUE
gc_profile_result(void)
{
rb_objspace_t *objspace = &rb_objspace;
VALUE record;
VALUE result;
int i, index;
record = gc_profile_record_get();
if (objspace->profile.run && objspace->profile.count) {
result = rb_sprintf("GC %d invokes.\n", NUM2INT(gc_count(0)));
index = 1;
rb_str_cat2(result, "Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC Time(ms)\n");
for (i = 0; i < (int)RARRAY_LEN(record); i++) {
VALUE r = RARRAY_PTR(record)[i];
#if !GC_PROFILE_MORE_DETAIL
if (rb_hash_aref(r, ID2SYM(rb_intern("GC_IS_MARKED")))) {
#endif
rb_str_catf(result, "%5d %19.3f %20"PRIuSIZE" %20"PRIuSIZE" %20"PRIuSIZE" %30.20f\n",
index++, NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_INVOKE_TIME")))),
(size_t)NUM2SIZET(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SIZE")))),
(size_t)NUM2SIZET(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")))),
(size_t)NUM2SIZET(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")))),
NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_TIME"))))*1000);
#if !GC_PROFILE_MORE_DETAIL
}
|
+ (Float) GC::Profiler.total_time
The total time used for garbage collection in milliseconds
|
|
# File 'gc.c'
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;
}
|