trace_tree 0.2.19 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62deca45905349bd526ed97929de96a290b0bc72444d4142ddddadb8724f063b
4
- data.tar.gz: 2e34e08a382e0cd249184a5ee92fbac613e06dce30806c6e8d521eee779764ca
3
+ metadata.gz: 4b6b20be57ccf2e78b519c7168b1ce03539983ca90edee377df0ef46df1e6efb
4
+ data.tar.gz: 48f2555a86a10a878ec48dbd2eb9d5b5cdea614d9c8d64e1a96a750eaa9d0543
5
5
  SHA512:
6
- metadata.gz: 53a7bcc1fcfba7bccb113c777022c98ad6bc38fe14b5b6c88985a4d26f3ab452e8d541301fa259274f26807d9d666d65593fb0746998e8bc557a98be4f5d4879
7
- data.tar.gz: b8bad2dea2b574bee4f0a1c82241587bcc708a2d2b042cbcf2fa18cedde6726d80b257b21b6c4a74f5795a754ebfbfa82c41b6894a76203872b1e3baf0be7801
6
+ metadata.gz: 66ab836be3474f70a2be81130dd1c502a6eb84b6eab030978c826358197a8b2bf31b28a88d3f4bbe60907dba775342eed4937c4cda14a3c08f5675fc2719fc7f
7
+ data.tar.gz: dfbec33b0177a877f11d3360e1bd5d94e62f3f967bd44217c3599025397ceadec68545dec21ac8c486d7cbd586886554a7130d5a8cf158b3cc9115b003da3234
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 *log, **opt, &to_do
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 *log
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 *Events, &@deal
55
+ @tp = TracePoint.new(*Events, &@deal)
54
56
  @tp.enable
55
57
 
56
- there.instance_eval &to_do
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 opt[:tmp] if opt[:tmp]
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 *enhancement, config
101
+ @point_loader = Point::Loader.new(*enhancement, config)
93
102
  end
94
103
 
95
104
  def dump_trace_tree
@@ -112,17 +121,10 @@ class TraceTree
112
121
  if (@no_methods = Array(opt[:no_methods])).empty?
113
122
  nil
114
123
  else
115
- stack_filter = 'return false unless outside_hidden_stack?(point)'
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) }
@@ -131,8 +133,8 @@ class TraceTree
131
133
  filter_method = <<-EOM
132
134
  def wanted? point
133
135
  return false if point.end_of_trace?
134
- return true if native?(point) || point.thread_relative?
135
136
  #{stack_filter}
137
+ return true if native?(point) || point.thread_relative?
136
138
  return true if point.method_defined_by_define_method?
137
139
  #{path_filter}
138
140
  true
@@ -151,14 +153,25 @@ class TraceTree
151
153
  stack = (point.thread[:trace_tree_no_methods_stack] ||= [])
152
154
  empty = stack.empty?
153
155
 
154
- if @no_methods.any?{ |pattern| pattern =~ point.method_name }
156
+ if point.event == :b_call || point.event == :b_return
157
+ return true if empty
158
+ if point.terminate?(stack.last)
159
+ stack.pop
160
+ else
161
+ stack << point
162
+ end
163
+ return false
164
+ end
165
+
166
+ if @no_methods.any?{ |pattern| pattern =~ point.method_id }
155
167
  if !empty && point.terminate?(stack.last)
156
168
  stack.pop
169
+ return stack.empty?
157
170
  else
158
171
  stack << point
159
172
  point << Point::Omitted.new
173
+ return empty
160
174
  end
161
- return true
162
175
  end
163
176
 
164
177
  empty
@@ -194,7 +207,9 @@ class TraceTree
194
207
  point.thread_begin = began_threads[thread]
195
208
  end
196
209
 
197
- #binding.pry
210
+ stacks.keys.each{ |thread| thread[:trace_tree_no_methods_stack] = nil }
211
+
212
+ # binding.pry
198
213
 
199
214
  stacks[trace_points.first.thread][0].
200
215
  callees[0].
@@ -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.exists?(custom) && (hash = YAML.load File.read custom)
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
@@ -11,7 +11,7 @@ class TraceTree
11
11
  attr_accessor :terminal, :config
12
12
 
13
13
  Interfaces = [:event, :defined_class, :method_id, :path, :lineno]
14
- attr_reader *Interfaces
14
+ attr_reader(*Interfaces)
15
15
 
16
16
  class << self
17
17
  def inherited base
@@ -73,14 +73,12 @@ EOM
73
73
  end
74
74
 
75
75
  @return_value = trace_point.return_value if x_return?
76
+ @thread = Thread.current
76
77
 
77
- if thread?
78
- @thread = trace_point.self
79
- else
78
+ unless thread?
80
79
  there = trace_point.binding.of_caller(3)
81
80
  @current = BindingOfCallers::Revealed.new there
82
81
  @frame_env = current.frame_env.to_sym
83
- @thread = current.send(:eval, 'Thread.current')
84
82
  end
85
83
  rescue => e
86
84
  puts e
@@ -162,7 +160,7 @@ EOM
162
160
 
163
161
  def class_name
164
162
  c_call? ? defined_class : current.klass
165
- rescue => e
163
+ rescue
166
164
  puts event
167
165
  end
168
166
 
@@ -191,7 +189,7 @@ EOM
191
189
  def initialize *enhancement, config
192
190
  @config = config
193
191
  @bases = Point.bases
194
- @bases = @bases.map{ |b| b = b.clone; b.prepend *enhancement; b } unless enhancement.empty?
192
+ @bases = @bases.map{ |b| b = b.clone; b.prepend(*enhancement); b } unless enhancement.empty?
195
193
  sort_bases
196
194
  end
197
195
 
@@ -6,7 +6,7 @@ class TraceTree
6
6
  BLANK = ''.freeze
7
7
 
8
8
  NEED_PP = (
9
- if File.exists? (pp_config = File.join(ENV['HOME'], '.trace_tree_pp'))
9
+ if File.exist? (pp_config = File.join(ENV['HOME'], '.trace_tree_pp'))
10
10
  IO.readlines(pp_config).map &:strip
11
11
  else
12
12
  []
@@ -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 *content
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 *path
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 *dir
60
+ FileUtils.mkdir_p File.join(*dir)
58
61
  end
59
62
  end
60
63
  end
@@ -1,3 +1,3 @@
1
1
  class TraceTree
2
- VERSION = "0.2.19"
2
+ VERSION = "0.3.0"
3
3
  end
data/trace_tree.gemspec CHANGED
@@ -20,12 +20,12 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.14"
23
+ spec.add_development_dependency "bundler", "> 1.14"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
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.1.5"
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,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trace_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.19
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-22 00:00:00.000000000 Z
11
+ date: 2021-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.14'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.14'
27
27
  - !ruby/object:Gem::Dependency
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.1.5
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.1.5
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
- rubyforge_project:
194
- rubygems_version: 2.7.6
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,