Exemplo 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;
}
Exemplo n.º 2
0
static VALUE cov_remove_coverage_hook(VALUE self) {
  if(!coverage_hook_set_p) 
    return Qfalse;
  else {
    rb_remove_event_hook(coverage_event_coverage_hook);
    coverage_hook_set_p = 0;
    return Qtrue;
  }
}
Exemplo n.º 3
0
static VALUE
methprofiler_teardown()
{
  if (!bMethProfilerRunning)
    return Qfalse;

  rb_remove_event_hook(event_handler);

  bMethProfilerRunning = Qfalse;
  return Qtrue;
}
Exemplo n.º 4
0
static void
__catch_line_event(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass)
{
    (void)sizeof(evflag);
    (void)sizeof(self);
    (void)sizeof(mid);
    (void)sizeof(klass);

    rb_remove_event_hook(__catch_line_event);
    if (rb_during_gc())
        return;
    __func_to_set_breakpoint_at();
}
Exemplo 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;
}
Exemplo 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;
}
Exemplo n.º 7
0
void
rb_clear_trace_func(void)
{
    st_foreach(GET_VM()->living_threads, clear_trace_func_i, (st_data_t) 0);
    rb_remove_event_hook(0);
}