From 72b199940d8a19d869bb9f0bb6065d15bbb030d7 Mon Sep 17 00:00:00 2001 From: yugui Date: Sun, 3 Jan 2010 15:36:17 +0000 Subject: * trace.h: new file. wraps tracing mechanisms. * defs/dtrace.d: new file. defined a dtrace provider "ruby". * include/ruby/ruby.h (LIKELY): moved from vm.c. (UNLIKELY): ditto. (OBJSETUP): probe "object-create". (RUBY_EVENT_RESCUE): new event. * vm_exec.c (DEBUG_ENTER_INSN): embeded a probe insn-entry into it. (DEBUG_END_INSN): insn-return. * vm.c (LIKELY): moved into ruby.h. (UNLIKELY): ditto. (Init_BareVM): embeded a probe "raise" into it. * variable.c (rb_class2name_without_alloc): new utility function. * tool/rbinstall.rb (install?(:ext, :arch, :'ext-arch')): installs dtrace.d if necessary. * thread_pthread.c (add_signal_thread_list): probe "raise". (rb_thread_create_timer_thread): ditto. * thread.c (rb_thread_schedule_rec): probes "thread-enter" and "thread-leave", (thread_start_func_2): ditto. (thread_cleanup_func): probe "thread-term" * lib/mkmf.rb: supports dtrace postprocessor on making an extension. * iseq.c (rb_vm_insn_name): new utility function. (rb_vm_insn_len): ditto. * insns.def (hook): probes "method-etnry", "method-return", "line", and "rescue". * compile.c (iseq_compile_each): adds a trace op for "rescue" probe. * gc.c (garbage_collect): probes "gc-begin" and "gc-end". (obj_free): probe "object-free" (garbage_collect_with_gvl): probe "raise" (negative_size_allocation_error): ditto. (rb_memerror): ditto. * eval.c (rb_rescue2): probe "rescue" (rb_longjmp): probe "raise" * ext/probe/probe.c: new extension for application defined probes. * ext/probe/extconf.rb: ditto. * configure.in (--with-tracing-model): new option to choose a tracing mechanism. (DTRACE): new substitution. name of dtrace(1). (RUBY_TRACING_MODEL): new substitution. (DTRACE_OBJ): ditto. (MINIDTRACE_OBJ): ditto. (GOLFDTRACE_OBJ): ditto. (LIBRUBY_DTRACE_OBJ): ditto. (RUBY_DTRACE_POSTPROCESS): new macro. checks whether the dtrace on the system needs postprocessing. (RUBY_DTRACE_BSD_BROKEN): new macro. checks whether the dtrace supports USDT. * Makefile.in: (DTRACE): new variable. name of dtrace(1). (TRACING_MODEL): new variable. name of the chosen tracing mechanism. (DTRACE_OBJ): same as the one in configure.in. (MINIDTRACE_OBJ): ditto. (GOLFDTRACE_OBJ): ditto. (LIBRUBY_DTRACE_OBJ): ditto. (CPPOUTFILE): new substitution. necessary for generating dtrace.d (trace_none.h): new target for TRACING_MODEL=none (RUBY_H_INCLUDES): appended a header for tracing. (distclean-local): also removes preprocessed version of dtrace.d ($(LIBRUBY_A)): needs $(LIBRUBY_DTRACE_OBJ) if dtrace needs postprocessing. ($(PROGRAM)): ditto. (golf): ditto. (miniruby): ditto. ($(arch_hdrdir)/ruby/dtrace.d): new target. preprocessed verson of defs/dtrace.d. generated if necessary. ($(arch_hdrdir)/ruby/trace_dtrace.h): new target. definition of probes. ($(LIBRUBY_DTRACE_OBJ)): new target. generated if dtrace needs postprocessing. ($(DTRACE_OBJ)): ditto. ($(MINIDTRACE_OBJ)): ditto. ($(GOLFDTRACE_OBJ)): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- include/ruby/ruby.h | 21 +++++++++-- include/ruby/trace.h | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 include/ruby/trace.h (limited to 'include/ruby') diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 5318772b35..ebef0e9605 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -40,10 +40,19 @@ extern "C" { #endif #ifdef __GNUC__ -#define PRINTF_ARGS(decl, string_index, first_to_check) \ - decl __attribute__((format(printf, string_index, first_to_check))) +# define PRINTF_ARGS(decl, string_index, first_to_check) \ + decl __attribute__((format(printf, string_index, first_to_check))) +# if __GNUC__ >= 3 +# define LIKELY(x) (__builtin_expect((x), 1)) +# define UNLIKELY(x) (__builtin_expect((x), 0)) +# else +# define LIKELY(x) (x) +# define UNLIKELY(x) (x) +# endif #else -#define PRINTF_ARGS(decl, string_index, first_to_check) decl +# define PRINTF_ARGS(decl, string_index, first_to_check) decl +# define LIKELY(x) (x) +# define UNLIKELY(x) (x) #endif #ifdef HAVE_STDLIB_H @@ -516,12 +525,17 @@ double rb_num2dbl(VALUE); VALUE rb_uint2big(VALUE); VALUE rb_int2big(SIGNED_VALUE); +#include "ruby/trace.h" + VALUE rb_newobj(void); #define NEWOBJ(obj,type) type *obj = (type*)rb_newobj() #define OBJSETUP(obj,c,t) do {\ RBASIC(obj)->flags = (t);\ RBASIC(obj)->klass = (c);\ if (rb_safe_level() >= 3) FL_SET(obj, FL_TAINT | FL_UNTRUSTED);\ + if (UNLIKELY(TRACE_OBJECT_CREATE_ENABLED())) { \ + FIRE_OBJECT_CREATE((VALUE)(obj), rb_class2name((c)), rb_sourcefile(), rb_sourceline()); \ + } \ } while (0) #define CLONESETUP(clone,obj) do {\ OBJSETUP(clone,rb_singleton_class_clone((VALUE)obj),RBASIC(obj)->flags);\ @@ -1325,6 +1339,7 @@ int ruby_native_thread_p(void); #define RUBY_EVENT_C_CALL 0x0020 #define RUBY_EVENT_C_RETURN 0x0040 #define RUBY_EVENT_RAISE 0x0080 +#define RUBY_EVENT_RESCUE 0x0100 #define RUBY_EVENT_ALL 0xffff #define RUBY_EVENT_VM 0x10000 #define RUBY_EVENT_SWITCH 0x20000 diff --git a/include/ruby/trace.h b/include/ruby/trace.h new file mode 100644 index 0000000000..f45e9d5396 --- /dev/null +++ b/include/ruby/trace.h @@ -0,0 +1,105 @@ +/********************************************************************** + + trace.h - + + $Author$ + + Copyright (C) 2009 Yuki Sonoda (Yugui) + +**********************************************************************/ + +#ifndef RUBY_TRACE_H +#define RUBY_TRACE_H + +#define RUBY_TRACING_MODEL_NONE 0 +#define RUBY_TRACING_MODEL_DTRACE 1 + +#if RUBY_TRACING_MODEL == RUBY_TRACING_MODEL_NONE +# define TRACE_METHOD_ENTRY_ENABLED() 0 +# define TRACE_METHOD_RETURN_ENABLED() 0 +# define TRACE_RAISE_ENABLED() 0 +# define TRACE_RESCUE_ENABLED() 0 +# define TRACE_LINE_ENABLED() 0 +# define TRACE_GC_BEGIN_ENABLED() 0 +# define TRACE_GC_END_ENABLED() 0 +# define TRACE_THREAD_INIT_ENABLED() 0 +# define TRACE_THREAD_TERM_ENABLED() 0 +# define TRACE_THREAD_LEAVE_ENABLED() 0 +# define TRACE_THREAD_ENTER_ENABLED() 0 +# define TRACE_OBJECT_CREATE_ENABLED() 0 +# define TRACE_OBJECT_FREE_ENABLED() 0 +# define TRACE_INSN_ENTRY_ENABLED() 0 +# define TRACE_INSN_RETURN_ENABLED() 0 +# define TRACE_RUBY_PROBE_ENABLED() 0 + +# define FIRE_METHOD_ENTRY(receiver, classname, methodname, sourcefile, sourceline) ((void)0) +# define FIRE_METHOD_RETURN(receiver, classname, methodname, sourcefile, sourceline) ((void)0) +# define FIRE_RAISE(exception, classname, sourcename, sourceline) ((void)0) +# define FIRE_RESCUE(exception, classname, sourcename, sourceline) ((void)0) +# define FIRE_LINE(sourcename, sourceline) ((void)0) +# define FIRE_GC_BEGIN() ((void)0) +# define FIRE_GC_END() ((void)0) +# define FIRE_THREAD_INIT(th, sourcefile, sourceline) ((void)0) +# define FIRE_THREAD_TERM(th, sourcefile, sourceline) ((void)0) +# define FIRE_THREAD_LEAVE(th, sourcefile, sourceline) ((void)0) +# define FIRE_THREAD_ENTER(th, sourcefile, sourceline) ((void)0) +# define FIRE_OBJECT_CREATE(obj, classname, sourcefile, sourceline) ((void)0) +# define FIRE_OBJECT_FREE(obj) ((void)0) +# define FIRE_INSN_ENTRY(insnname, operands, sourcename, sourceline) ((void)0) +# define FIRE_INSN_RETURN(insnname, operands, sourcename, sourceline) ((void)0) +# define FIRE_RUBY_PROBE(name, data) ((void)0) + +#elif RUBY_TRACING_MODEL == RUBY_TRACING_MODEL_DTRACE +# include "ruby/trace_dtrace.h" +# define TRACE_METHOD_ENTRY_ENABLED() RUBY_METHOD_ENTRY_ENABLED() +# define TRACE_METHOD_RETURN_ENABLED() RUBY_METHOD_RETURN_ENABLED() +# define TRACE_RAISE_ENABLED() RUBY_RAISE_ENABLED() +# define TRACE_RESCUE_ENABLED() RUBY_RESCUE_ENABLED() +# define TRACE_LINE_ENABLED() RUBY_LINE_ENABLED() +# define TRACE_GC_BEGIN_ENABLED() RUBY_GC_BEGIN_ENABLED() +# define TRACE_GC_END_ENABLED() RUBY_GC_END_ENABLED() +# define TRACE_THREAD_INIT_ENABLED() RUBY_THREAD_INIT_ENABLED() +# define TRACE_THREAD_TERM_ENABLED() RUBY_THREAD_TERM_ENABLED() +# define TRACE_THREAD_LEAVE_ENABLED() RUBY_THREAD_LEAVE_ENABLED() +# define TRACE_THREAD_ENTER_ENABLED() RUBY_THREAD_ENTER_ENABLED() +# define TRACE_OBJECT_CREATE_ENABLED() RUBY_OBJECT_CREATE_ENABLED() +# define TRACE_OBJECT_FREE_ENABLED() RUBY_OBJECT_FREE_ENABLED() +# define TRACE_INSN_ENTRY_ENABLED() RUBY_INSN_ENTRY_ENABLED() +# define TRACE_INSN_RETURN_ENABLED() RUBY_INSN_RETURN_ENABLED() +# define TRACE_RUBY_PROBE_ENABLED() RUBY_RUBY_PROBE_ENABLED() + +# define FIRE_METHOD_ENTRY(receiver, classname, methodname, sourcefile, sourceline) \ + RUBY_METHOD_ENTRY(receiver, classname, methodname, sourcefile, sourceline) +# define FIRE_METHOD_RETURN(receiver, classname, methodname, sourcefile, sourceline) \ + RUBY_METHOD_RETURN(receiver, classname, methodname, sourcefile, sourceline) +# define FIRE_RAISE(exception, classname, sourcename, sourceline) \ + RUBY_RAISE(exception, classname, sourcename, sourceline) +# define FIRE_RESCUE(exception, classname, sourcename, sourceline) \ + RUBY_RESCUE(exception, classname, sourcename, sourceline) +# define FIRE_LINE(sourcename, sourceline) \ + RUBY_LINE(sourcename, sourceline) +# define FIRE_GC_BEGIN() RUBY_GC_BEGIN() +# define FIRE_GC_END() RUBY_GC_END() +# define FIRE_THREAD_INIT(th, sourcefile, sourceline) \ + RUBY_THREAD_INIT(th, (char*)sourcefile, sourceline) +# define FIRE_THREAD_TERM(th, sourcefile, sourceline) \ + RUBY_THREAD_TERM(th, (char*)sourcefile, sourceline) +# define FIRE_THREAD_LEAVE(th, sourcefile, sourceline) \ + RUBY_THREAD_LEAVE(th, (char*)sourcefile, sourceline) +# define FIRE_THREAD_ENTER(th, sourcefile, sourceline) \ + RUBY_THREAD_ENTER(th, (char*)sourcefile, sourceline) +# define FIRE_OBJECT_CREATE(obj, classname, sourcefile, sourceline) \ + RUBY_OBJECT_CREATE(obj, (char*)classname, (char*)sourcefile, sourceline) +# define FIRE_OBJECT_FREE(obj) \ + RUBY_OBJECT_FREE(obj) +# define FIRE_INSN_ENTRY(insnname, operands, sourcename, sourceline) \ + RUBY_INSN_ENTRY(insnname, operands, sourcename, sourceline) +# define FIRE_INSN_RETURN(insnname, operands, sourcename, sourceline) \ + RUBY_INSN_RETURN(insnname, operands, sourcename, sourceline) +# define FIRE_RUBY_PROBE(name, data) \ + RUBY_RUBY_PROBE(name, data) +#endif + +#define FIRE_RAISE_FATAL() FIRE_RAISE(0, (char*)"fatal", (char*)"", 0) + +#endif -- cgit v1.2.3