Skip to content

Commit

Permalink
Test the heapdump command
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Jul 28, 2023
1 parent b3a256d commit a6a4ce3
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
5 changes: 0 additions & 5 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 "

Expand Down
4 changes: 3 additions & 1 deletion ext/rbtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/rbtrace/core_ext.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/rbtrace/msgq.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require 'rbtrace'
require 'ffi'

module MsgQ
extend FFI::Library
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,
Expand Down
4 changes: 3 additions & 1 deletion lib/rbtrace/rbtracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a6a4ce3

Please sign in to comment.