From: KOSAKI Motohiro Date: 2010-01-10T03:28:52+09:00 Subject: [ruby-dev:40006] yuguiさんのvm_probesのsystemtap対応 kosakiです。 [ruby-core:27448] [Feature:trunk] adding hooks for better tracing でアナウンスされたDTraceパッチですが 以下のような変更を加えることによりSystemTapでも動くことを確認しました。 汚い箇所も多々あるかと思いますが、ご参考までに。 From 3b65780694cb22e12bf4ef5ae24f73627a0882f6 Mon Sep 17 00:00:00 2001 From: KOSAKI Motohiro Date: Sun, 10 Jan 2010 02:41:27 +0900 Subject: [PATCH] Initial systemtap support Signed-off-by: KOSAKI Motohiro --- depend | 4 +++- extconf.rb | 6 +++++- systemtap_probes.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 systemtap_probes.h diff --git a/depend b/depend index ec2a9e8..f421069 100644 --- a/depend +++ b/depend @@ -5,8 +5,10 @@ tracing_mechanism.h: $(TRACING_MECHANISM)_probes.h mkmf.log dtrace_probes.h: dtrace.h dtrace.h: dtrace.d mkmf.log $(DTRACE) -h $(ARCH_FLAGS) -o dtrace.h -s dtrace.d -dtrace.$(OBJEXT): $(ORIG_OBJS) dtrace.d mkmf.log +dtrace.o: $(ORIG_OBJS) dtrace.d mkmf.log $(DTRACE) -G $(ARCH_FLAGS) -o $@ -s dtrace.d $(ORIG_OBJS) +systemtap.o: $(ORIG_OBJS) dtrace.d mkmf.log + $(DTRACE) -G $(ARCH_FLAGS) -o $@ -s dtrace.d dtrace.d: dtrace.d.erb mkmf.log echo 'please re-run extconf.rb' false diff --git a/extconf.rb b/extconf.rb index 6b56239..bc52712 100644 --- a/extconf.rb +++ b/extconf.rb @@ -6,7 +6,7 @@ DTRACE = 'dtrace' ARCH=$configure_args['with-arch'] def choose_mechanism - case mechanism = $configure_args['tracing-mechanism'] + case mechanism = with_config('tracing-mechanism', case RUBY_PLATFORM; when /linux/; 'systemtap'; end) when 'dtrace', nil mechanism = 'dtrace' begin @@ -18,6 +18,10 @@ def choose_mechanism exit false end create_dtrace_d + when 'systemtap' + $objs = %w[ vm_probes.o ] + $objs << 'systemtap.o' + create_dtrace_d else message "unknown tracing mechanism #{mechanism}" exit false diff --git a/systemtap_probes.h b/systemtap_probes.h new file mode 100644 index 0000000..b9d5fff --- /dev/null +++ b/systemtap_probes.h @@ -0,0 +1,49 @@ +#ifndef DTRACE_PROBES_H +#define DTRACE_PROBES_H + +# include "dtrace.h" + +/* + XXX_ENABLED macro doesn't works correctly if dtrace.o is linked shared library. ;-) + Thus, we disable this macros temporary. +*/ +# define TRACE_METHOD_ENTRY_ENABLED() 1 +# define TRACE_METHOD_RETURN_ENABLED() 1 +# define TRACE_RAISE_ENABLED() 1 +# define TRACE_RESCUE_ENABLED() 1 +# define TRACE_LINE_ENABLED() 1 +# define TRACE_GC_START_ENABLED() 1 +# define TRACE_GC_END_ENABLED() 1 +# define TRACE_THREAD_INIT_ENABLED() 1 +# define TRACE_THREAD_TERM_ENABLED() 1 +# define TRACE_THREAD_LEAVE_ENABLED() 1 +# define TRACE_THREAD_ENTER_ENABLED() 1 +# define TRACE_OBJECT_CREATE_ENABLED() 1 +# define TRACE_OBJECT_FREE_ENABLED() 1 + +# define FIRE_METHOD_ENTRY(receiver, classname, methodname, sourcefile, sourceline) \ + RUBY_METHOD_ENTRY(receiver, (char*)classname, (char*)methodname, (char*)sourcefile, sourceline) +# define FIRE_METHOD_RETURN(receiver, classname, methodname, sourcefile, sourceline) \ + RUBY_METHOD_RETURN(receiver, (char*)classname, (char*)methodname, (char*)sourcefile, sourceline) +# define FIRE_RAISE(exception, classname, sourcename, sourceline) \ + RUBY_RAISE(exception, (char*)classname, (char*)sourcename, sourceline) +# define FIRE_RESCUE(exception, classname, sourcename, sourceline) \ + RUBY_RESCUE(exception, (char*)classname, (char*)sourcename, sourceline) +# define FIRE_LINE(sourcename, sourceline) \ + RUBY_LINE((char*)sourcename, sourceline) +# define FIRE_GC_START() RUBY_GC_START() +# 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, sourcefile, sourceline) \ + RUBY_OBJECT_CREATE(obj, (char*)sourcefile, sourceline) +# define FIRE_OBJECT_FREE(obj) \ + RUBY_OBJECT_FREE(obj) + +#endif -- 1.6.6