Ejemplo n.º 1
0
/*
 * IO::Trace#run(stream = nil, formatter = nil)
 *
 * - Enables tracing
 * - Setup an MRI event hook for RUBY_EVENT_LINE
 * - yields the block
 * - Unregister event hook
 * - Stops tracing
 * - Snapshot collected aggregates
 * - Walk collected aggregates
 * - Dump results to a stream via a given formatter (both optional)
 *
 * Stream expects a #<<(data) and formatters a lambda{|stream, lambda| ... } contract
*/
static VALUE
rb_io_trace_run(int argc, VALUE *argv, VALUE obj)
{
    io_trace_t* trace = GetIOTracer(obj);
    VALUE formatter, result;
    int ret, status;
    result = Qnil;

    BlockRequired();

    rb_scan_args(argc, argv, "02", &trace->stream, &trace->formatter);
    StartTrace(trace);
#ifdef RUBY_VM
    rb_add_event_hook(rb_io_trace_event_hook, RUBY_EVENT_LINE, Qnil);
#else
    rb_add_event_hook(rb_io_trace_event_hook, RUBY_EVENT_LINE);
#endif
    result = rb_protect(rb_yield, obj, &status);
    rb_remove_event_hook(rb_io_trace_event_hook);
    StopTrace(trace);
    if(!NIL_P(trace->stream)){
      formatter = rb_io_trace_formatter(trace);
      rb_funcall(formatter, id_call, 2, obj, trace->stream);
    }
    return result;
}
Ejemplo n.º 2
0
static VALUE
methprofiler_setup()
{
  if (bMethProfilerRunning)
    return Qtrue;

#if defined(RB_EVENT_HOOKS_HAVE_CALLBACK_DATA) || defined(RUBY_EVENT_VM)
  rb_add_event_hook(event_handler, RUBY_EVENT_CALL|RUBY_EVENT_C_CALL, 0);
#else
  rb_add_event_hook(event_handler, RUBY_EVENT_CALL|RUBY_EVENT_C_CALL);
#endif

  bMethProfilerRunning = Qtrue;
  return Qtrue;
}
Ejemplo n.º 3
0
int
debase_start_attach()
{
    if (rb_during_gc())
        return 1;
    rb_add_event_hook(__catch_line_event, RUBY_EVENT_LINE, (VALUE) NULL);
    return 0;
}
Ejemplo n.º 4
0
static VALUE cov_install_coverage_hook(VALUE self) {
    if (!coverage_hook_set_p) {
        if (!coverinfo) coverinfo = st_init_strtable();
        coverage_hook_set_p = 1;
        /* TODO: allow C_CALL too, since it's supported already
         * the overhead is around ~30%, tested on typo */
        rb_add_event_hook(coverage_event_coverage_hook, RUBY_EVENT_ALL & ~RUBY_EVENT_C_CALL & ~RUBY_EVENT_C_RETURN & ~RUBY_EVENT_CLASS);

        return Qtrue;
    } else return Qfalse;
}
Ejemplo n.º 5
0
static VALUE
set_trace_func(VALUE obj, VALUE trace)
{

    rb_remove_event_hook(call_trace_func);

    if (NIL_P(trace)) {
        return Qnil;
    }

    if (!rb_obj_is_proc(trace)) {
        rb_raise(rb_eTypeError, "trace_func needs to be Proc");
    }

    rb_add_event_hook(call_trace_func, RUBY_EVENT_ALL, trace);
    return trace;
}
Ejemplo n.º 6
0
static void profiler_linetrace(int remove)
{
  static int hooked = 0;

  if (remove) {
    if (!hooked) return;
    hooked = 0;
    rb_remove_event_hook(&profiler_linetrace_callback);
    return;
  }

  if (hooked) {
    return;
  }

  rb_add_event_hook(&profiler_linetrace_callback, RUBY_EVENT_END, Qnil);
  hooked = 1;

  return;
}
void Init_debug_event_hook()
{
    rb_add_event_hook(debug_event_hook, RUBY_EVENT_ALL, Qnil);
}