trace_tree 0.2.21 → 0.3.2

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: 0be4af3563495464f3f18a8f3071777eaff9d29fbd90c99e79338dcd6ed97818
4
- data.tar.gz: 82691f1633c340f8fcdc602564367db4d63769fa1d9a076d3a1ecba8f65d57dc
3
+ metadata.gz: 5faac3e419aae49a1d520caabd21eca4b4569b60bed6be5f29d69b26561781e6
4
+ data.tar.gz: 95441a432f9fdd29d4cd3ffa50ae468fec4764ccada641d0cdd25e6db5564da0
5
5
  SHA512:
6
- metadata.gz: 67e6c97a69c109f44ae2f5527628caabb02e1c1aaff1ae05160b836f360b98432fc68d37a992664497c0089dcd7b02af2a9eb3999f27acf57134239129fd01fe
7
- data.tar.gz: e24c3bab4d4a09883a450d91b0a3f8f10f517a9da35acb37b66f51e5435902fe4e6970cf4cc97c03c4e06d580fe262e96a7464339bbee99ae4669825b163812c
6
+ metadata.gz: 510554091628f1449c479cb0a218a9875e446fb6414cb53d101390c6bff35490deb409979e73e8eddeb7edbffd56e6682ca3c96cfd60fab7ede0a7d0a9c27abb
7
+ data.tar.gz: 516bf6a7a61ddc1c2487261fd2b24aaf58fa105a6b914bd87ab3ae95771d9e70a5f854c72fb1c634a850631e350bc377bf25df7cd617100b2dc30e080b43f8f9
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
+ # source 'https://gems.ruby-china.com'
2
3
 
3
4
  # Specify your gem's dependencies in trace_tree.gemspec
4
5
  gemspec
data/README.md CHANGED
@@ -54,11 +54,19 @@ 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
+
63
+ ### Methods' return values
64
+
65
+ By default it stores return values of functions in generated html. If there is any kind of value can not be stringified, you can do something like this to avoid exception:
66
+
67
+ ```ruby
68
+ TraceTree::ReturnValue.formatted(Mongo::Protocol::Message) { |_| "Mongo::Protocol::Message" }
69
+ ```
62
70
 
63
71
  ### Example 1: Output to HTML
64
72
 
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
@@ -100,11 +109,14 @@ class TraceTree
100
109
  log.puts tree
101
110
  log.puts timer.to_s if opt[:timer]
102
111
  rescue => e
103
- log.puts timer.to_s, e.inspect, e.backtrace, table_of_points
112
+ log.puts timer.to_s, e.inspect, e.backtrace
113
+ log.puts table_of_points
104
114
  end
105
115
 
106
116
  def table_of_points
107
117
  Terminal::Table.from_hashes trace_points_array.map(&:to_h)
118
+ rescue => e
119
+ log.puts "#{__method__}", e.inspect, e.backtrace
108
120
  end
109
121
 
110
122
  def make_filter
@@ -115,14 +127,7 @@ class TraceTree
115
127
  'return false unless outside_hidden_stack?(point)'
116
128
  end
117
129
 
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
130
+ path_filter = nil
126
131
 
127
132
  if stack_filter.nil? && path_filter.nil?
128
133
  return @deal = -> point { trace_points << point_loader.create(point) }
@@ -207,7 +212,7 @@ class TraceTree
207
212
 
208
213
  stacks.keys.each{ |thread| thread[:trace_tree_no_methods_stack] = nil }
209
214
 
210
- #binding.pry
215
+ # binding.pry
211
216
 
212
217
  stacks[trace_points.first.thread][0].
213
218
  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,8 @@ 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
+ 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
- Interfaces.each do |i|
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
- if thread?
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 => e
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 *enhancement; b } unless enhancement.empty?
191
+ @bases = @bases.map{ |b| b = b.clone; b.prepend(*enhancement); b } unless enhancement.empty?
195
192
  sort_bases
196
193
  end
197
194
 
@@ -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.21"
2
+ VERSION = "0.3.2"
3
3
  end
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", "~> 10.0"
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.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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trace_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.21
4
+ version: 0.3.2
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-27 00:00:00.000000000 Z
11
+ date: 2021-05-29 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: '10.0'
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: '10.0'
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.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,