Module: GC::Profiler

Defined in:
gc.c

Class Method Summary (collapse)

Class Method Details

+ (nil) GC::Profiler.clear

clear before profile data.



# File 'gc.c'

/*
 *  call-seq:
 *    GC::Profiler.clear          -> nil
 *
 *  clear before profile data.
 *
 */

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

updates GC profile mode. stop profiler for GC.



# File 'gc.c'

/*
 *  call-seq:
 *    GC::Profiler.disable          -> nil
 *
 *  updates GC profile mode.
 *  stop profiler for GC.
 *
 */

static VALUE
gc_profile_disable(void)
{
    rb_objspace_t *objspace = &rb_objspace;

    objspace->profile.run = FALSE;
    return Qnil;
}

+ (nil) GC::Profiler.enable

updates GC profile mode. start profiler for GC.



# File 'gc.c'

/*
 *  call-seq:
 *    GC::Profiler.enable          -> nil
 *
 *  updates GC profile mode.
 *  start profiler for GC.
 *
 */

static VALUE
gc_profile_enable(void)
{
    rb_objspace_t *objspace = &rb_objspace;

    objspace->profile.run = TRUE;
    return Qnil;
}

+ (Boolean) GC::Profiler.enable?

returns current status of GC profile mode.



# File 'gc.c'

/*
 *  call-seq:
 *    GC::Profiler.enable?                 -> true or false
 *
 *  returns current status of GC profile mode.
 */

static VALUE
gc_profile_enable_get(VALUE self)
{
    rb_objspace_t *objspace = &rb_objspace;
    return objspace->profile.run;
}

+ (Object) GC::Profiler.report

GC::Profiler.result display



# File 'gc.c'

/*
 *  call-seq:
 *     GC::Profiler.report
 *
 *  GC::Profiler.result display
 *
 */

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);
    }
    rb_io_write(out, gc_profile_result());

    return Qnil;
}

+ (String) GC::Profiler.result

Report profile data to string.

It returns a string 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'

/*
 *  call-seq:
 *     GC::Profiler.result -> string
 *
 *  Report profile data to string.
 *
 *  It returns a string 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
 */

static VALUE
gc_profile_result(void)
{
    rb_objspace_t *objspace = &rb_objspace;
    VALUE record;
    VALUE result;
    int i;

    record = gc_profile_record_get();
    if (objspace->profile.run && objspace->profile.count) {
    result = rb_sprintf("GC %d invokes.\n", NUM2INT(gc_count(0)));
    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];
        rb_str_catf(result, "%5d %19.3f %20d %20d %20d %30.20f\n",
            i+1, NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_INVOKE_TIME")))),
            NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SIZE")))),
            NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")))),
            NUM2INT(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
    rb_str_cat2(result, "\n\n");
    rb_str_cat2(result, "More detail.\n");
    rb_str_cat2(result, "Index Allocate Increase    Allocate Limit  Use Slot  Have Finalize             Mark Time(ms)            Sweep Time(ms)\n");
    for (i = 0; i < (int)RARRAY_LEN(record); i++) {
        VALUE r = RARRAY_PTR(record)[i];
        rb_str_catf(result, "%5d %17d %17d %9d %14s %25.20f %25.20f\n",
            i+1, NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("ALLOCATE_INCREASE")))),
            NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("ALLOCATE_LIMIT")))),
            NUM2INT(rb_hash_aref(r, ID2SYM(rb_intern("HEAP_USE_SLOTS")))),
            rb_hash_aref(r, ID2SYM(rb_intern("HAVE_FINALIZE")))? "true" : "false",
            NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_MARK_TIME"))))*1000,
            NUM2DBL(rb_hash_aref(r, ID2SYM(rb_intern("GC_SWEEP_TIME"))))*1000);
    }
#endif
    }
    else {
    result = rb_str_new2("");
    }
    return result;
}

+ (Float) GC::Profiler.total_time

return total time that GC used. (msec)



# File 'gc.c'

/*
 *  call-seq:
 *     GC::Profiler.total_time -> float
 *
 *  return total time that GC used. (msec)
 */

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);
}