rbtrace 0.3.15 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/bin/rbtrace +67 -7
- data/rbtrace.gemspec +1 -1
- data/test.sh +13 -12
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/bin/rbtrace
CHANGED
@@ -658,7 +658,7 @@ class RBTracer
|
|
658
658
|
parser = Trollop::Parser.new do
|
659
659
|
version <<-EOS
|
660
660
|
rbtrace: like strace, but for ruby code
|
661
|
-
version 0.3.
|
661
|
+
version 0.3.16
|
662
662
|
(c) 2011 Aman Gupta (tmm1)
|
663
663
|
http://github.com/tmm1/rbtrace
|
664
664
|
EOS
|
@@ -672,7 +672,10 @@ for examples and more information, see http://github.com/tmm1/rbtrace
|
|
672
672
|
|
673
673
|
Usage:
|
674
674
|
|
675
|
-
rbtrace
|
675
|
+
rbtrace --exec <CMD> # run and trace <CMD>
|
676
|
+
rbtrace --pid <PID+> # trace the given process(es)
|
677
|
+
rbtrace --ps <CMD> # look for running <CMD> processes to trace
|
678
|
+
|
676
679
|
rbtrace -o <FILE> # write output to file
|
677
680
|
rbtrace -t # show method call start time
|
678
681
|
rbtrace -n # hide duration of each method call
|
@@ -709,11 +712,21 @@ Trace Expressions:
|
|
709
712
|
All Options:\n
|
710
713
|
|
711
714
|
EOS
|
715
|
+
opt :exec,
|
716
|
+
"spawn new ruby process and attach to it",
|
717
|
+
:type => :strings,
|
718
|
+
:short => nil
|
719
|
+
|
712
720
|
opt :pid,
|
713
721
|
"pid of the ruby process to trace",
|
714
722
|
:type => :ints,
|
715
723
|
:short => '-p'
|
716
724
|
|
725
|
+
opt :ps,
|
726
|
+
"find any matching processes to trace",
|
727
|
+
:type => :string,
|
728
|
+
:short => nil
|
729
|
+
|
717
730
|
opt :firehose,
|
718
731
|
"show all method calls",
|
719
732
|
:short => '-f'
|
@@ -774,11 +787,6 @@ EOS
|
|
774
787
|
:type => String,
|
775
788
|
:short => '-e'
|
776
789
|
|
777
|
-
opt :exec,
|
778
|
-
"spawn new ruby process and attach to it",
|
779
|
-
:type => :strings,
|
780
|
-
:short => nil
|
781
|
-
|
782
790
|
opt :wait,
|
783
791
|
"seconds to wait before attaching to process",
|
784
792
|
:default => 0,
|
@@ -853,6 +861,58 @@ EOS
|
|
853
861
|
|
854
862
|
tracee = nil
|
855
863
|
|
864
|
+
if opts[:ps_given]
|
865
|
+
list = `ps aux`.split("\n")
|
866
|
+
filtered = list.grep(Regexp.new opts[:ps])
|
867
|
+
filtered.reject! do |line|
|
868
|
+
line =~ /^\w+\s+#{Process.pid}\s+/ # cannot trace self
|
869
|
+
end
|
870
|
+
|
871
|
+
if filtered.size > 0
|
872
|
+
max_len = filtered.size.to_s.size
|
873
|
+
|
874
|
+
STDERR.puts "*** found #{filtered.size} processes matching #{opts[:ps].inspect}"
|
875
|
+
filtered.each_with_index do |line, i|
|
876
|
+
STDERR.puts " [#{(i+1).to_s.rjust(max_len)}] #{line.strip}"
|
877
|
+
end
|
878
|
+
STDERR.puts " [0] all #{filtered.size} processes"
|
879
|
+
|
880
|
+
while true
|
881
|
+
STDERR.sync = true
|
882
|
+
STDERR.print "*** trace which processes? (0/1,4): "
|
883
|
+
|
884
|
+
begin
|
885
|
+
input = gets
|
886
|
+
rescue Interrupt
|
887
|
+
exit 1
|
888
|
+
end
|
889
|
+
|
890
|
+
if input =~ /^(\d+,?)+$/
|
891
|
+
if input.strip == '0'
|
892
|
+
pids = filtered.map do |line|
|
893
|
+
line.split[1].to_i
|
894
|
+
end
|
895
|
+
else
|
896
|
+
indices = input.split(',').map(&:to_i)
|
897
|
+
pids = indices.map do |i|
|
898
|
+
if i > 0 and line = filtered[i-1]
|
899
|
+
line.split[1].to_i
|
900
|
+
end
|
901
|
+
end
|
902
|
+
end
|
903
|
+
|
904
|
+
unless pids.include?(nil)
|
905
|
+
opts[:pid] = pids
|
906
|
+
break
|
907
|
+
end
|
908
|
+
end
|
909
|
+
end
|
910
|
+
else
|
911
|
+
STDERR.puts "*** could not find any processes matching #{opts[:ps].inspect}"
|
912
|
+
exit 1
|
913
|
+
end
|
914
|
+
end
|
915
|
+
|
856
916
|
if opts[:exec_given]
|
857
917
|
tracee = fork{
|
858
918
|
Process.setsid
|
data/rbtrace.gemspec
CHANGED
data/test.sh
CHANGED
@@ -30,18 +30,19 @@ trace() {
|
|
30
30
|
echo
|
31
31
|
}
|
32
32
|
|
33
|
-
|
34
|
-
trace -m
|
35
|
-
trace -m sleep
|
36
|
-
trace -m "
|
37
|
-
trace -m "
|
38
|
-
trace
|
39
|
-
trace --gc
|
40
|
-
trace --
|
41
|
-
trace --slow=250
|
42
|
-
trace --
|
43
|
-
trace --gc -m Dir. --slow=250
|
44
|
-
trace -m
|
33
|
+
bin/rbtrace -m sleep --wait 2 --exec ruby -e '10.times{ sleep 0.5 }'
|
34
|
+
#trace -m Test.run --devmode
|
35
|
+
#trace -m sleep
|
36
|
+
#trace -m sleep Dir.chdir Dir.pwd Process.pid "String#gsub" "String#*"
|
37
|
+
#trace -m "Kernel#"
|
38
|
+
#trace -m "String#gsub(self,@test)" "String#*(self,__source__)" "String#multiply_vowels(self,self.length,num)"
|
39
|
+
#trace --gc --slow=200
|
40
|
+
#trace --gc -m Dir.
|
41
|
+
#trace --slow=250
|
42
|
+
#trace --slow=250 --slow-methods sleep
|
43
|
+
#trace --gc -m Dir. --slow=250 --slow-methods sleep
|
44
|
+
#trace --gc -m Dir. --slow=250
|
45
|
+
#trace -m Process. Dir.pwd "Proc#call"
|
45
46
|
# trace --firehose
|
46
47
|
|
47
48
|
cleanup
|
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:
|
4
|
+
hash: 51
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 16
|
10
|
+
version: 0.3.16
|
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-11-
|
18
|
+
date: 2011-11-25 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|