<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>shotgun/rubinius.d</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -35,7 +35,6 @@ runtime/platform.conf
 *.swp
 *.dylib
 *.so
-*.d
 *~
 \#*
 .\#*</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -10,6 +10,12 @@ else
   BINSUFFIX?=
 endif
 
+ifdef DTRACE
+	DTRACE_H=dtrace.h
+else
+	DTRACE_H=
+endif
+
 CFLAGS += -I.. $(CPPFLAGS) -Iexternal_libs/libbstring -Iexternal_libs/libcchash -Iexternal_libs/libmpa -Iexternal_libs/libmquark -Iexternal_libs/libev
 
 ALIBS=external_libs/libtommath/libtommath.a external_libs/onig/.libs/libonig.a external_libs/libzip/lib/.libs/libzip.a external_libs/libltdl/.libs/libltdl.a external_libs/libev/.libs/libev.a external_libs/libbstring/libbstring.a external_libs/libcchash/libcchash.a external_libs/libmpa/libptr_array.a external_libs/libmquark/libmquark.a
@@ -109,7 +115,7 @@ external_libs/libmpa/libptr_array.a:
 external_libs/libmquark/libmquark.a:
 	cd external_libs/libmquark; $(MAKE)
 
-$(RBLIB): config.h $(ALIBS) external_libs/lightning/config.h 
+$(RBLIB): config.h $(DTRACE_H) $(ALIBS) external_libs/lightning/config.h 
 	cd lib; $(MAKE) library; 
 
 .PHONY: $(RBLIB)
@@ -117,6 +123,9 @@ $(RBLIB): config.h $(ALIBS) external_libs/lightning/config.h
 # Don't try to build main until librubinius exists
 main.c: $(RBLIB)
 
+dtrace.h: rubinius.d
+	/usr/sbin/dtrace -h -s rubinius.d -o dtrace.h
+
 rubinius.bin: $(RBLIB) main.o
 	$(COMP) -o rubinius.bin main.o $(RBLIB) $(BIN_RPATH)
 </diff>
      <filename>shotgun/Makefile</filename>
    </modified>
    <modified>
      <diff>@@ -162,6 +162,28 @@ void cpu_add_roots(STATE, cpu c, ptr_array roots) {
   #undef ar
 }
 
+int cpu_ip2line(STATE, OBJECT meth, int ip) {
+  OBJECT lines, tup;
+  int l, total, start, nd, op;
+  
+  if(meth-&gt;obj_type != CMethodType) return 0;
+
+  lines = cmethod_get_lines(meth);
+  total = NUM_FIELDS(lines);
+  for(l = 0; l &lt; total; l++) {
+    tup = tuple_at(state, lines, l);
+    start = FIXNUM_TO_INT(tuple_at(state, tup, 0));
+    nd = FIXNUM_TO_INT(tuple_at(state, tup, 1));
+    op = FIXNUM_TO_INT(tuple_at(state, tup, 2));
+
+    if(ip &gt;= start &amp;&amp; ip &lt;= nd) {
+      return op;
+    }
+  }
+
+  return 0;
+}
+
 void cpu_update_roots(STATE, cpu c, ptr_array roots, int start) {
   xpointer tmp;
   int i, len;</diff>
      <filename>shotgun/lib/cpu.c</filename>
    </modified>
    <modified>
      <diff>@@ -201,6 +201,8 @@ OBJECT cpu_marshal_to_file(STATE, OBJECT obj, char *path, int version);
 void cpu_bootstrap(STATE);
 void cpu_add_roots(STATE, cpu c, ptr_array roots);
 void cpu_update_roots(STATE, cpu c, ptr_array roots, int start);
+int cpu_ip2line(STATE, OBJECT meth, int ip);
+
 
 /* Method cache functions */
 void cpu_clear_cache(STATE, cpu c);</diff>
      <filename>shotgun/lib/cpu.h</filename>
    </modified>
    <modified>
      <diff>@@ -16,6 +16,13 @@
 #include &quot;shotgun/lib/fixnum.h&quot;
 #include &quot;shotgun/lib/primitive_util.h&quot;
 
+#if CONFIG_ENABLE_DTRACE
+#include &quot;dtrace.h&quot;
+#define ENABLE_DTRACE 1
+#else
+#define ENABLE_DTRACE 0
+#endif
+
 #define RISA(obj,cls) (REFERENCE_P(obj) &amp;&amp; ISA(obj,BASIC_CLASS(cls)))
 
 #define next_int _int = *ip_ptr++;
@@ -553,9 +560,39 @@ static inline int cpu_try_primitive(STATE, cpu c, OBJECT mo, OBJECT recv, int ar
   req = FIXNUM_TO_INT(cmethod_get_required(mo));
   
   if(args == req || req &lt; 0) {
+#if ENABLE_DTRACE
+  if (RUBINIUS_FUNCTION_ENTRY_ENABLED()) {
+    const char * module_name = mod == Qnil ? &quot;&lt;unknown&gt;&quot; : rbs_symbol_to_cstring(state, module_get_name(mod));
+    const char * method_name = rbs_symbol_to_cstring(state, sym);
+
+    cpu_flush_ip(c);
+
+    struct fast_context *fc = FASTCTX(c-&gt;active_context);
+    int line_number = cpu_ip2line(state, fc-&gt;method, fc-&gt;ip);
+    const char * filename = rbs_symbol_to_cstring(state, cmethod_get_file(fc-&gt;method));
+
+    RUBINIUS_FUNCTION_ENTRY(module_name, method_name, filename, line_number);
+  }
+#endif
+    
     stack_push(recv);
     if(cpu_perform_primitive(state, c, prim, mo, args, sym, mod, block)) {
       /* Worked! */
+      
+#if ENABLE_DTRACE
+  if (RUBINIUS_FUNCTION_RETURN_ENABLED()) {
+    const char * module_name = mod == Qnil ? &quot;&lt;unknown&gt;&quot; : rbs_symbol_to_cstring(state, module_get_name(mod));
+    const char * method_name = rbs_symbol_to_cstring(state, sym);
+
+    cpu_flush_ip(c);
+
+    struct fast_context *fc = FASTCTX(c-&gt;active_context);
+    int line_number = cpu_ip2line(state, fc-&gt;method, fc-&gt;ip);
+    const char * filename = rbs_symbol_to_cstring(state, cmethod_get_file(fc-&gt;method));
+
+    RUBINIUS_FUNCTION_RETURN(module_name, method_name, filename, line_number);
+  }
+#endif
       return TRUE;
     }
     /* Didn't work, need to remove the recv we put on before. */
@@ -647,6 +684,23 @@ void nmc_activate(STATE, cpu c, OBJECT nmc, OBJECT val, int reraise);
 inline int cpu_simple_return(STATE, cpu c, OBJECT val) {
   OBJECT destination, home;
 
+#if ENABLE_DTRACE
+  if (RUBINIUS_FUNCTION_RETURN_ENABLED()) {
+    OBJECT module = cpu_current_module(state, c);
+    
+    const char * module_name = (module == Qnil) ? &quot;&lt;unknown&gt;&quot; : rbs_symbol_to_cstring(state, module_get_name(module));
+    const char * method_name = rbs_symbol_to_cstring(state, cmethod_get_name(cpu_current_method(state, c)));
+    
+    cpu_flush_ip(c);
+    
+    struct fast_context *fc = FASTCTX(c-&gt;active_context);
+    int line_number = cpu_ip2line(state, fc-&gt;method, fc-&gt;ip);
+    const char * filename = rbs_symbol_to_cstring(state, cmethod_get_file(fc-&gt;method));
+
+    RUBINIUS_FUNCTION_RETURN(module_name, method_name, filename, line_number);
+  }
+#endif
+
   destination = cpu_current_sender(c);
   
   // printf(&quot;Rtrnng frm %p (%d)\n&quot;, c-&gt;active_context, FASTCTX(c-&gt;active_context)-&gt;size);
@@ -710,6 +764,24 @@ inline int cpu_return_to_sender(STATE, cpu c, OBJECT val, int consider_block, in
   
   is_block = blokctx_s_block_context_p(state, c-&gt;active_context);
   destination = cpu_current_sender(c);
+  
+#if ENABLE_DTRACE
+  if (RUBINIUS_FUNCTION_RETURN_ENABLED() &amp;&amp; !is_block) {
+    OBJECT module = cpu_current_module(state, c);
+
+    const char * module_name = (module == Qnil) ? &quot;&lt;unknown&gt;&quot; : rbs_symbol_to_cstring(state, module_get_name(module));
+    const char * method_name = rbs_symbol_to_cstring(state, cmethod_get_name(cpu_current_method(state, c)));
+
+    cpu_flush_ip(c);
+    
+    struct fast_context *fc = FASTCTX(c-&gt;active_context);
+    int line_number = cpu_ip2line(state, fc-&gt;method, fc-&gt;ip);
+    const char * filename = rbs_symbol_to_cstring(state, cmethod_get_file(fc-&gt;method));
+
+    RUBINIUS_FUNCTION_RETURN(module_name, method_name, filename, line_number);
+  }
+#endif
+  
     
   if(destination == Qnil) {
     object_memory_retire_context(state-&gt;om, c-&gt;active_context);
@@ -856,8 +928,9 @@ static inline void cpu_return_to_block_creator(STATE, cpu c) {
 inline void cpu_goto_method(STATE, cpu c, OBJECT recv, OBJECT meth,
                                      int count, OBJECT name, OBJECT block) {
   OBJECT ctx;
-  
+
   if(cpu_try_primitive(state, c, meth, recv, count, name, Qnil, block)) { return; }
+
   ctx = cpu_create_context(state, c, recv, meth, name, 
         _real_class(state, recv), (unsigned long int)count, block);
   cpu_activate_context(state, c, ctx, ctx, 0);
@@ -933,6 +1006,22 @@ static inline void _cpu_build_and_activate(STATE, cpu c, OBJECT mo,
       missing ? &quot;METHOD MISSING&quot; : &quot;&quot;
       );
   }
+  
+#if ENABLE_DTRACE
+  if (RUBINIUS_FUNCTION_ENTRY_ENABLED()) {
+    const char * module_name = rbs_symbol_to_cstring(state, module_get_name(mod));
+    const char * method_name = rbs_symbol_to_cstring(state, sym);
+
+    cpu_flush_ip(c);
+
+    struct fast_context *fc = FASTCTX(c-&gt;active_context);
+    int line_number = cpu_ip2line(state, fc-&gt;method, fc-&gt;ip);
+    const char * filename = rbs_symbol_to_cstring(state, cmethod_get_file(fc-&gt;method));
+
+    RUBINIUS_FUNCTION_ENTRY(module_name, method_name, filename, line_number);
+  }
+#endif
+
   ctx = cpu_create_context(state, c, recv, mo, sym, mod, (unsigned long int)args, block);
   /* If it was missing, setup some extra data in the MethodContext for
      the method_missing method to check out, to see why it was missing. */
@@ -1281,6 +1370,12 @@ next_op:
 #endif
 check_interrupts:
     if(state-&gt;om-&gt;collect_now) {
+
+#if ENABLE_DTRACE
+      if (RUBINIUS_GC_BEGIN_ENABLED()) {
+        RUBINIUS_GC_BEGIN();
+      }
+#endif      
       int cm = state-&gt;om-&gt;collect_now;
       
       /* Collect the first generation. */
@@ -1311,6 +1406,12 @@ check_interrupts:
       }
       
       state-&gt;om-&gt;collect_now = 0;
+
+#if ENABLE_DTRACE
+      if (RUBINIUS_GC_END_ENABLED()) {
+        RUBINIUS_GC_END();
+      }
+#endif      
     }
     
     if(state-&gt;check_events) {</diff>
      <filename>shotgun/lib/cpu_instructions.c</filename>
    </modified>
    <modified>
      <diff>@@ -33,26 +33,6 @@ static int _recursive_reporting = 0;
 
 #define SYM2STR(st, sym) string_byte_address(st, rbs_symbol_to_string(st, sym))
 
-static int _ip2line(STATE, OBJECT meth, int ip) {
-  OBJECT lines, tup;
-  int l, total, start, nd, op;
-
-  lines = cmethod_get_lines(meth);
-  total = NUM_FIELDS(lines);
-  for(l = 0; l &lt; total; l++) {
-    tup = tuple_at(state, lines, l);
-    start = FIXNUM_TO_INT(tuple_at(state, tup, 0));
-    nd = FIXNUM_TO_INT(tuple_at(state, tup, 1));
-    op = FIXNUM_TO_INT(tuple_at(state, tup, 2));
-
-    if(ip &gt;= start &amp;&amp; ip &lt;= nd) {
-      return op;
-    }
-  }
-
-  return 0;
-}
-
 void machine_print_callstack_limited(machine m, int maxlev) {
   OBJECT context, tmp;
   const char *modname, *methname, *filename;
@@ -102,7 +82,7 @@ void machine_print_callstack_limited(machine m, int maxlev) {
       (void*)context, modname, methname,
       fc-&gt;ip,
       filename,
-      _ip2line(m-&gt;s, fc-&gt;method, fc-&gt;ip)
+      cpu_ip2line(m-&gt;s, fc-&gt;method, fc-&gt;ip)
     );
     context = fc-&gt;sender;
   }</diff>
      <filename>shotgun/lib/machine.c</filename>
    </modified>
    <modified>
      <diff>@@ -73,8 +73,14 @@ echo &quot;#define CONFIG_EXTPATH \&quot;$EXTPATH\&quot;&quot;
 echo &quot;#define CONFIG_BUILDREV \&quot;$BUILDREV\&quot;&quot;
 echo &quot;#define CONFIG_ENGINE \&quot;$ENGINE\&quot;&quot;
 echo &quot;#define CONFIG_CC \&quot;$CC\&quot;&quot;
+
+if test &quot;$DTRACE&quot; = &quot;1&quot;; then
+  echo &quot;#define CONFIG_ENABLE_DTRACE 1&quot;
+fi
+
 ) &gt; config.h
 
+
 if config/run is64bit; then
   echo &quot;#define CONFIG_WORDSIZE 64&quot; &gt;&gt; config.h
   echo &quot;#define CONFIG_ENABLE_DT 0&quot; &gt;&gt; config.h</diff>
      <filename>shotgun/mkconfig.sh</filename>
    </modified>
    <modified>
      <diff>@@ -6,3 +6,5 @@ RUBY_PATCHLEVEL=111
 
 LIBVER=0.8
 VERSION=${LIBVER}.0
+
+DTRACE=0</diff>
      <filename>shotgun/vars.mk</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b9e5fc471bdb331ee7d84e04a4baccef3baf89d4</id>
    </parent>
  </parents>
  <author>
    <name>Marcus Crafter</name>
    <login>crafterm</login>
    <email>crafterm@redartisan.com</email>
  </author>
  <url>http://github.com/evanphx/rubinius/commit/46513843cedfe47bd5710aa3756230aa15a1570a</url>
  <id>46513843cedfe47bd5710aa3756230aa15a1570a</id>
  <committed-date>2008-01-27T16:40:54-08:00</committed-date>
  <authored-date>2008-01-27T16:40:54-08:00</authored-date>
  <message>Added DTrace probes for function-entry/return and gc-begin/end.

Probes are disabled by default, see shotgun/vars.mk to enable them in your build on a DTrace compatible machine.
Probe signatures are compatible with Joyent's Ruby probes, with the exception of the provider name (Rubinius).
Example dtrace scripts and documentation forthcoming.</message>
  <tree>c5164b2b9eaa5a03b6838052acc1b95774345b8f</tree>
  <committer>
    <name>Marcus Crafter</name>
    <login>crafterm</login>
    <email>crafterm@redartisan.com</email>
  </committer>
</commit>
