trace_tree 0.2.20 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/lib/trace_tree.rb +23 -18
- data/lib/trace_tree/config.rb +1 -1
- data/lib/trace_tree/point.rb +7 -10
- data/lib/trace_tree/return_value.rb +1 -1
- data/lib/trace_tree/tmp_file.rb +7 -4
- data/lib/trace_tree/version.rb +1 -1
- data/trace_tree.gemspec +2 -2
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8e369c5e99d5fbc0625e52c52e3e91255f4feb3e4a7a7c8cc89c4b1f9becebc3
|
4
|
+
data.tar.gz: 57d3d1e6d68cc3e453f07ae531c3c84ef860a1d51236f75a085dbbd32444bea3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d3780b5fcfe831b44b5cf9cb1429b5c025781dfba8ce4e035512905e29f9a76a4285136975f28e8f8860d35076f7d069c646aead70c36abaec3178880387df7
|
7
|
+
data.tar.gz: 4e08b2bdfa70d08ee69e65047cc4c4e664734ba49c356f79a768e5c48d1579fae3e289398556f5a5f413dc6c52012fbd22de5c7c3be90a05cbb38a939701cd03
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -54,11 +54,11 @@ end
|
|
54
54
|
* `:htmp => nil` by default. It is combination of `:html` and `:tmp`.
|
55
55
|
* `:return => true` by default. It stores return values of functions in generated html. Hover function call and press `r` to print return value in console.
|
56
56
|
* `:args => false` by default. Set it true to puts arguments of `:call` functions into html. Since arguments are always return values of other functions, so this option is not necessary.
|
57
|
-
* `:in => //, :out => nil` by default. Give them regexp(s) to include/exclude methods defined in files match that regexp(s). Notice thread-calls and methods defined by `define_method` are always included. Also, once you set any of these two options, the code to trace should not be in same line with `binding.trace_tree() do`.
|
58
57
|
* `:no_methods => nil` by default. Give it regexp(s) to hide stack under matching methods. Useful when you want to dump stack of a rack middleware but lower middlewares.
|
59
58
|
* `:warm => nil` by default. Set it something unique to the code block so that the code block will be traced only when it's called second time, in case we dump lots of code loading and initialization.
|
60
59
|
* `:timer => nil` by default. Set it true if you want to know how much time spent in tracing and drawing tree. Notice the `file` should be appendable, otherwise the time will overwrite the tree.
|
61
60
|
* `:debug => nil` by default. Give it `STDOUT`/`STDERR` or anything responds to `:puts` to output a whole list of TracePoints. Or give it a file name in the default tmp dir of your system.
|
61
|
+
* `transcode => false` by default. Set it true to convert unknown character into `"?"` when you see `Encoding::UndefinedConversionError`.
|
62
62
|
|
63
63
|
### Example 1: Output to HTML
|
64
64
|
|
data/lib/trace_tree.rb
CHANGED
@@ -18,7 +18,7 @@ class Binding
|
|
18
18
|
return yield
|
19
19
|
end
|
20
20
|
|
21
|
-
TraceTree.new(self).generate
|
21
|
+
TraceTree.new(self).generate(*log, **opt, &to_do)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -41,19 +41,21 @@ class TraceTree
|
|
41
41
|
|
42
42
|
def generate *log, **opt, &to_do
|
43
43
|
@opt = opt
|
44
|
-
@log = dump_location
|
44
|
+
@log = dump_location(*log)
|
45
45
|
@debug = debug_location
|
46
46
|
enhance_point
|
47
47
|
@build_command = (opt[:html] || opt[:htmp]) ? :tree_html_full : :tree_graph
|
48
48
|
make_filter
|
49
49
|
@__file__, @__line__, there = bi.eval('[__FILE__, __LINE__, self]')
|
50
50
|
|
51
|
+
dry_run
|
52
|
+
|
51
53
|
#start_trace
|
52
54
|
timer[:trace]
|
53
|
-
@tp = TracePoint.new
|
55
|
+
@tp = TracePoint.new(*Events, &@deal)
|
54
56
|
@tp.enable
|
55
57
|
|
56
|
-
there.instance_eval
|
58
|
+
there.instance_eval(&to_do)
|
57
59
|
ensure
|
58
60
|
#stop_trace
|
59
61
|
return unless @tp
|
@@ -66,16 +68,23 @@ class TraceTree
|
|
66
68
|
|
67
69
|
attr_reader :bi, :trace_points, :log, :build_command, :timer, :opt, :point_loader, :config
|
68
70
|
|
71
|
+
def dry_run
|
72
|
+
tp = TracePoint.new{}
|
73
|
+
tp.enable
|
74
|
+
ensure
|
75
|
+
tp.disable
|
76
|
+
end
|
77
|
+
|
69
78
|
def debug_location
|
70
79
|
loc = opt[:debug]
|
71
80
|
return nil unless loc
|
72
81
|
return loc if loc.respond_to? :puts
|
73
|
-
TmpFile.new loc
|
82
|
+
TmpFile.new loc, transcode: opt[:transcode]
|
74
83
|
end
|
75
84
|
|
76
85
|
def dump_location *log
|
77
|
-
return TmpFile.new
|
78
|
-
return TmpFile.new(opt[:htmp] + '.html') if opt[:htmp]
|
86
|
+
return TmpFile.new(opt[:tmp], transcode: opt[:transcode]) if opt[:tmp]
|
87
|
+
return TmpFile.new((opt[:htmp] + '.html'), transcode: opt[:transcode]) if opt[:htmp]
|
79
88
|
log.empty? ? STDOUT : log[0]
|
80
89
|
end
|
81
90
|
|
@@ -89,7 +98,7 @@ class TraceTree
|
|
89
98
|
enhancement << TraceTree::LuxuryReturnValue
|
90
99
|
end
|
91
100
|
enhancement << TraceTree::Args if opt[:args] == true
|
92
|
-
@point_loader = Point::Loader.new
|
101
|
+
@point_loader = Point::Loader.new(*enhancement, config)
|
93
102
|
end
|
94
103
|
|
95
104
|
def dump_trace_tree
|
@@ -115,14 +124,7 @@ class TraceTree
|
|
115
124
|
'return false unless outside_hidden_stack?(point)'
|
116
125
|
end
|
117
126
|
|
118
|
-
path_filter =
|
119
|
-
if opt.key?(:in) || opt.key?(:out)
|
120
|
-
@in = Array(opt[:in] || //)
|
121
|
-
@out = Array(opt[:out])
|
122
|
-
'return false unless @in.any?{ |pattern| pattern =~ point.path } && @out.all?{ |pattern| pattern !~ point.path }'
|
123
|
-
else
|
124
|
-
nil
|
125
|
-
end
|
127
|
+
path_filter = nil
|
126
128
|
|
127
129
|
if stack_filter.nil? && path_filter.nil?
|
128
130
|
return @deal = -> point { trace_points << point_loader.create(point) }
|
@@ -164,11 +166,12 @@ class TraceTree
|
|
164
166
|
if @no_methods.any?{ |pattern| pattern =~ point.method_id }
|
165
167
|
if !empty && point.terminate?(stack.last)
|
166
168
|
stack.pop
|
169
|
+
return stack.empty?
|
167
170
|
else
|
168
171
|
stack << point
|
169
172
|
point << Point::Omitted.new
|
173
|
+
return empty
|
170
174
|
end
|
171
|
-
return true
|
172
175
|
end
|
173
176
|
|
174
177
|
empty
|
@@ -204,7 +207,9 @@ class TraceTree
|
|
204
207
|
point.thread_begin = began_threads[thread]
|
205
208
|
end
|
206
209
|
|
207
|
-
|
210
|
+
stacks.keys.each{ |thread| thread[:trace_tree_no_methods_stack] = nil }
|
211
|
+
|
212
|
+
# binding.pry
|
208
213
|
|
209
214
|
stacks[trace_points.first.thread][0].
|
210
215
|
callees[0].
|
data/lib/trace_tree/config.rb
CHANGED
@@ -11,7 +11,7 @@ class TraceTree
|
|
11
11
|
def self.load
|
12
12
|
config = DEFAULT
|
13
13
|
custom = File.join ENV['HOME'], '.trace_tree_config'
|
14
|
-
if File.
|
14
|
+
if File.exist?(custom) && (hash = YAML.load File.read custom)
|
15
15
|
hash.select!{ |k, v| config.include? k }
|
16
16
|
config = config.merge hash
|
17
17
|
end
|
data/lib/trace_tree/point.rb
CHANGED
@@ -11,7 +11,8 @@ class TraceTree
|
|
11
11
|
attr_accessor :terminal, :config
|
12
12
|
|
13
13
|
Interfaces = [:event, :defined_class, :method_id, :path, :lineno]
|
14
|
-
attr_reader
|
14
|
+
attr_reader(*Interfaces)
|
15
|
+
class_eval 'def assign_trace_point_values(tp);' + Interfaces.map{ |i| "@#{i} = tp.#{i}" }.join(';') + ';end'
|
15
16
|
|
16
17
|
class << self
|
17
18
|
def inherited base
|
@@ -68,19 +69,15 @@ EOM
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def initialize trace_point
|
71
|
-
|
72
|
-
instance_variable_set "@#{i}", trace_point.send(i)
|
73
|
-
end
|
72
|
+
assign_trace_point_values(trace_point)
|
74
73
|
|
75
74
|
@return_value = trace_point.return_value if x_return?
|
75
|
+
@thread = Thread.current
|
76
76
|
|
77
|
-
|
78
|
-
@thread = trace_point.self
|
79
|
-
else
|
77
|
+
unless thread?
|
80
78
|
there = trace_point.binding.of_caller(3)
|
81
79
|
@current = BindingOfCallers::Revealed.new there
|
82
80
|
@frame_env = current.frame_env.to_sym
|
83
|
-
@thread = current.send(:eval, 'Thread.current')
|
84
81
|
end
|
85
82
|
rescue => e
|
86
83
|
puts e
|
@@ -162,7 +159,7 @@ EOM
|
|
162
159
|
|
163
160
|
def class_name
|
164
161
|
c_call? ? defined_class : current.klass
|
165
|
-
rescue
|
162
|
+
rescue
|
166
163
|
puts event
|
167
164
|
end
|
168
165
|
|
@@ -191,7 +188,7 @@ EOM
|
|
191
188
|
def initialize *enhancement, config
|
192
189
|
@config = config
|
193
190
|
@bases = Point.bases
|
194
|
-
@bases = @bases.map{ |b| b = b.clone; b.prepend
|
191
|
+
@bases = @bases.map{ |b| b = b.clone; b.prepend(*enhancement); b } unless enhancement.empty?
|
195
192
|
sort_bases
|
196
193
|
end
|
197
194
|
|
data/lib/trace_tree/tmp_file.rb
CHANGED
@@ -12,14 +12,17 @@ class TraceTree
|
|
12
12
|
|
13
13
|
DefaultName = 'trace_tree.html'
|
14
14
|
|
15
|
-
def initialize path
|
15
|
+
def initialize path, transcode: false
|
16
16
|
path = recognize_dir path
|
17
17
|
@tmp = custom path
|
18
|
+
@transcode = transcode
|
18
19
|
end
|
19
20
|
|
20
21
|
def puts *content
|
22
|
+
content = content.map{ |c| c.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') } if @transcode
|
23
|
+
|
21
24
|
File.open @tmp, 'a' do |f|
|
22
|
-
f.puts
|
25
|
+
f.puts(*content)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
@@ -45,7 +48,7 @@ class TraceTree
|
|
45
48
|
path[-1] = time + path[-1]
|
46
49
|
path = [Dir.tmpdir] + path
|
47
50
|
ensure_parent path
|
48
|
-
File.join
|
51
|
+
File.join(*path)
|
49
52
|
end
|
50
53
|
|
51
54
|
def time
|
@@ -54,7 +57,7 @@ class TraceTree
|
|
54
57
|
|
55
58
|
def ensure_parent path_arr
|
56
59
|
dir = path_arr[0..-2]
|
57
|
-
FileUtils.mkdir_p File.join
|
60
|
+
FileUtils.mkdir_p File.join(*dir)
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
data/lib/trace_tree/version.rb
CHANGED
data/trace_tree.gemspec
CHANGED
@@ -21,11 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "> 1.14"
|
24
|
-
spec.add_development_dependency "rake", "
|
24
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
25
25
|
spec.add_development_dependency "minitest", "~> 5.0"
|
26
26
|
spec.add_development_dependency "pry"
|
27
27
|
|
28
|
-
spec.add_dependency "binding_of_callers", "~> 0.
|
28
|
+
spec.add_dependency "binding_of_callers", "~> 0.2.0"
|
29
29
|
spec.add_dependency "tree_graph", "~> 0.2.0"
|
30
30
|
spec.add_dependency "tree_html", "~> 0.1.7"
|
31
31
|
spec.add_dependency "terminal-tableofhashes", "~> 0.1.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trace_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.2.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.2.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: tree_graph
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,8 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
190
|
- !ruby/object:Gem::Version
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
|
-
|
194
|
-
rubygems_version: 2.5.2.3
|
193
|
+
rubygems_version: 3.2.3
|
195
194
|
signing_key:
|
196
195
|
specification_version: 4
|
197
196
|
summary: Print TracePoint(:b_call, :b_return, :c_call, :c_return, :call, :return,
|