diff --git a/ext/extconf.rb b/ext/extconf.rb index 12eb097..db6a711 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -63,11 +63,6 @@ def sys(cmd) have_func('rb_gc_add_event_hook', ['ruby.h', 'node.h']) have_func('rb_postponed_job_register_one', 'ruby.h') -# increase message size on linux -if RUBY_PLATFORM =~ /linux/ - $defs.push("-DBUF_SIZE=256") -end - # warnings save lives $CFLAGS << " -Wall " diff --git a/ext/rbtrace.c b/ext/rbtrace.c index a516170..e8f0f0f 100644 --- a/ext/rbtrace.c +++ b/ext/rbtrace.c @@ -79,7 +79,7 @@ timeofday_usec() #define MAX_TRACERS 100 // max method tracers #define MAX_EXPRS 10 // max expressions per tracer #ifndef BUF_SIZE // msgq buffer size -#define BUF_SIZE 120 +#define BUF_SIZE 1024 #endif typedef struct { @@ -1138,6 +1138,8 @@ Init_rbtrace() rbtrace_module = rb_define_module("RBTrace"); VALUE output = rb_define_module_under(rbtrace_module, "OUT"); + rb_const_set(rbtrace_module, rb_intern("BUF_SIZE"), INT2NUM(BUF_SIZE)); + rb_define_singleton_method(output, "write", send_write, 1); // hook into the gc diff --git a/lib/rbtrace/core_ext.rb b/lib/rbtrace/core_ext.rb index f90630d..d8e93f6 100644 --- a/lib/rbtrace/core_ext.rb +++ b/lib/rbtrace/core_ext.rb @@ -1,7 +1,3 @@ -class String - alias :bytesize :size -end unless ''.respond_to?(:bytesize) - module FFI::LastError Errnos = Errno::constants.map(&Errno.method(:const_get)).inject({}) do |hash, c| hash[ c.const_get(:Errno) ] = c diff --git a/lib/rbtrace/msgq.rb b/lib/rbtrace/msgq.rb index e97b98c..c585516 100644 --- a/lib/rbtrace/msgq.rb +++ b/lib/rbtrace/msgq.rb @@ -1,3 +1,4 @@ +require 'rbtrace' require 'ffi' module MsgQ @@ -5,7 +6,7 @@ module MsgQ ffi_lib FFI::CURRENT_PROCESS class EventMsg < FFI::Struct - BUF_SIZE = RUBY_PLATFORM =~ /linux/ ? 256 : 120 + BUF_SIZE = RBTrace::BUF_SIZE IPC_NOWAIT = 004000 layout :mtype, :long, diff --git a/lib/rbtrace/rbtracer.rb b/lib/rbtrace/rbtracer.rb index 25da99a..a672d9b 100644 --- a/lib/rbtrace/rbtracer.rb +++ b/lib/rbtrace/rbtracer.rb @@ -323,7 +323,9 @@ def send_cmd(*cmd) msg = cmd.to_msgpack # A message is null-terminated, but bytesize gives the unterminated # length. - raise ArgumentError, 'command is too long' if msg.bytesize >= MsgQ::EventMsg::BUF_SIZE + if msg.bytesize >= RbTrace::BUF_SIZE + raise ArgumentError, "command is too long (#{msg.bytesize}B >= #{MsgQ::EventMsg::BUF_SIZE}B)" + end MsgQ::EventMsg.send_cmd(@qo, msg) rescue Errno::EINTR retry diff --git a/test.sh b/test.sh index 4edc983..49b618a 100755 --- a/test.sh +++ b/test.sh @@ -38,6 +38,7 @@ trace -m sleep Dir.chdir Dir.pwd Process.pid "String#gsub" "String#*" trace -m "Kernel#" trace -m "String#gsub(self,@test)" "String#*(self,__source__)" "String#multiply_vowels(self,self.length,num)" trace -e 'p(1 + 1)' +trace -h trace --gc --slow=200 trace --gc -m Dir. trace --slow=250