rbtrace 0.3.13 → 0.3.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +0 -1
  2. data/bin/rbtrace +45 -5
  3. data/ext/extconf.rb +2 -2
  4. data/rbtrace.gemspec +1 -1
  5. metadata +5 -5
data/README.md CHANGED
@@ -196,6 +196,5 @@ for popular ruby libraries and functions.
196
196
  * add watch expressions to fire tracers only when an expression is true
197
197
  * add special expressions for method args (_arg0_, _arguments_)
198
198
  * optimize local variable lookup to avoid instance_eval
199
- * run process via bin/rbtrace (to trace rubygems and bootup time)
200
199
  * investigate mach_msg on osx since msgget(2) has hard kernel limits
201
200
 
@@ -154,11 +154,15 @@ class RBTracer
154
154
  raise ArgumentError, 'could not signal process, are you running as root?'
155
155
  end
156
156
 
157
- signal
158
- sleep 0.25 # wait for process to create msgqs
157
+ 5.times do
158
+ signal
159
+ sleep 0.15 # wait for process to create msgqs
159
160
 
160
- @qi = MsgQ.msgget( pid, 0666)
161
- @qo = MsgQ.msgget(-pid, 0666)
161
+ @qi = MsgQ.msgget( pid, 0666)
162
+ @qo = MsgQ.msgget(-pid, 0666)
163
+
164
+ break if @qi > -1 || @qo > -1
165
+ end
162
166
 
163
167
  if @qi == -1 || @qo == -1
164
168
  raise ArgumentError, 'pid is not listening for messages, did you `require "rbtrace"`'
@@ -770,6 +774,11 @@ EOS
770
774
  :type => String,
771
775
  :short => '-e'
772
776
 
777
+ opt :exec,
778
+ "spawn new ruby process and attach to it",
779
+ :type => :strings,
780
+ :short => nil
781
+
773
782
  opt :timeout,
774
783
  "seconds to wait before giving up on attach/detach",
775
784
  :default => 5
@@ -777,9 +786,17 @@ EOS
777
786
 
778
787
  opts = Trollop.with_standard_exception_handling(parser) do
779
788
  raise Trollop::HelpNeeded if ARGV.empty?
789
+ parser.stop_on '--exec'
780
790
  parser.parse(ARGV)
781
791
  end
782
792
 
793
+ if ARGV.first == '--exec'
794
+ ARGV.shift
795
+ opts[:exec_given] = true
796
+ opts[:exec] = ARGV.dup
797
+ ARGV.clear
798
+ end
799
+
783
800
  unless %w[ fork eval slow firehose methods config gc ].find{ |n| opts[:"#{n}_given"] }
784
801
  $stderr.puts "Error: --slow, --gc, --firehose, --methods or --config required."
785
802
  $stderr.puts "Try --help for help."
@@ -790,6 +807,15 @@ EOS
790
807
  parser.die :fork, '(can only be invoked with one pid)'
791
808
  end
792
809
 
810
+ if opts[:exec_given]
811
+ if opts[:pid_given]
812
+ parser.die :exec, '(cannot exec and attach to pid)'
813
+ end
814
+ if opts[:fork_given]
815
+ parser.die :fork, '(cannot fork inside newly execed process)'
816
+ end
817
+ end
818
+
793
819
  methods, smethods = [], []
794
820
 
795
821
  if opts[:methods_given]
@@ -822,7 +848,15 @@ EOS
822
848
 
823
849
  tracee = nil
824
850
 
825
- if opts[:pid].size <= 1
851
+ if opts[:exec_given]
852
+ tracee = fork{
853
+ Process.setsid
854
+ ENV['RUBYOPT'] = "-r#{File.expand_path('../../lib/rbtrace',__FILE__)}"
855
+ exec(*opts[:exec])
856
+ }
857
+ STDERR.puts "*** spawned child #{tracee}: #{opts[:exec].inspect[1..-2]}"
858
+
859
+ elsif opts[:pid].size <= 1
826
860
  tracee = opts[:pid].first
827
861
 
828
862
  else
@@ -917,6 +951,12 @@ EOS
917
951
  if tracer
918
952
  tracer.detach
919
953
  end
954
+
955
+ if opts[:exec_given]
956
+ STDERR.puts "*** waiting on spawned child #{tracee}"
957
+ Process.kill 'TERM', tracee
958
+ Process.waitpid(tracee)
959
+ end
920
960
  end
921
961
  end
922
962
  end
@@ -16,10 +16,10 @@ unless File.exists?("#{CWD}/dst/lib/libmsgpackc.a")
16
16
 
17
17
  msgpack = File.basename('msgpack-0.5.4.tar.gz')
18
18
  dir = File.basename(msgpack, '.tar.gz')
19
+ cflags, ldflags = ENV['CFLAGS'], ENV['LDFLAGS']
19
20
 
20
21
  # build fat binaries on osx
21
22
  if RUBY_PLATFORM =~ /darwin/ and (archs = Config::CONFIG['LDFLAGS'].scan(/(-arch\s+.+?)(?:\s|$)/).flatten).any?
22
- cflags, ldflags = ENV['CFLAGS'], ENV['LDFLAGS']
23
23
  ENV['CFLAGS'] = "#{cflags} #{archs.join(' ')}"
24
24
  ENV['LDFLAGS'] = "#{ldflags} #{archs.join(' ')}"
25
25
  end
@@ -30,7 +30,7 @@ unless File.exists?("#{CWD}/dst/lib/libmsgpackc.a")
30
30
  sys("tar zxvf #{msgpack}")
31
31
  Dir.chdir(dir) do
32
32
  if RUBY_PLATFORM =~ /i686/ and gcc = `gcc -v 2>&1` and gcc =~ /gcc version (\d\.\d)/ and $1.to_f <= 4.1
33
- ENV['CFLAGS'] += " -march=i686 "
33
+ ENV['CFLAGS'] = " #{ENV['CFLAGS']} -march=i686 "
34
34
  end
35
35
  sys("./configure --disable-dependency-tracking --disable-shared --disable-cxx --with-pic --prefix=#{CWD}/dst/")
36
36
  sys("make install")
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rbtrace'
3
- s.version = '0.3.13'
3
+ s.version = '0.3.14'
4
4
  s.homepage = 'http://github.com/tmm1/rbtrace'
5
5
 
6
6
  s.authors = 'Aman Gupta'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbtrace
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 13
10
- version: 0.3.13
9
+ - 14
10
+ version: 0.3.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aman Gupta
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-16 00:00:00 -07:00
18
+ date: 2011-11-22 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  requirements: []
125
125
 
126
126
  rubyforge_project:
127
- rubygems_version: 1.4.2
127
+ rubygems_version: 1.6.2
128
128
  signing_key:
129
129
  specification_version: 3
130
130
  summary: "rbtrace: like strace but for ruby code"