Skip to content

Instantly share code, notes, and snippets.

@jamesgolick
Created November 19, 2012 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesgolick/4113649 to your computer and use it in GitHub Desktop.
Save jamesgolick/4113649 to your computer and use it in GitHub Desktop.
static VALUE
gc_basic_profile_total_time(VALUE self)
{
rb_objspace_t *objspace = &rb_objspace;
return DBL2NUM(objspace->basic_profile.total_time);
}
typedef struct gc_profile_record {
double gc_time;
double gc_mark_time;
double gc_sweep_time;
double gc_invoke_time;
size_t heap_use_slots;
size_t heap_live_objects;
size_t heap_free_objects;
size_t heap_total_objects;
size_t heap_use_size;
size_t heap_total_size;
int have_finalize;
int is_marked;
size_t allocate_increase;
size_t allocate_limit;
} gc_profile_record;
(gdb) p ruby_current_vm->objspace->profile.count
$1 = 533282
1.9.3p194 :001 > GC::Profiler.enabled?
=> false
1.9.3p194 :002 > GC::Profiler.enable
=> nil
1.9.3p194 :003 > GC::Profiler.enabled?
=> 0
Total: 90 samples
49 54.4% 54.4% 49 54.4% GC::Profiler.total_time
9 10.0% 64.4% 9 10.0% garbage_collector
if (count >= objspace->profile.size) {
objspace->profile.size += 1000;
objspace->profile.record = realloc(objspace->profile.record, sizeof(gc_profile_record) * objspace->profile.size);
}
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);
}
irb(main):001:0> GC::BasicProfiler.enabled?
=> false
irb(main):002:0> GC::BasicProfiler.enable
=> nil
irb(main):003:0> GC::BasicProfiler.enabled?
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment