Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f302d64aa7
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 100 lines (87 sloc) 1.946 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#include <ruby.h>
#include <node.h>
#include <env.h>

static int tracing = 0;
static int am_tracing = 0;

static char *
get_event_name(rb_event_t event)
{
  switch (event) {
  case RUBY_EVENT_LINE:
return "line";
  case RUBY_EVENT_CLASS:
return "class";
  case RUBY_EVENT_END:
return "end";
  case RUBY_EVENT_CALL:
return "call";
  case RUBY_EVENT_RETURN:
return "return";
  case RUBY_EVENT_C_CALL:
return "c-call";
  case RUBY_EVENT_C_RETURN:
return "c-return";
  case RUBY_EVENT_RAISE:
return "raise";
  default:
return "unknown";
  }
}

static VALUE cov_tracer = 0;

static void
insurance_trace_func(event, node, self, id, klass)
    rb_event_t event;
    NODE *node;
    VALUE self;
    ID id;
    VALUE klass;
{
  int state, raised;
  NODE *node_save;
  VALUE srcfile;
  struct FRAME *prev;
  static int counting = 0;

  if (tracing) return;
  if (id == ID_ALLOCATOR) return;
  tracing = 1;
  if (node) {
    ruby_current_node = node;
    ruby_frame->node = node;
    ruby_sourcefile = node->nd_file;
    ruby_sourceline = nd_line(node);
  }

  srcfile = rb_str_new2(ruby_sourcefile?ruby_sourcefile:"(ruby)");
  rb_funcall(cov_tracer, rb_intern("call"), 3, rb_str_new2(get_event_name(event)), srcfile, INT2FIX(ruby_sourceline));
  tracing = 0;
}

static VALUE
is_tracing()
{
  if (am_tracing == 0) {
    return Qfalse;
  }
  return Qtrue;
}

static VALUE
set_insurance_trace_func(obj, trace)
    VALUE obj, trace;
{
  if (NIL_P(trace)) {
cov_tracer = 0;
am_tracing = 0;
rb_remove_event_hook(insurance_trace_func);
return Qnil;
  }

  cov_tracer = trace;
  am_tracing = 1;
  rb_add_event_hook(insurance_trace_func, RUBY_EVENT_LINE);
  return trace;
}


void
Init_insurance_tracer()
{
    VALUE mProf;

    mProf = rb_define_module("Insurance");
    rb_define_module_function(mProf, "set_trace_func", set_insurance_trace_func, 1);
    rb_define_module_function(mProf, "is_tracing?", is_tracing, 0);
}
Something went wrong with that request. Please try again.