Created
June 23, 2012 05:06
-
-
Save tmm1/2976968 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <ruby.h> | |
#include <node.h> | |
#include <oboe/oboe.h> | |
oboe_reporter_t udp_reporter; | |
#ifdef RUBY_GC_EVENT_ALL | |
// requires https://github.com/tmm1/brew2deb/blob/master/packages/ruby/patches/gc-hooks.patch | |
static void gc_hook(rb_gc_event_t gc_event, VALUE obj) | |
{ | |
if (!oboe_context_is_valid()) | |
return; | |
oboe_metadata_t *metadata = oboe_context_get(); | |
oboe_event_t event; | |
oboe_metadata_create_event(metadata, &event); | |
oboe_event_init(&event, metadata); | |
oboe_event_add_info(&event, "Layer", "garbage_collector"); | |
switch(gc_event) | |
{ | |
case RUBY_GC_EVENT_START: | |
oboe_event_add_info(&event, "Label", "entry"); | |
break; | |
case RUBY_GC_EVENT_END: | |
oboe_event_add_info(&event, "Label", "exit"); | |
break; | |
} | |
oboe_reporter_send(&udp_reporter, metadata, &event); | |
oboe_event_destroy(&event); | |
} | |
#endif | |
VALUE oboe_trace_gc(VALUE self) | |
{ | |
if (!rb_block_given_p()) | |
rb_raise(rb_eArgError, "block required"); | |
#ifndef RUBY_GC_EVENT_ALL | |
//rb_raise(rb_eNotImpError, "rb_gc_add_event_hook() is not available in this ruby build"); | |
fprintf(stderr, "rb_gc_add_event_hook() is not available in this ruby build\n"); | |
return rb_yield(Qnil); | |
#else | |
VALUE ret; | |
rb_gc_add_event_hook(gc_hook, RUBY_GC_EVENT_START|RUBY_GC_EVENT_END); | |
ret = rb_yield(Qnil); | |
rb_gc_remove_event_hook(gc_hook); | |
return ret; | |
#endif | |
} | |
void Init_oboe_gc() | |
{ | |
oboe_reporter_udp_init(&udp_reporter, "127.0.0.1", "7831"); | |
rb_define_method(rb_cObject, "oboe_trace_gc", oboe_trace_gc, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment