Skip to content

Commit

Permalink
Merge pull request #91 from casperisfine/ruby-3.2
Browse files Browse the repository at this point in the history
Setup CI and fix some small errors
  • Loading branch information
SamSaffron authored Dec 1, 2023
2 parents 1242bef + a6a4ce3 commit 2680644
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 24 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Test
on: [push, pull_request]

jobs:
ruby:
name: Ruby ${{ matrix.ruby }}
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
ruby: ["3.2", "3.1", "3.0", "2.7", "2.6"]
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Tests
run: ./test.sh
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
9 changes: 4 additions & 5 deletions 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 @@ -876,9 +876,7 @@ eval_inspect(VALUE rb_code) {
}

static VALUE
rescue_inspect(VALUE arg) {
VALUE exception = rb_errinfo(); /* get last exception */
rb_set_errinfo(Qnil);
rescue_inspect(VALUE arg, VALUE exception) {
return rb_funcall(exception, rb_intern("inspect"), 0);
}

Expand All @@ -891,7 +889,6 @@ rbtrace__process_event(msgpack_object cmd)
static int last_tracer_id = -1; // hax
char query[BUF_SIZE];

char code[BUF_SIZE+150];
VALUE val = Qnil;

msgpack_object_array ary;
Expand Down Expand Up @@ -1148,6 +1145,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
3 changes: 1 addition & 2 deletions lib/rbtrace/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ def self.run

opt :shapesdump,
"generate a shapes dump for the process in FILENAME",
:default => "AUTO",

:default => "AUTO"
end

opts = Optimist.with_standard_exception_handling(parser) do
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
2 changes: 1 addition & 1 deletion rbtrace.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.add_dependency 'optimist', '>= 3.0.0'
s.add_dependency 'msgpack', '>= 0.4.3'

s.add_development_dependency "rake", "~> 10.0"
s.add_development_dependency "rake"

s.license = "MIT"
s.summary = 'rbtrace: like strace but for ruby code'
Expand Down
2 changes: 1 addition & 1 deletion server.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'ext/rbtrace'
require 'rbtrace'
require 'tmpdir'

class String
Expand Down
10 changes: 6 additions & 4 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cd ..
bundle check
export RUBYOPT="-I.:lib"

ruby server.rb &
bundle exec ruby server.rb &
export PID=$!

trap cleanup INT TERM
Expand All @@ -23,11 +23,11 @@ cleanup() {

trace() {
echo ------------------------------------------
echo ./bin/rbtrace -p $PID $*
echo ./bin/rbtrace -p $PID "$@"
echo ------------------------------------------
./bin/rbtrace -p $PID $* &
bundle exec ./bin/rbtrace -p $PID "$@" &
sleep 2
kill $!
kill $! || true
wait $! || true
echo
}
Expand All @@ -37,6 +37,8 @@ trace -m sleep
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 2680644

Please sign in to comment.